Jump to: navigation, search

Difference between revisions of "Gerrit Workflow"

(Running System Tests: Replaced content with reference to where it appears on the Testing page)
(Replaced content with "Please see the new Developer's Guide here: http://docs.openstack.org/infra/manual/developers.html")
(28 intermediate revisions by 12 users not shown)
Line 1: Line 1:
 
+
Please see the new Developer's Guide here: http://docs.openstack.org/infra/manual/developers.html
= 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 [[GerritJenkinsGit]].
 
 
 
[[File:Contribution path.png]]
 
 
 
== Account Setup ==
 
You'll need a [https://launchpad.net/+login Launchpad account], since this is how the Web interface for the Gerrit Code Review system will identify you. This is also useful for automatically crediting bug fixes to you when you address them with your code commits.
 
 
 
If you haven't already, [https://www.openstack.org/join/ join The OpenStack Foundation] (it's free and required for all code contributors). Among other privileges, this also allows you to vote in elections and run for elected positions within The OpenStack Project. When signing up for Foundation Membership, make sure to give the same E-mail address you'll use for code contributions, since this will need to match your preferred E-mail address in Gerrit.
 
 
 
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.
 
 
Unless you are an U.S. Government Employee (see below), [https://review.openstack.org/#/settings/agreements agree to the Individual Contributor License Agreement] and provide contact information. Your full name and E-mail address will be public (since they also appear in project commit logs) and the latter needs to match the user.email in your Git configuration. The other contact information (postal address, phone numbers) will be kept confidential and is only used as a fallback record in the unlikely event The OpenStack Foundation needs to reach you directly over code contribution related matters. This contact information can also be easily [https://review.openstack.org/#/settings/contact updated] later if desired, but make sure the primary E-mail address always matches the one you set for your OpenStack Foundation Membership--otherwise Gerrit will give you an error message and refuse to accept your contact information.
 
 
Employees of the the U.S. Government do not sign the Individual CLA. Instead, someone with authority to sign on behalf of your agency should sign the [[GovernmentCLA|U.S. Government Contributor License Agreement]]. Please contact the OpenStack Foundation to initiate this process.
 
 
If you are '''contributing on behalf of a company''' or organization, you still need to sign the ICLA above but someone at your company or organization also needs to sign the [https://review.openstack.org/#/settings/agreements Corporate Contributor License Agreement] providing a list of people authorized to commit code to OpenStack. Check [[HowToUpdateCorporateCLA|How to update the CCLA]] to provide changes to such list. A list of current companies and organizations with an existing [[Contributors/Corporate|Corporate CLA]] is available for your review.
 
 
 
You'll also want to [https://review.openstack.org/#/settings/ssh-keys upload an SSH key] while you're at it, so that you'll be able to [[GerritWorkflow#Committing_Changes|commit changes for review]] later.
 
 
 
Ensure that you have run these steps to let git know about your email address:
 
 
 
<pre><nowiki>
 
git config --global user.name "Firstname Lastname"
 
git config --global user.email "your_email@youremail.com"
 
</nowiki></pre>
 
 
 
To check your git configuration:
 
 
 
<pre><nowiki>
 
git config --list
 
</nowiki></pre>
 
 
 
== 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, MacOSx, or most other Unix-like systems, it is as simple as:
 
 
 
<pre><nowiki>
 
pip install git-review
 
</nowiki></pre>
 
 
 
On Ubuntu Precise (12.04) and later, git-review is included in the distribution, so install it as any other package:
 
 
 
<pre><nowiki>
 
apt-get install git-review
 
</nowiki></pre>
 
 
 
On Fedora 16 and later, git-review is included into the distribution, so install it as any other package:
 
 
 
<pre><nowiki>
 
yum install git-review
 
</nowiki></pre>
 
 
 
On Fedora 15 and earlier you have to install pip (its package name is `python-pip`), then install git-review using pip in a conventional way.
 
 
 
On Red Hat Enterprise Linux, you must first enable the [http://fedoraproject.org/wiki/EPEL EPEL] repository, then install it as any other package:
 
 
 
<pre><nowiki>
 
yum install git-review
 
</nowiki></pre>
 
 
 
On openSUSE 12.2 and later, git-review is included in the distribution under the name python-git-review, so install it as any other package:
 
<pre><nowiki>
 
zypper in python-git-review
 
</nowiki></pre>
 
 
 
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.
 
 
 
== Project Setup (if you plan to run only unit tests) ==
 
Clone a project in the usual way, for example:
 
 
 
<pre><nowiki>
 
git clone git://git.openstack.org/openstack/nova.git
 
</nowiki></pre>
 
 
 
You may want to ask git-review to configure your project to know about Gerrit at this point.  If you don't, it will do so the first time you submit a change for review, but you probably want to do this ahead of time so the Gerrit Change-Id commit hook gets installed.  To do so (again, using Nova as an example):
 
 
 
<pre><nowiki>
 
cd nova
 
git review -s
 
</nowiki></pre>
 
 
 
Git-review checks that you can log in to gerrit with your ssh key. It assumes that your gerrit/launchpad user name is the same as the current running user.  If that doesn't work, it asks for your gerrit/launchpad user name. If you don't remember the user name go to the [https://review.openstack.org/#/settings/ settings page on gerrit] to check it out (it's not your email address).
 
 
 
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.
 
 
 
<pre><nowiki>
 
git remote add gerrit ssh://<username>@review.openstack.org:29418/openstack/nova.git
 
</nowiki></pre>
 
 
 
In the project directory, you have a `.git` hidden directory and a `.gitreview` hidden file. You can see them with:
 
 
 
<pre><nowiki>
 
ls -la
 
</nowiki></pre>
 
 
 
== Project Setup (if you plan to run system tests) ==
 
 
 
Use [[DevStack]] to fetch, configure, and run all the projects you want in your system.  DevStack will do the "git clone" for each of the projects, to a destination you may define in your DevStack config file.  In the projects on which you want to work, do the git review setup as above.
 
 
 
== Normal Workflow ==
 
Once your local repository is set up as above, you must use the following workflow.
 
 
 
Make sure you have the latest upstream changes:
 
 
 
<pre><nowiki>
 
git remote update
 
git checkout master
 
git pull --ff-only origin master
 
</nowiki></pre>
 
 
 
Create a [http://git-scm.com/book/en/Git-Branching-Branching-Workflows#Topic-Branches 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 (for example, "bp/authentication").  The general convention when working on bugs is to name the branch '''bug/BUG-NUMBER''' (for example, "bug/1234567"). Otherwise, give it a meaningful name because it will show up as the topic for your change in Gerrit.
 
 
 
<pre><nowiki>
 
git checkout -b TOPIC-BRANCH
 
</nowiki></pre>
 
 
 
To generate documentation artifacts, navigate to the directory where the pom.xml file is located for the project and run the following command:
 
 
 
<pre><nowiki>
 
mvn clean generate-sources
 
</nowiki></pre>
 
 
 
For complete information about generating documentation artifacts, see "Build Output Locally" on the https://wiki.openstack.org/wiki/Documentation/HowTo page.
 
 
 
=== Running Unit Tests ===
 
 
 
See also [[Testing]] and [https://github.com/openstack/oslo-incubator/blob/master/TESTING.rst oslo-incubator/TESTING.rst].
 
 
 
Use [http://testrun.org/tox/latest/ tox] to run the unit tests in a virtualenv.  At the moment there is a bug in the latest tox; see https://bugs.launchpad.net/openstack-ci/+bug/1274135 for a workaround.
 
 
 
Most projects configure tox to use testr to run the tests; see [[Testr]].  In such cases you have the option to use testr to run the tests without a virtualenv, if your main environment is suitable.
 
 
 
There is an obsolescent convention, as follows.  Most projects have a shell script, named "run_tests.sh", that runs the unit tests of that project.  To invoke it, simply "cd" to the project's directory and invoke the script.  For example, to run the Nova unit tests in a default DevStack installation,
 
<pre><nowiki>
 
cd /opt/stack/nova
 
./run_tests.sh
 
</nowiki></pre>
 
 
 
=== Running System Tests ===
 
 
 
See [[Testing#IntegrationTests|IntegrationTests on the Testing page]].
 
 
 
=== Committing Changes ===
 
Prior to checking in make sure that you [[Testing#Unit_Tests|run the unit tests]].
 
 
 
[[GitCommitMessages|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:
 
 
 
<pre><nowiki>
 
Implements: blueprint BLUEPRINT
 
Closes-Bug: ####### (Partial-Bug or Related-Bug are options)
 
</nowiki></pre>
 
 
 
For example:
 
 
 
<pre><nowiki>
 
Adds keystone support
 
 
 
...Long multiline description of the change...
 
 
 
Implements: blueprint authentication
 
Closes-Bug: #123456
 
Change-Id: I4946a16d27f712ae2adf8441ce78e6c0bb0bb657
 
</nowiki></pre>
 
 
 
Note that in most cases the Change-Id line should be automatically added by a Gerrit commit hook that you will want to install.  See [[Gerrit_Workflow#Project_Setup|Project Setup]] for details on configuring your project for Gerrit.  If you already made the commit and the Change-Id was not added, do the Gerrit setup step and run:
 
<pre>git commit --amend</pre>
 
The commit hook will automatically add the Change-Id when you finish amending the commit message, even if you don't actually make any changes.
 
 
 
Make your changes, commit them, and submit them for review:
 
<pre><nowiki>
 
git commit -a
 
git review
 
</nowiki></pre>
 
 
 
'''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.
 
 
 
=== Review ===
 
Once the code is committed, it appears at https://review.openstack.org. Please refer http://wiki.openstack.org/GerritJenkinsGit for more information. If the link corresponding to your code is clicked, it shows the status and other information. Automatic testing occurs and the results are displayed. Reviewers comment in the comment box or in the code itself.
 
 
 
If someone leaves an in-line comment, you can see it from expanded "Patch Set." "Comments" column shows how many comments are in each file. If you click a file name that has comments, the new page shows a diff page with the reviewer's name and comments. Click "Reply" and write your response. It is 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.
 
 
 
More on what happens next is described on [[GerritJenkinsGit#Reviewing_a_Change]].
 
 
 
=== Work in Progress ===
 
 
 
A change can be marked Work in Progress if, for example, it is not ready for merging, or even general code review, but you would still like to get early comments. Marking a change work in progress is simple, just click the "Work In Progress" button under the latest patchset of a change to mark it as a work in progress. Changes in this state are public and can be viewed by everyone. Authenticated users can leave comments as they would in normal code review, but changes in this state cannot be submitted for merging. This allows you to solicit early feedback without worry that incomplete changes will be accidentally merged.
 
 
 
<pre><nowiki>
 
git commit -a
 
git review
 
# Go to change in Gerrit web UI and click "Work In Progress" button under most recent patchset.
 
</nowiki></pre>
 
 
 
'''Caution: The Draft feature in Gerrit may be tempting, but it is not friendly to the CI systems and should not be used. Use the Work in Progress feature instead.'''
 
 
 
=== 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 must 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 becomes a change in Gerrit, and must 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:
 
 
 
<pre><nowiki>
 
git checkout master
 
git pull origin master
 
git checkout TOPIC-BRANCH
 
git rebase -i master
 
</nowiki></pre>
 
 
 
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 can prepare your public commit message(s) in your editor.  You 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:
 
 
 
<pre><nowiki>
 
git commit -a --amend
 
git review
 
</nowiki></pre>
 
 
 
=== Add dependency ===
 
When you want to start new work that is based on the commit under the review, you can add the commit as a dependency.
 
 
 
<pre><nowiki>
 
#fetch change under review and check out branch based on that change.
 
git review -d $PARENT_CHANGE_NUMBER
 
git checkout -b $DEV_TOPIC_BRANCH
 
# Edit files, add files to git
 
git commit
 
git review
 
</nowiki></pre>
 
 
 
* '''NOTE:''' git review rebases the existing change (the dependency) and the new commit if there is a conflict against the branch they are being proposed to. Typically this is desired behavior as merging cannot happen until these conflicts are resolved. If you don't want to deal with new patchsets in the existing change immediately you can pass the -R option to git review in the last step above to prevent rebasing. This requires future rebasing to resolve conflicts.
 
 
 
 
 
If the commit your work depends on is updated, and you need to get the latest patch from the depended commit, you can do the following.
 
 
 
<pre><nowiki>
 
# fetch and checkout the parent change
 
git review -d $PARENT_CHANGE_NUMBER
 
# Note the branch created by git review. Should be review/$USER/$PARENT_CHANGE_ID or similar.
 
# Checkout existing development topic branch for the child commit.
 
git checkout $DEV_TOPIC_BRANCH
 
# Rebase onto updated parent branch to create a dependency on the latest version of that change.
 
git rebase -i review/$USER/$PARENT_CHANGE #This is the branch created by git review that was noted earlier.
 
# Do the revisions
 
git commit -a --amend
 
# submit for review
 
git review
 
</nowiki></pre>
 
 
 
The note for the previous example applies here as well. Typically you want the rebase behavior in git review. If you would rather postpone resolving merge conflicts you can use git review -R as the last step above.
 

Revision as of 00:46, 27 February 2015

Please see the new Developer's Guide here: http://docs.openstack.org/infra/manual/developers.html