Tutorial 2 Code Review in GitHub and Gerrit basics - McGill-ECSE429-Winter2022/tutorials GitHub Wiki

GitHub Code Reviews

  1. Navigate to the folder for the working copy of your ecse429-tutorial1 from the previous tutorial.

  2. List all branches of the project, i.e. local and remote using the command (git branch -a). Switch -r would only list the remote branches. For listing only local branches use the command (git branch) without any switches.

  3. Create & checkout a new branch named called tutorial2. (git branch tutorial2 && git checkout tutorial2 ) For creating a new branch and checking it out in a single command use (git checkout -b tutorial2)

  4. Edit README.md.

    # ecse429-tutorial2
    
    A default java project generated by Maven.
    
  5. Commit your changes and push this tutorial2 branch. (git add . && git commit -m "Adding brief project description" && git push origin tutorial2) You can also set the local branch to track the upstream branch using the switch --set-upstream.

  6. Open the main page for the repository on Github. Click on the green button in the upper right corner to open a pull request.

  7. Study the possible settings, then create the pull request.

  8. On the next page, click on Files changed. Place a comment in the updated file and start a review.

  9. Normally, the owner and the reviewer are two different participants, and GitHub offers more options when completing a review: approve changes or request changes. This time simply click on Finish review and Comment.

  10. Merge the pull request. Delete the branch afterwards.

Gerrit Code Reviews

  1. Go to http://gerrithub.io/, click on First time Sign In.

  2. Authenticate with GitHub, then select the repositories you want to replicate with Gerrit.

    Note
    You can select repositories to replicate anytime by navigating to gerrithub.io > Open Gerrit Code Review > GitHub (in the top menubar) > Repositories
  3. Create a GerritHub password for HTTP access. Go to your profile (upper right corner) > Settings > HTTP Credentials, then click on Generate New Password. Make sure to save it somewhere, otherwise you need to generate it again next time.

  4. Click on Brows > Repositories, then search for your repository.

  5. Select your project named after your repository, then set the settings below and click on Save Changes.

  6. Copy the command from the git clone command shown above the Description text box after changing to Clone with commit-msg hook and http.

    Note
    Make sure you are issuing the git clone command in a folder that is not part of any git repository working copy in your file system. (In other words, you should do it in your ~/git folder or the like.) Optionally, if you have SSH key installed to GitHub, you can import it to GerritHub and use that for authentication.
  7. Paste the command to the terminal. Enter your generated password when prompted.

Making a Change with Gerrit

  1. Navigate to the repository. Edit the README.md file:

    # ecse429-tutorial2
    
    # Edditing the README.md file for publishing first Gerrit CR
  2. Add, commit and push the changes.

  3. Observe the changes synced to GitHub, too.

  4. Create a new change to the README.md file, and create a new commit. Do not push it yet!

  5. Issue git push origin HEAD:refs/for/main. The outputs should show that a new Gerrit change is created.

  6. Navigate to your GerritHub dashboard. Observe the changes there.

Note
GitHub does not sync Gerrit changes, since they are pushed to a gerrit-specific branch (refs/for/[branchname]).

Review and Manage a Change with Gerrit

  1. Click on the change and explore the options on the web interface.

  2. Comment on the README.md file within the change suggesting a sample sentence.

  3. The comment will remain a draft up to the point until you submit your review. Click on the Reply…​ button on the overview page for the change.

  4. Implement the modifications within the README.md file on your local machine.

    # ecse429-tutorial2
    # Editing the README.md file for publishing first Gerrit CR
    # Editing the README.md file for responding back to the Gerrit RC and ammending the change
. Append these modifications to the change
+
[source,none]

git add README.md git commit --amend -m [Amend Commit Message] git push origin HEAD:refs/for/main

+
[CAUTION]
It is very important to mention that in git, amending a pushed commit is a history-rewriting operation, that is in most cases to be avoided. However, Gerrit follows these changes by amending a previous commit that holds the previous version of the change.

. Observe the new patch set online. +

. Approve and verify the change. +

. Submit the changes to the `main` branch. +

. Soon the commit becomes visible in GitHub as well. Make sure to pull afterwards to update your local branches.
⚠️ **GitHub.com Fallback** ⚠️