Tutorial 2 Code Review in GitHub and Gerrit basics - McGill-ECSE429-Winter2022/tutorials GitHub Wiki
-
Navigate to the folder for the working copy of your ecse429-tutorial1 from the previous tutorial.
-
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. -
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) -
Edit
README.md.
# ecse429-tutorial2 A default java project generated by Maven. -
Commit your changes and push this
tutorial2branch. (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. -
Open the main page for the repository on Github. Click on the green button in the upper right corner to open a pull request.
-
Study the possible settings, then create the pull request.
-
On the next page, click on Files changed. Place a comment in the updated file and start a review.
-
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.
-
Merge the pull request. Delete the branch afterwards.
-
Go to http://gerrithub.io/, click on First time Sign In.
-
Authenticate with GitHub, then select the repositories you want to replicate with Gerrit.
NoteYou can select repositories to replicate anytime by navigating to gerrithub.io > Open Gerrit Code Review > GitHub (in the top menubar) > Repositories -
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.
-
Click on Brows > Repositories, then search for your repository.
-
Select your project named after your repository, then set the settings below and click on Save Changes.
-
Copy the command from the
git clonecommand shown above the Description text box after changing to Clone with commit-msg hook and http.NoteMake sure you are issuing the git clonecommand 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~/gitfolder or the like.) Optionally, if you have SSH key installed to GitHub, you can import it to GerritHub and use that for authentication. -
Paste the command to the terminal. Enter your generated password when prompted.
-
Navigate to the repository. Edit the
README.mdfile:# ecse429-tutorial2 # Edditing the README.md file for publishing first Gerrit CR -
Add, commit and push the changes.
-
Observe the changes synced to GitHub, too.
-
Create a new change to the README.md file, and create a new commit. Do not push it yet!
-
Issue
git push origin HEAD:refs/for/main. The outputs should show that a new Gerrit change is created. -
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]).
|
-
Click on the change and explore the options on the web interface.
-
Comment on the
README.mdfile within the change suggesting a sample sentence. -
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.
-
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.