Home > Undergraduate > CITS4407 Open Source Tools and Scripting >    Labs

  CITS4407 OPEN SOURCE TOOLS AND SCRIPTING
 
 

Lab 9: git and make

This week's lab simulates the the real-life workflow of a computer programmer starting on an unfamiliar project. Whether working for a company or contributing to open-source projects, at some stage in your career you will end up working with code written by somebody else. When this happens, you will work through the following steps:
  1. Access the code (get it onto your computer)
  2. Understand the code, at least at a high level. If you're lucky there will be a README to explain it.
  3. Figure out what you need to change and how you will change it
  4. Record your changes in such a way that they can be passed on to other users of the codebase.
Typically, we imagine that most computer programming work falls under step 3, because this is where the creativity, problem solving and code-writing occurs. However, all four steps are critical for understanding and contributing to a project. If you can learn the four steps, you will be prepared to work on any software project. To illustrate this point, this week's lab uses unfamiliar languages (C and make) and an unfamiliar workflow (git).

Questions

Step 1: Access

  1. Copy the repository from /lab/week11/casino.tar.gz to your mapped directory. Once there, extract it using tar:
    tar -xvf casino.tar.gz
    cd casino
    

Step 2: Understand

  1. Work out how to build and run monty - the README file should help you out here. Once you build it, run ./monty and see what it does.
  2. Use git log to look at the existing commits. These show what has been worked on in the project and can help you understand what state the project is in.

Step 3: Change

  1. Before making changes, check out a new branch to keep your work separate from main.
    git checkout -b lab11
    
  2. Check you are on the correct branch using git status
  3. Create a Makefile with a single target called build. This target should execute the same command you used when you built monty back in step 2. This target should have montyhall.c as a dependency.
  4. As you are working, you can use git diff at any time to see the changes you have made. Use git status to see the repository status: what files have been changed, what branch you are on, etc

Step 4: Record

  1. Before making a commit, we need to tell git who we are. Run the commands below to configure git with a username and email. These can be whatever you want. If you are publishing a repository publically, it's a good idea to use a fake email address.
    git config --global user.email [email protected]
    git config --global user.name stud
    
  2. Commit your changes in git:
    git add Makefile # tell git to track the Makefile and include its changes in the next commit
    git status # check the status of the repo
    git commit # this will open an editor so you can record an appropriate commit messsage, save and quit the editor when done
    git status # check the status of the repo and see how it has changed
    
    Note that we did not commit the binary file monty - this can be generated from the other files so we don't need to track it in git.
  3. Use git log to look at the list of commits. The most recent one should be your new commit.
Congratulations, you have just contributed to an unfamiliar project, using a new workflow and working with new languages!

Further exercises

These exercises give you some further practice with git and make.
  1. Create a .gitignore file so that git ignores the compiled monty binary.
  2. Commit your changes, using an appropriate commit message.
  3. Add a clean rule to your Makefile. This rule should remove any files produced by the build process (in this case, just the compiled monty program).
  4. Commit your changes as before, using an appropriate commit message.
  5. Add another make rule called install which installs compiled binary.

  6. Note: Installation on linux is as simple as copying the binary to an appropriate location (usually one on your PATH). In this case, copy the binary to /usr/games.
  7. Commit your changes as before, using an appropriate commit message.
  8. Now that you have made a few commits, use git log to look over them them.

Bonus

  1. Set up the git lola alias following the instructions here.
  2. Create a github account and add the github repo to your account as a new private repository.
  3. Use git merge to merge your lab11 branch back into main branch.


Department of Computer Science & Software Engineering
The University of Western Australia
Last modified: 8 February 2022
Modified By: Daniel Smith

UWA