Working with Git and Gerrit » History » Version 39

Peter Niederlag, 2011-03-01 15:59

1 1 Karsten Dambekalns
h1. Working with Git and Gerrit Code Review
2 22 Karsten Dambekalns
3
{{>toc}}
4 1 Karsten Dambekalns
5 38 Peter Niederlag
The TYPO3 project uses Git and the Gerrit Code Review system to channel commits for review.
6 20 Karsten Dambekalns
7 29 Bastian Waidelich
Here is what you need to know to contribute, more details on Git are available in the "Pro Git book":http://progit.org/book/, the "Gerrit documentation":https://review.typo3.org/Documentation/index.html and other resources (see "helpful links" section below).
8 1 Karsten Dambekalns
9 28 Karsten Dambekalns
h2. What <projectname> means in this documentation
10
11 38 Peter Niederlag
When we use <projectname> in the following documentation and examples, this means the project name as used in gerrit. If you are unsure you can find out the correct URL to clone from by going to http://git.typo3.org and copy it from the summary page of the project you're interested in. Here are some examples of <projectname>:
12 28 Karsten Dambekalns
13
TYPO3v5/Distributions/Base
14 38 Peter Niederlag
TYPO3v4/Core
15 28 Karsten Dambekalns
16 26 Karsten Dambekalns
h2. Quickstart Guides
17 1 Karsten Dambekalns
18 26 Karsten Dambekalns
* For a quick "Getting Started" guide, see the [[Gerrit and Git Quickstart]]
19
* Here is a transcript of a session [[Cloning the FLOW3 Base Distribution]]
20
* Here is a transcript of a session [[Cloning the TYPO3 Phoenix Base Distribution]]
21 25 Sebastian Kurfuerst
22 26 Karsten Dambekalns
*Note:* Take time to learn and explore git and gerrit!
23
24 1 Karsten Dambekalns
h2. Git
25 24 Karsten Dambekalns
26 32 Stefano Kowalke
* See [[Working with Git]]
27 1 Karsten Dambekalns
28 24 Karsten Dambekalns
h2. Gerrit Code Review
29 1 Karsten Dambekalns
30
h3. Registering with gerrit
31
32 26 Karsten Dambekalns
To register with gerrit, you need to have an account on typo3.org. Then visit https://review.typo3.org/ and log in using your typo3.org username and password. Click on 'Settings' -> 'Profile', and check that gerrit correctly knows your name and email address (it should; if not it might take a while for the synchronization to take place).
33 1 Karsten Dambekalns
34
In order to be able to upload code, you now need to create a ssh key that gerrit can use to identify you, or tell gerrit about one that already exists.
35
36
To create a new ssh key, if you don't already have one, run
37
<pre>ssh-keygen -t dsa -f ~/.ssh/id_dsa</pre>
38
The public key for this is now stored in ~/.ssh/id_dsa.pub.
39 23 Karsten Dambekalns
40
To tell gerrit about your key, log in, and go to 'Settings'. Select 'SSH Keys', and paste your public key into the "Add SSH Public Key" box, or click on the 'Open Key...' option to load it from the filesystem. Click on 'Add' to add the new public key.
41 27 Karsten Dambekalns
42 31 Stefano Kowalke
h3. Setting up ssh config
43
44 1 Karsten Dambekalns
To make things easier, set up ssh so that it knows about the defaults for the gerrit server. Edit @~/.ssh/config@, and add a section like:
45
<pre>Host review.typo3.org 
46 23 Karsten Dambekalns
User <username> 
47 34 Stefano Kowalke
Hostname review.typo3.org
48 1 Karsten Dambekalns
IdentityFile ~/.ssh/id_dsa 
49
Port 29418</pre>
50 23 Karsten Dambekalns
(where <username> is what you logged in with, i.e. your typo3.org username)
51 1 Karsten Dambekalns
52 23 Karsten Dambekalns
To verify your ssh key is working correctly, try using an ssh client to connect to gerrit. You should get the following output if it all works:
53 1 Karsten Dambekalns
<pre>$ ssh review.typo3.org
54 23 Karsten Dambekalns
gerrit: no shell available
55
Connection to review.typo3.org closed.</pre>
56 4 Karsten Dambekalns
57 30 Karsten Dambekalns
Now you can configure git to push to Gerrit whenever you clone something from git.tyo3.org. All you need to do (for git > 1.6.4) is this
58
59
<pre>git config --global url."ssh://review.typo3.org".pushInsteadOf git://git.typo3.org</pre>
60
61
Now you can clone from git://git.typo3.org and a push on that clone would go into ssh://git.typo3.org using your configure username and port from above.
62
63 36 Stefano Kowalke
h3. The Change-Id hook
64
65
Gerrit introduces the concept of "Change IDs". This is a unique reference for a particular change, which remains constant regardless of any changes that are made to the implementation. This allows a single reference to be attached to a given modification, irrespective of any rewrites that may occur as a result of review comments. Manually maintaining change ids is a pain, so gerrit provides a git hook which can be used to automatically add a change id to any new modifications you create.
66
67
Because hooks cannot be transferred with a clone of a project, you must copy them to your @.git/hooks@ directory and make them executable. The hook can be downloaded from the gerrit server by running the following in the top level of your git tree
68
<pre>scp -p -P 29418 review.typo3.org:hooks/commit-msg .git/hooks/</pre>
69
70
*Do this for every working copy you clone!* Make sure the hook is marked as executable after it is installed (scp should take care of this)!
71
72
When using a superproject with submodules, you can use this to install the hook for every submodule:
73
<pre>git submodule foreach 'scp -p -P 29418 review.typo3.org:hooks/commit-msg .git/hooks/'</pre>
74
75
If you cannot use scp (you should, it takes care of permissions automatically!), you can download the hook via HTTP, e.g. using @curl@, @wget@ or a browser, from
76
<pre>https://review.typo3.org/tools/hooks/commit-msg</pre>
77
78
*Windows users*: If you are using msysgit, the hook and scp work as shown here, simply use the git shell included with msysgit.
79
80 37 Stefano Kowalke
h3. Differend roles for Gerrit
81 1 Karsten Dambekalns
82 37 Stefano Kowalke
The things we did until now described more generally the settings for git and gerrit on your machine.
83
Now we will get in touch with the two main roles you can have in gerrit.
84
85
* [[Working with Gerrit as a Developer]]
86
* [[Working with Gerrit as a Reviewer]]
87 29 Bastian Waidelich
88
h2. Helpful links
89
90
* "Git Homepage":http://www.git-scm.com/
91
* "Pro Git book":http://progit.org/book/
92
* "Git ready - tutorials":http://gitready.com/
93
* "Gerrit documentation":https://review.typo3.org/Documentation/index.html
94 4 Karsten Dambekalns
95
h2. Thanks
96 1 Karsten Dambekalns
97
... to the folks over at "OpenAFS":http://openafs.org/ that made us stumble over gerrit and whose wiki page we shamelessly used as a base for this page.
98 2 Karsten Dambekalns
99
... to Sebastian Kurf├╝rst, Peter Niederlag, Christopher Hlubek for their help with git, gerrit and redmine.
100
101 23 Karsten Dambekalns
... Bastian Waidelich for being the brave Windows test user.
102 26 Karsten Dambekalns
103
... to Shawn Pearce for being helpful on the gerrit mailing list.
104 5 Karsten Dambekalns
105 1 Karsten Dambekalns
... to the TYPO3 Core Team for being open towards a change in SCM flavor.