Git: Difference between revisions

From coreboot
Jump to navigation Jump to search
No edit summary
(Link to Peter's Git intro on the mailing list, describe correct commit message format, and add tips and information for pushing commits)
Line 4: Line 4:
== Register with gerrit ==
== Register with gerrit ==
For authenticated access (to submit patches) you'll need a gerrit account which you can register at http://review.coreboot.org/.
For authenticated access (to submit patches) you'll need a gerrit account which you can register at http://review.coreboot.org/.
You also need to add your ssh keys (which are used for authenticating your connections to the repo) and your email addresses (used to match up signed-off-by: statements) to your gerrit user data at http://review.coreboot.org/#settings
You also need to add your ssh key(s) (used for authenticating your connections to the repo) and your email address(es) (used to match up Signed-off-by: statements) to your gerrit user data at http://review.coreboot.org/#settings


=== OpenID ===
=== OpenID ===
It seems that gerrit is picky about the OpenID format. Always provide a full URL, including protocol (ie. http:// or https:// prefix). Unfortunately its error message is non-intuitive.
It seems that gerrit is picky about the OpenID format. Always provide a full URL, including protocol (ie. http:// or https:// prefix). Unfortunately the error messages are non-intuitive.


== Gerrit workflow ==
== Gerrit workflow ==
Gerrit interprets commits as individual changes. These are be autobuilt by Jenkins, and can be reviewed by developers. Once they get a positive review and have no build issues, they can be merged to the master branch. Thus, no developer directly pushes to master.
Gerrit interprets each Git commit as an individual change. Changes are autobuilt by Jenkins, and can be reviewed by developers. Once a change has gotten a positive review and have no build issues, it is applied to the master branch. Thus, no developer directly pushes to master.


Reviews grant points on a scale from -2 to 2. The meaning is:
Reviews grant points on a scale from -2 to 2. The meaning is:
Line 45: Line 45:
  wget -O .git/hooks/commit-msg http://review.coreboot.org/tools/hooks/commit-msg
  wget -O .git/hooks/commit-msg http://review.coreboot.org/tools/hooks/commit-msg


== pushing changes ==
= Working with Git =
When you committed your changes locally, you can push them to the server using
  git push origin HEAD:refs/for/master


This will create a review request per commit on gerrit.
Git is a distributed version control system. This means that you can manage commits and branches completely without restriction in your local clone of the coreboot repository. Peter wrote [http://www.coreboot.org/pipermail/coreboot/2011-June/065427.html a Git introduction] after the switch to use Git was announced on the mailing list.


For automating some aspects of patch submission (ie. simplify the command line), see the last paragraph of http://review.coreboot.org/Documentation/user-upload.html#push_create
== Commit messages ==
Git does not enforce a commit message style, although maybe it should. For all aspects of Git to work the best, it's important to follow these simple guidelines for commit messages:


= Using git =
1. The first line of the commit message has a short (less than 65 characters) summary
2. The second line is empty (no whitespace at all)
3. The third and any number of following lines contain a longer description of the commit as is neccessary, including relevant background information and quite possibly rationale for why the issue was solved in this particular way. These lines should never be longer than 75 characters.
4. The next line is empty (no whitespace at all)
5. A Change-Id: line is added to let gerrit track this logical change
6. A Signed-off-by: line is added according to [[Development_Guidelines#Sign-off_Procedure|the development guidelines]]


There are tons of git tutorials out there, it's probably a waste of time to start yet another.
Please do not create Change-Id: and Signed-off-by: manually because it is boring and error-prone. Instead, please install the commit-hook as described [[#Authenticated_read/write_access|above]] or by running:
make gitconfig


So take a look at http://git-scm.com/, http://www.kernel.org/pub/software/scm/git/docs/v1.7.5.4/gittutorial.html, http://git.or.cz/course/svn.html.
And remember to always use git commit -s to make git add your Signed-off-by: automatically.
 
Here is an example of a correctly formatted commit message:
examplecomponent: Refactor duplicated setup into a function
Setting up the demo device correctly requires the exact same register
values to be written into each of the PCI device functions. Moving the
writes into a function allows also otherexamplecomponent to use them.
Signed-off-by: Joe Hacker <joe@hacker.email>
 
== Pushing changes ==
First ensure that the git remote you want to use for pushing refers to an ssh:// URL (see Authenticated read/write access above). If you need to change this after the fact, ie. if you registered on gerrit only after having cloned anonymously, you can. Assuming that your remote is called ''origin'' (this is the default) you can run:
git config remote.origin.url ssh://<username>@review.coreboot.org:29418/coreboot
 
Then run the following command once to tell git that by default you want to submit all commits in the currently checked-out branch for review on gerrit:
git config remote.origin.push HEAD:refs/for/master
 
After this, the command to push your changes is:
git push origin
 
If you always push from one particular branch it is further convenient to run:
git config branch.<particularbranchname>.remote origin
 
And then you push changes simply by:
git push
 
Pushing several commits not yet in the coreboot repository at once will create one review request on gerrit per commit. '''NB!''' If you have applied patches from gerrit on a branch and you push that branch gerrit will think you are submitting new versions of those patches. This may or may not be what you intend, so please run git log origin/master.. before git push and verify that you are will submit the intended commits.
 
For automating patch submission further (ie. more ways of simplifying the command line), see the last paragraph of http://review.coreboot.org/Documentation/user-upload.html#push_create
 
== Further Git reading ==
There are tons of git tutorials out there. Take a look at http://git-scm.com/, http://www.kernel.org/pub/software/scm/git/docs/v1.7.5.4/gittutorial.html, http://git.or.cz/course/svn.html and in particular the http://progit.org/ book.


= Browsing =
= Browsing =

Revision as of 23:37, 8 June 2011

Gerrit

As part of our move to gerrit, git was introduced as primary SCM.

Register with gerrit

For authenticated access (to submit patches) you'll need a gerrit account which you can register at http://review.coreboot.org/. You also need to add your ssh key(s) (used for authenticating your connections to the repo) and your email address(es) (used to match up Signed-off-by: statements) to your gerrit user data at http://review.coreboot.org/#settings

OpenID

It seems that gerrit is picky about the OpenID format. Always provide a full URL, including protocol (ie. http:// or https:// prefix). Unfortunately the error messages are non-intuitive.

Gerrit workflow

Gerrit interprets each Git commit as an individual change. Changes are autobuilt by Jenkins, and can be reviewed by developers. Once a change has gotten a positive review and have no build issues, it is applied to the master branch. Thus, no developer directly pushes to master.

Reviews grant points on a scale from -2 to 2. The meaning is:

  • -2: Do not merge (blocks gerrit from merging)
  • -1: I'd prefer you don't merge it
  • 0: neutral
  • +1: Looks good, but I won't make the last call on it
  • +2: Looks good, go ahead and merge (gerrit provides a "submit" function once it has a +2 vote)

-2 and +2 are only available to core developers as it's comparable to commit rights in SVN.

Gerrit and CLI

Reviews normally happens through the website.

Since gerrit exposes an interface through its ssh daemon, it's also possible to do reviews from CLI or mail. Unfortunately there doesn't seem to be any standing tradition on how to build a workflow around these parts, so we'll document our best practices here once they settled.

Gerrit and Email

Gerrit has poor email integration (in fact, it doesn't really have any at all). We send a couple of notifications to the mailing list, but that is a coreboot specific extension. Peter intends to build a mail-to-gerrit gateway should the need arise.

This gateway will provide:

  • no patch submission mechanism ("git push" is CLI friendly)
  • patch review (maybe openpgp signed "Acked-by" mails)
  • patch submission (automatically with Acked-by?)
  • maybe patch rejection? (openpgp signed "Nacked-by" mails)

Anonymous read access

Read-only access is available anonymously:

git clone http://review.coreboot.org/p/coreboot

Authenticated read/write access

git clone ssh://<username>@review.coreboot.org:29418/coreboot

Inside the checkout you should install the commit-msg hook which prepares commit messages to fit the style required by gerrit. This needs to happen only once per clone and can be done with

wget -O .git/hooks/commit-msg http://review.coreboot.org/tools/hooks/commit-msg

Working with Git

Git is a distributed version control system. This means that you can manage commits and branches completely without restriction in your local clone of the coreboot repository. Peter wrote a Git introduction after the switch to use Git was announced on the mailing list.

Commit messages

Git does not enforce a commit message style, although maybe it should. For all aspects of Git to work the best, it's important to follow these simple guidelines for commit messages:

1. The first line of the commit message has a short (less than 65 characters) summary 2. The second line is empty (no whitespace at all) 3. The third and any number of following lines contain a longer description of the commit as is neccessary, including relevant background information and quite possibly rationale for why the issue was solved in this particular way. These lines should never be longer than 75 characters. 4. The next line is empty (no whitespace at all) 5. A Change-Id: line is added to let gerrit track this logical change 6. A Signed-off-by: line is added according to the development guidelines

Please do not create Change-Id: and Signed-off-by: manually because it is boring and error-prone. Instead, please install the commit-hook as described above or by running:

make gitconfig

And remember to always use git commit -s to make git add your Signed-off-by: automatically.

Here is an example of a correctly formatted commit message:

examplecomponent: Refactor duplicated setup into a function

Setting up the demo device correctly requires the exact same register
values to be written into each of the PCI device functions. Moving the
writes into a function allows also otherexamplecomponent to use them.

Signed-off-by: Joe Hacker <joe@hacker.email>

Pushing changes

First ensure that the git remote you want to use for pushing refers to an ssh:// URL (see Authenticated read/write access above). If you need to change this after the fact, ie. if you registered on gerrit only after having cloned anonymously, you can. Assuming that your remote is called origin (this is the default) you can run:

git config remote.origin.url ssh://<username>@review.coreboot.org:29418/coreboot

Then run the following command once to tell git that by default you want to submit all commits in the currently checked-out branch for review on gerrit:

git config remote.origin.push HEAD:refs/for/master

After this, the command to push your changes is:

git push origin

If you always push from one particular branch it is further convenient to run:

git config branch.<particularbranchname>.remote origin

And then you push changes simply by:

git push

Pushing several commits not yet in the coreboot repository at once will create one review request on gerrit per commit. NB! If you have applied patches from gerrit on a branch and you push that branch gerrit will think you are submitting new versions of those patches. This may or may not be what you intend, so please run git log origin/master.. before git push and verify that you are will submit the intended commits.

For automating patch submission further (ie. more ways of simplifying the command line), see the last paragraph of http://review.coreboot.org/Documentation/user-upload.html#push_create

Further Git reading

There are tons of git tutorials out there. Take a look at http://git-scm.com/, http://www.kernel.org/pub/software/scm/git/docs/v1.7.5.4/gittutorial.html, http://git.or.cz/course/svn.html and in particular the http://progit.org/ book.

Browsing

There is no code browser that's properly synced with our gerrit instance at this time. This is a work in progress.