Gerrit Workflow Quick Reference
Use this section as a quick reference for commands that you need to run to begin work in a new repository. Read this entire section before you complete the steps in the workflow for the first time. Then, review this section when you start work on a new OpenStack project.
For a more complete description of the setup, see GerritJenkinsGithub.
Make sure you have a launchpad account, and you have uploaded your ssh public keys to it.
Visit https://review.openstack.org/ and click the Sign In link at the top-right corner of the page. Log in with your Launchpad ID.
Because Gerrit uses Launchpad OpenID single sign-on, you won't need a separate password for Gerrit, and once you log in to one of Launchpad, Gerrit, or Jenkins, you won't have to enter your password for the others.
Gerrit accounts are automatically synchronized with Launchpad, so your Gerrit account should already have the same username, full name, email address, ssh keys, and group membership.
Some information in Launchpad is not publicly available and so may not be copied over. The first time you log into Gerrit, you should click the Settings link at the top of the page, and then make sure that your Contact Information, SSH Public Keys, and Groups look correct. If not, please register your email address and SSH keys.
Ensure that you have run these steps to let git know about your email address:
git config --global user.name "Firstname Lastname" git config --global user.email "email@example.com"
To check your git configuration:
git config --list
Git Review Installation
We recommend using the "git-review" tool which is a git subcommand that handles all the details of working with Gerrit, the code review system used in OpenStack development. Before you start work, make sure you have git-review installed on your system.
On Ubuntu, or most other Unix-like systems, it is as simple as:
pip install git-review
On Ubuntu Precise (12.04) and later, git-review is included in the distribution, so install it as any other package:
apt-get install git-review
On Fedora 16 and later, git-review is included into the distribution, so install it as any other package:
yum install git-review
On Fedora 15 and earlier, or on Red Hat Enterprise Linux, you have to install pip (its package name is `python-pip`), then install git-review using pip in a conventional way.
All of git-review's interactions with gerrit are sequences of normal git commands. If you want to know more about what it's doing, just add -v to the options and it will print out all of the commands it's running.
Clone a project in the usual way, for example:
git clone git://github.com/openstack/nova.git
You may want to ask git-review to configure your project to know about Gerrit at this point (though if you don't, it will do so the first time you submit a change for review). To do so (again, using Nova as an example):
cd nova git review -s
Git-review will check that you can log into gerrit with your ssh key. It assumes that your gerrit/launchpad username is the same as the current running user. If that doesn't work, it will ask for your gerrit/launchpad username.
Note that you can verify the SSH host keys for review.openstack.org here: https://review.openstack.org/#/settings/ssh-keys
If you get the error "We don't know where your gerrit is.", you will need to add a new git remote. The url should be in the error message. Copy that and create the new remote.
git remote add gerrit ssh://<username>@review.openstack.org:29418/openstack/nova.git
In the project directory, you have a `.git` hidden directory and a `.gitreview` hidden file. You can see them with:
Once your local repository is set up as above, you must use the following workflow.
Make sure you have the latest upstream changes:
git remote update git checkout master git pull origin master
Create a topic branch to hold your work and switch to it. If you are working on a blueprint, name your topic branch bp/BLUEPRINT where BLUEPRINT is the name of a blueprint in launchpad (e.g., "bp/authentication"). The general convention when working on bugs is to name the branch bug/BUG-NUMBER (e.g., "bug/1234567"). Otherwise, give it a meaningful name because it will show up as the topic for your change in Gerrit.
git checkout -b TOPIC-BRANCH
Git commit messages should start with a short 50 character or less summary in a single paragraph. The following paragraph(s) should explain the change in more detail.
If your changes addresses a blueprint or a bug, be sure to mention them in the commit message using the following syntax:
blueprint BLUEPRINT bug #######
Adds keystone support ...Long multiline description of the change... Implements: blueprint authentication Fixes: bug #123456 Change-Id: I4946a16d27f712ae2adf8441ce78e6c0bb0bb657
Make your changes, commit them, and submit them for review:
git commit -a git review
Caution: Do not check in changes on your master branch. Doing so will cause merge commits when you pull new upstream changes, and merge commits will not be accepted by Gerrit.
Prior to checking in make sure that you run "tox".
Once the code is committed, it appears at https://review.openstack.org. Please refer http://wiki.openstack.org/GerritJenkinsGithub for more information. If the link corresponding to your code is clicked, it will show the status and other information. Automatic testing will be done and the results will be displayed once they are complete. Reviewers will come and review and leave comments in the comment box or in the code itself.
If there is an in-line comment, you can see it from expanded "Patch Set." "Comments" column will show how many comments are in each file. If you click a file name that has comments, the new page will show a diff page with the reviewer's name and comments. Click "Reply" and write your response. It will be saved as a draft if you click "Save." Now, go back to the page that shows a list of patch sets and click "Review," and then, click "Publish comments."
If your code is not ready for review, click "Work in Progress" to indicate that a reviewer does not need to review it for now. Note that the button is invisible until you login the site.
A change can be submitted as a draft if, for example, it's not ready for merging, or even general code review, but you would like to share it selectively to get early comments. If you upload a change as a draft, by default, no one else can see it. You must explicitly add each person you would like to share it with as a reviewer. Reviewers you add can leave comments, but cannot vote at this stage. You can continue to upload new patchsets to the change as it evolves, and once it is ready for general review, you can click the "Publish" button. It will then become a normal change in Gerrit that everyone can see, including the earlier reviews from the draft stage. This is a one way transition; once a draft is published, it can't be made a draft again.
A draft change is uploaded by adding the "-D" option. Simply make changes, commit them, and submit them as a draft:
git commit -a git review -D
Caution: Earlier versions (prior to 1.16) of git-review may also have the "-D" option, but the git ref that Gerrit uses to indicate a change should be a draft was changed; so if using "-D" results in an error, you may need to upgrade to latest.
Long-lived Topic Branches
If you are working on a larger project, you may be working on your topic branch for a while. In that case, you may want to check in your changes frequently during development and you will need to rebase your change to the current state of the master repository before submitting it for code review. In these situations you should prepare your change carefully before submitting it.
If the master repository has changed since you started, you should rebase your changes to the current state. And if you have made many small commits, you should squash them so that they do not show up in the public repository. Remember: each commit will become a change in Gerrit, and need to be approved separately. If you are making one "change" to the project, squash your many "checkpoint" commits into one commit for public consumption. Here's how to do both of those:
git checkout master git pull origin master git checkout TOPIC-BRANCH git rebase -i master
Use the editor to squash any commits that should not appear in the public history. If you want one change to be submitted to Gerrit, you should only have one "pick" line at the end of this process. After completing this, you will be able to prepare your public commit message(s) in your editor. You will start with the commit message from the commit that you picked, and it should have a Change-Id line in the message. Be sure to leave that Change-Id line in place when editing.
Once the commit history in your branch looks correct, run git review to submit your changes to Gerrit.
Updating a Change
If the code review process suggests additional changes, make and amend the changes to the the existing commit. Leave the existing Change-Id: footer in the commit message as-is. Gerrit knows that this is an updated patch for an existing change:
git commit -a --amend git review
When you wanna start new work on the commit under the review. You can add the commit as dependencies.
#fetch config git fetch https://review.openstack.org/openstack/nova refs/changes/16/10816/9 && git checkout FETCH_HEAD git checkout -b SOMEBRANCHNAME git review -R
- NOTE* -R option is very important. If you omit the -R option, the original commit is updated by mistake.