blob: 45ed8f1553bc8ffc1f5b678538d5b54e1e9f2f76 [file] [log] [blame]
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11001<!--{
2 "Title": "Contribution Guidelines"
3}-->
Russ Coxfb39a4d2009-10-23 15:24:08 -07004
Russ Cox6c7f9f62009-11-09 16:56:17 -08005<h2 id="Introduction">Introduction</h2>
Rob Pike5b72f9c2009-11-01 20:48:21 -08006
7<p>
Russ Coxd55abfd2009-12-09 14:05:12 -08008This document explains how to contribute changes to the Go project.
Andrew Gerrand968f0df2014-12-12 13:53:29 +11009It assumes you have followed the
Jonathan Feinberg452f40f2012-09-26 14:39:31 -040010<a href="/doc/install/source">installation instructions</a> and
Russ Coxd55abfd2009-12-09 14:05:12 -080011have <a href="code.html">written and tested your code</a>.
Andrew Gerrand968f0df2014-12-12 13:53:29 +110012</p>
Andrew Gerrandd708e922014-12-10 09:29:35 +110013
14<p>
Russ Coxd55abfd2009-12-09 14:05:12 -080015(Note that the <code>gccgo</code> frontend lives elsewhere;
Ian Lance Taylor2528f332009-11-06 14:15:41 -080016see <a href="gccgo_contribute.html">Contributing to gccgo</a>.)
Russ Cox38a41ee2009-11-06 10:04:22 -080017</p>
Russ Coxfb39a4d2009-10-23 15:24:08 -070018
Rob Pike96ee38b2009-12-17 12:12:47 +110019<h2 id="Design">Discuss your design</h2>
20
21<p>
22The project welcomes submissions but please let everyone know what
Andrew Gerrand3c10bdd2015-07-31 11:43:57 +100023you're working on if you want to change or add to the Go repositories.
Rob Pike96ee38b2009-12-17 12:12:47 +110024</p>
25
26<p>
Andy Maloneyc53de852015-08-03 10:15:52 -040027Before undertaking to write something new for the Go project,
Andrew Gerrand3c10bdd2015-07-31 11:43:57 +100028please <a href="https://golang.org/issue/new">file an issue</a>
29(or claim an <a href="https://golang.org/issues">existing issue</a>).
30Significant changes must go through the
31<a href="https://golang.org/s/proposal-process">change proposal process</a>
32before they can be accepted.
Rob Pike96ee38b2009-12-17 12:12:47 +110033</p>
34
35<p>
Andrew Gerrand3c10bdd2015-07-31 11:43:57 +100036This process gives everyone a chance to validate the design,
37helps prevent duplication of effort,
38and ensures that the idea fits inside the goals for the language and tools.
39It also checks that the design is sound before code is written;
40the code review tool is not the place for high-level discussions.
Rob Pike96ee38b2009-12-17 12:12:47 +110041</p>
42
Caleb Spare2bd52372015-08-03 17:48:43 -070043<p>
44When planning work, please note that the Go project follows a
45<a href="https://golang.org/wiki/Go-Release-Cycle">six-month
46development cycle</a>. The latter half of each cycle is a three-month
47feature freeze during which only bug fixes and doc updates are accepted.
48New work cannot be submitted during a feature freeze.
49</p>
50
Russ Coxd55abfd2009-12-09 14:05:12 -080051<h2 id="Testing">Testing redux</h2>
Russ Cox830813f2009-11-08 21:08:27 -080052
53<p>
Russ Coxd55abfd2009-12-09 14:05:12 -080054You've <a href="code.html">written and tested your code</a>, but
55before sending code out for review, run all the tests for the whole
56tree to make sure the changes don't break other packages or programs:
Russ Cox38a41ee2009-11-06 10:04:22 -080057</p>
58
59<pre>
Nathan John Youngmand5f208c2014-03-17 09:35:04 +110060$ cd go/src
61$ ./all.bash
Russ Cox38a41ee2009-11-06 10:04:22 -080062</pre>
63
64<p>
Nathan John Youngmand5f208c2014-03-17 09:35:04 +110065(To build under Windows use <code>all.bat</code>.)
66</p>
67
68<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +110069After running for a while, the command should print
70"<code>ALL</code> <code>TESTS</code> <code>PASSED</code>".
Russ Cox38a41ee2009-11-06 10:04:22 -080071</p>
72
Russ Cox6c7f9f62009-11-09 16:56:17 -080073<h2 id="Code_review">Code review</h2>
Russ Cox38a41ee2009-11-06 10:04:22 -080074
75<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080076Changes to Go must be reviewed before they are accepted,
Russ Cox38a41ee2009-11-06 10:04:22 -080077no matter who makes the change.
Andrew Gerrand722f7d22014-12-18 11:42:25 +110078A custom git command called <code>git-codereview</code>,
Andrew Gerrandd708e922014-12-10 09:29:35 +110079discussed below, helps manage the code review process through a Google-hosted
80<a href="https://go-review.googlesource.com/">instance</a> of the code review
81system called <a href="https://code.google.com/p/gerrit/">Gerrit</a>.
Russ Cox38a41ee2009-11-06 10:04:22 -080082</p>
83
Andrew Gerrandd708e922014-12-10 09:29:35 +110084<h3>Set up authentication for code review</h3>
Russ Cox9ad14c92009-11-06 10:33:46 -080085
Russ Cox38a41ee2009-11-06 10:04:22 -080086<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080087Gerrit uses Google Accounts for authentication. If you don't have
88a Google Account, you can create an account which
89<a href="https://www.google.com/accounts/NewAccount">includes
90a new Gmail email account</a> or create an account associated
91<a href="https://accounts.google.com/SignUpWithoutGmail">with your existing
92email address</a>.
Andrew Gerrandd708e922014-12-10 09:29:35 +110093</p>
94
95<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080096The email address associated with the Google Account you use will be recorded in
97the <a href="https://go.googlesource.com/go/+log/">change log</a>
98and in the <a href="/CONTRIBUTORS">contributors file</a>.
Andrew Gerrandd708e922014-12-10 09:29:35 +110099</p>
100
101<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800102To set up your account in Gerrit, visit
103<a href="https://go.googlesource.com">go.googlesource.com</a>
104and click on "Generate Password" in the page's top right menu bar.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100105</p>
106
107<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800108You will be redirected to accounts.google.com to sign in.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100109</p>
110
111<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800112Once signed in, you are returned back to go.googlesource.com to "Configure Git".
113Follow the instructions on the page.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100114(If you are on a Windows computer, you should instead follow the instructions
115in the yellow box to run the command.)
116</p>
117
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800118<p>
119Your secret authentication token is now in a <code>.gitcookie</code> file
120and Git is configured to use this file.
121</p>
122
Andrew Gerrandd708e922014-12-10 09:29:35 +1100123<h3>Register with Gerrit</h3>
124
125<p>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800126Now that you have your authentication token,
127you need to register your account with Gerrit.
128To do this, visit
129<a href="https://go-review.googlesource.com/login/">
130go-review.googlesource.com/login/</a>. You will immediately be redirected
131to Google Accounts. Sign in using the same Google Account you used above.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100132That is all that is required.
133</p>
134
Andy Maloneyc53de852015-08-03 10:15:52 -0400135<h3>Contributor License Agreement</h3>
136
137<p>Gerrit serves as the gatekeeper and uses your e-mail address as the key.
138To send your first change to the Go project from a given address,
139you must have completed one of the contributor license agreements:
140<ul>
141<li>
142If you are the copyright holder, you will need to agree to the
143<a href="https://developers.google.com/open-source/cla/individual">individual
144contributor license agreement</a>, which can be completed online.
145</li>
146<li>
147If your organization is the copyright holder, the organization
148will need to agree to the
149<a href="https://developers.google.com/open-source/cla/corporate">corporate
150contributor license agreement</a>.
151(If the copyright holder for your code has already completed the
152agreement in connection with another Google open source project,
153it does not need to be completed again.)
154</li>
155</ul>
156
157<p>
158You can use the links above to create and sign the contributor license agreement
159or you can show your current agreements and create new ones through the Gerrit
160interface. <a href="https://go-review.googlesource.com/login/">Log into Gerrit</a>,
161click your name in the upper-right, choose "Settings", then select "Agreements"
162from the topics on the left. If you do not have a signed agreement listed here,
163you can create one by clicking "New Contributor Agreement" and following the steps.
164</p>
165
166<p>
167This rigmarole only needs to be done for your first submission for each email address.
168</p>
169
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100170<h3>Install the git-codereview command</h3>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100171
172<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100173Now install the <code>git-codereview</code> command by running,
Russ Cox38a41ee2009-11-06 10:04:22 -0800174</p>
175
176<pre>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800177$ go get -u golang.org/x/review/git-codereview
Russ Cox38a41ee2009-11-06 10:04:22 -0800178</pre>
179
Andrew Gerrandd708e922014-12-10 09:29:35 +1100180<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100181Make sure <code>git-codereview</code> is installed in your shell path, so that the
Andrew Gerrandd708e922014-12-10 09:29:35 +1100182<code>git</code> command can find it. Check that
Russ Cox38a41ee2009-11-06 10:04:22 -0800183</p>
184
Andrew Gerrandd708e922014-12-10 09:29:35 +1100185<pre>
Andrew Gerrand0293b7e2014-12-18 12:55:22 +1100186$ git codereview help
Andrew Gerrandd708e922014-12-10 09:29:35 +1100187</pre>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100188
Andrew Gerrandd708e922014-12-10 09:29:35 +1100189<p>
190prints help text, not an error.
Russ Cox38a41ee2009-11-06 10:04:22 -0800191</p>
192
Andrew Gerrandd708e922014-12-10 09:29:35 +1100193<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100194Note to Git aficionados: The <code>git-codereview</code> command is not required to
Andrew Gerrandd708e922014-12-10 09:29:35 +1100195upload and manage Gerrit code reviews. For those who prefer plain Git, the text
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100196below gives the Git equivalent of each git-codereview command. If you do use plain
197Git, note that you still need the commit hooks that the git-codereview command
Andrew Gerrandd708e922014-12-10 09:29:35 +1100198configures; those hooks add a Gerrit <code>Change-Id</code> line to the commit
199message and check that all Go source files have been formatted with gofmt. Even
200if you intend to use plain Git for daily work, install the hooks in a new Git
Oling Catce365522014-12-14 14:32:56 +0800201checkout by running <code>git-codereview</code> <code>hooks</code>.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100202</p>
203
204<h3>Set up git aliases</h3>
205
206<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100207The <code>git-codereview</code> command can be run directly from the shell
Andrew Gerrandd708e922014-12-10 09:29:35 +1100208by typing, for instance,
209</p>
210
211<pre>
Andrew Gerrand0293b7e2014-12-18 12:55:22 +1100212$ git codereview sync
Andrew Gerrandd708e922014-12-10 09:29:35 +1100213</pre>
214
215<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100216but it is more convenient to set up aliases for <code>git-codereview</code>'s own
Andrew Gerrandd708e922014-12-10 09:29:35 +1100217subcommands, so that the above becomes,
218</p>
219
220<pre>
221$ git sync
222</pre>
223
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100224<p>
225The <code>git-codereview</code> subcommands have been chosen to be distinct from
Andrew Gerrandd708e922014-12-10 09:29:35 +1100226Git's own, so it's safe to do so.
227</p>
228
229<p>
230The aliases are optional, but in the rest of this document we will assume
231they are installed.
232To install them, copy this text into your Git configuration file
233(usually <code>.gitconfig</code> in your home directory):
234</p>
235
236<pre>
237[alias]
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100238 change = codereview change
239 gofmt = codereview gofmt
240 mail = codereview mail
241 pending = codereview pending
242 submit = codereview submit
243 sync = codereview sync
Andrew Gerrandd708e922014-12-10 09:29:35 +1100244</pre>
245
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100246<h3>Understanding the git-codereview command</h3>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100247
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100248<p>After installing the <code>git-codereview</code> command, you can run</p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100249
250<pre>
Andrew Gerrand0293b7e2014-12-18 12:55:22 +1100251$ git codereview help
Andrew Gerrandd708e922014-12-10 09:29:35 +1100252</pre>
253
254<p>
255to learn more about its commands.
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100256You can also read the <a href="https://godoc.org/golang.org/x/review/git-codereview">command documentation</a>.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100257</p>
258
259<h3>Switch to the master branch</h3>
Andrew Gerrand32387052012-06-05 00:55:45 +1000260
261<p>
262Most Go installations use a release branch, but new changes should
Andrew Gerrandd708e922014-12-10 09:29:35 +1100263only be made based on the master branch.
264(They may be applied later to a release branch as part of the release process,
265but most contributors won't do this themselves.)
266Before making a change, make sure you start on the master branch:
Andrew Gerrand32387052012-06-05 00:55:45 +1000267</p>
268
269<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100270$ git checkout master
271$ git sync
Andrew Gerrand32387052012-06-05 00:55:45 +1000272</pre>
273
Andrew Gerrandd708e922014-12-10 09:29:35 +1100274<p>
275(In Git terms, <code>git</code> <code>sync</code> runs
276<code>git</code> <code>pull</code> <code>-r</code>.)
277</p>
278
Russ Cox9ad14c92009-11-06 10:33:46 -0800279<h3>Make a change</h3>
Russ Cox38a41ee2009-11-06 10:04:22 -0800280
281<p>
282The entire checked-out tree is writable.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100283Once you have edited files, you must tell Git that they have been modified.
284You must also tell Git about any files that are added, removed, or renamed files.
285These operations are done with the usual Git commands,
286<code>git</code> <code>add</code>,
287<code>git</code> <code>rm</code>,
288and
289<code>git</code> <code>mv</code>.
Russ Cox38a41ee2009-11-06 10:04:22 -0800290</p>
291
Andrew Gerrandd708e922014-12-10 09:29:35 +1100292<p>
293If you wish to checkpoint your work, or are ready to send the code out for review, run</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800294
295<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100296$ git change <i>&lt;branch&gt;</i>
Russ Cox38a41ee2009-11-06 10:04:22 -0800297</pre>
298
Andrew Gerrandd708e922014-12-10 09:29:35 +1100299<p>
300from any directory in your Go repository to commit the changes so far.
301The name <i>&lt;branch&gt;</i> is an arbitrary one you choose to identify the
302local branch containing your changes.
303</p>
304
305<p>
306(In Git terms, <code>git</code> <code>change</code> <code>&lt;branch&gt;</code>
307runs <code>git</code> <code>checkout</code> <code>-b</code> <code>branch</code>,
308then <code>git</code> <code>branch</code> <code>--set-upstream-to</code> <code>origin/master</code>,
309then <code>git</code> <code>commit</code>.)
310</p>
311
312<p>
313Git will open a change description file in your editor.
314(It uses the editor named by the <code>$EDITOR</code> environment variable,
315<code>vi</code> by default.)
Russ Cox38a41ee2009-11-06 10:04:22 -0800316The file will look like:
317</p>
318
319<pre>
Russ Cox38a41ee2009-11-06 10:04:22 -0800320
Andrew Gerrandd708e922014-12-10 09:29:35 +1100321# Please enter the commit message for your changes. Lines starting
322# with '#' will be ignored, and an empty message aborts the commit.
323# On branch foo
324# Changes not staged for commit:
325# modified: editedfile.go
326#
Russ Cox38a41ee2009-11-06 10:04:22 -0800327</pre>
328
329<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100330At the beginning of this file is a blank line; replace it
331with a thorough description of your change.
Nigel Tao3f383422011-01-05 13:00:08 +1100332The first line of the change description is conventionally a one-line
333summary of the change, prefixed by the primary affected package,
Andrew Gerrandd708e922014-12-10 09:29:35 +1100334and is used as the subject for code review mail.
335The rest of the
336description elaborates and should provide context for the
337change and explain what it does.
338If there is a helpful reference, mention it here.
Russ Cox696e8022009-11-07 18:56:00 -0800339</p>
340
341<p>
342After editing, the template might now read:
Russ Cox38a41ee2009-11-06 10:04:22 -0800343</p>
344
345<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100346math: improved Sin, Cos and Tan precision for very large arguments
Russ Cox38a41ee2009-11-06 10:04:22 -0800347
Andrew Gerrandd708e922014-12-10 09:29:35 +1100348The existing implementation has poor numerical properties for
349large arguments, so use the McGillicutty algorithm to improve
350accuracy above 1e10.
Russ Cox38a41ee2009-11-06 10:04:22 -0800351
Andrew Gerrandd708e922014-12-10 09:29:35 +1100352The algorithm is described at http://wikipedia.org/wiki/McGillicutty_Algorithm
Russ Cox696e8022009-11-07 18:56:00 -0800353
Andrew Gerrandd708e922014-12-10 09:29:35 +1100354Fixes #159
Russ Cox38a41ee2009-11-06 10:04:22 -0800355
Andrew Gerrandd708e922014-12-10 09:29:35 +1100356# Please enter the commit message for your changes. Lines starting
357# with '#' will be ignored, and an empty message aborts the commit.
358# On branch foo
359# Changes not staged for commit:
360# modified: editedfile.go
361#
Russ Cox38a41ee2009-11-06 10:04:22 -0800362</pre>
363
364<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100365The commented section of the file lists all the modified files in your client.
366It is best to keep unrelated changes in different change lists,
367so if you see a file listed that should not be included, abort
368the command and move that file to a different branch.
Russ Cox38a41ee2009-11-06 10:04:22 -0800369</p>
370
371<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100372The special notation "Fixes #159" associates the change with issue 159 in the
373<a href="https://golang.org/issue/159">Go issue tracker</a>.
374When this change is eventually submitted, the issue
375tracker will automatically mark the issue as fixed.
376(There are several such conventions, described in detail in the
377<a href="https://help.github.com/articles/closing-issues-via-commit-messages/">GitHub Issue Tracker documentation</a>.)
378</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800379
380<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100381Once you have finished writing the commit message,
382save the file and exit the editor.
383</p>
384
385<p>
386If you wish to do more editing, re-stage your changes using
387<code>git</code> <code>add</code>, and then run
Russ Cox38a41ee2009-11-06 10:04:22 -0800388</p>
389
390<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100391$ git change
Russ Cox38a41ee2009-11-06 10:04:22 -0800392</pre>
393
Andrew Gerrandd708e922014-12-10 09:29:35 +1100394<p>
395to update the change description and incorporate the staged changes. The
396change description contains a <code>Change-Id</code> line near the bottom,
397added by a Git commit hook during the initial
398<code>git</code> <code>change</code>.
399That line is used by Gerrit to match successive uploads of the same change.
400Do not edit or delete it.
401</p>
402
403<p>
404(In Git terms, <code>git</code> <code>change</code> with no branch name
405runs <code>git</code> <code>commit</code> <code>--amend</code>.)
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100406</p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100407
Bill Thiede822b2cb2014-07-03 17:42:23 -0400408<h3>Mail the change for review</h3>
409
410<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100411Once the change is ready, mail it out for review:
Bill Thiede822b2cb2014-07-03 17:42:23 -0400412</p>
413
414<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100415$ git mail
Bill Thiede822b2cb2014-07-03 17:42:23 -0400416</pre>
417
Andrew Gerrandd708e922014-12-10 09:29:35 +1100418<p>
419You can specify a reviewer or CC interested parties
420using the <code>-r</code> or <code>-cc</code> options.
421Both accept a comma-separated list of email addresses:
422</p>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400423
Andrew Gerrandd708e922014-12-10 09:29:35 +1100424<pre>
425$ git mail -r joe@golang.org -cc mabel@example.com,math-nuts@swtch.com
426</pre>
427
428<p>
429Unless explicitly told otherwise, such as in the discussion leading
430up to sending in the change list, it's better not to specify a reviewer.
431All changes are automatically CC'ed to the
432<a href="https://groups.google.com/group/golang-codereviews">golang-codereviews@googlegroups.com</a>
Josh Bleecher Snyder5ac5a982015-06-19 13:55:38 -0700433mailing list. If this is your first ever change, there may be a moderation
434delay before it appears on the mailing list, to prevent spam.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100435</p>
436
437<p>
438(In Git terms, <code>git</code> <code>mail</code> pushes the local committed
439changes to Gerrit using <code>git</code> <code>push</code> <code>origin</code>
440<code>HEAD:refs/for/master</code>.)
441</p>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400442
443<p>
444If your change relates to an open issue, please add a comment to the issue
445announcing your proposed fix, including a link to your CL.
446</p>
447
Andrew Gerrandd708e922014-12-10 09:29:35 +1100448<p>
449The code review server assigns your change an issue number and URL,
450which <code>git</code> <code>mail</code> will print, something like:
451</p>
452
453<pre>
454remote: New Changes:
455remote: https://go-review.googlesource.com/99999 math: improved Sin, Cos and Tan precision for very large arguments
456</pre>
457
Bill Thiede822b2cb2014-07-03 17:42:23 -0400458<h3>Reviewing code</h3>
459
460<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100461Running <code>git</code> <code>mail</code> will send an email to you and the
462reviewers asking them to visit the issue's URL and make comments on the change.
463When done, the reviewer adds comments through the Gerrit user interface
464and clicks "Reply" to send comments back.
465You will receive a mail notification when this happens.
466You must reply through the web interface.
467(Unlike with the old Rietveld review system, replying by mail has no effect.)
Bill Thiede822b2cb2014-07-03 17:42:23 -0400468</p>
469
Bill Thiede822b2cb2014-07-03 17:42:23 -0400470<h3>Revise and upload</h3>
471
472<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100473You must respond to review comments through the web interface.
474(Unlike with the old Rietveld review system, responding by mail has no effect.)
475</p>
476
477<p>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400478When you have revised the code and are ready for another round of review,
Andrew Gerrandd708e922014-12-10 09:29:35 +1100479stage those changes and use <code>git</code> <code>change</code> to update the
480commit.
481To send the update change list for another round of review,
482run <code>git</code> <code>mail</code> again.
Bill Thiede822b2cb2014-07-03 17:42:23 -0400483</p>
484
485<p>
486The reviewer can comment on the new copy, and the process repeats.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100487The reviewer approves the change by giving it a positive score
488(+1 or +2) and replying <code>LGTM</code>: looks good to me.
Bill Thiede822b2cb2014-07-03 17:42:23 -0400489</p>
490
491<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100492You can see a list of your pending changes by running <code>git</code>
493<code>pending</code>, and switch between change branches with <code>git</code>
494<code>change</code> <code><i>&lt;branch&gt;</i></code>.
Russ Cox38a41ee2009-11-06 10:04:22 -0800495</p>
496
Russ Cox38a41ee2009-11-06 10:04:22 -0800497<h3>Synchronize your client</h3>
498
Andrew Gerrandd708e922014-12-10 09:29:35 +1100499<p>
500While you were working, others might have submitted changes to the repository.
501To update your local branch, run
502</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800503
504<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100505$ git sync
Russ Cox38a41ee2009-11-06 10:04:22 -0800506</pre>
507
Russ Cox38a41ee2009-11-06 10:04:22 -0800508<p>
Oling Catce365522014-12-14 14:32:56 +0800509(In git terms, <code>git</code> <code>sync</code> runs
Andrew Gerrandd708e922014-12-10 09:29:35 +1100510<code>git</code> <code>pull</code> <code>-r</code>.)
Russ Cox696e8022009-11-07 18:56:00 -0800511</p>
512
513<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100514If files you were editing have changed, Git does its best to merge the
515remote changes into your local changes.
516It may leave some files to merge by hand.
517</p>
518
519<p>
520For example, suppose you have edited <code>sin.go</code> but
Russ Cox696e8022009-11-07 18:56:00 -0800521someone else has committed an independent change.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100522When you run <code>git</code> <code>sync</code>,
523you will get the (scary-looking) output:
Russ Cox38a41ee2009-11-06 10:04:22 -0800524
525<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100526$ git sync
527Failed to merge in the changes.
528Patch failed at 0023 math: improved Sin, Cos and Tan precision for very large arguments
529The copy of the patch that failed is found in:
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800530 /home/you/repo/.git/rebase-apply/patch
Andrew Gerrandd708e922014-12-10 09:29:35 +1100531
532When you have resolved this problem, run "git rebase --continue".
533If you prefer to skip this patch, run "git rebase --skip" instead.
534To check out the original branch and stop rebasing, run "git rebase --abort".
Russ Cox38a41ee2009-11-06 10:04:22 -0800535</pre>
536
Russ Cox696e8022009-11-07 18:56:00 -0800537<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100538If this happens, run
539</p>
540
541<pre>
542$ git status
543</pre>
544
545<p>
546to see which files failed to merge.
547The output will look something like this:
548</p>
549
550<pre>
551rebase in progress; onto a24c3eb
552You are currently rebasing branch 'mcgillicutty' on 'a24c3eb'.
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800553 (fix conflicts and then run "git rebase --continue")
554 (use "git rebase --skip" to skip this patch)
555 (use "git rebase --abort" to check out the original branch)
Andrew Gerrandd708e922014-12-10 09:29:35 +1100556
557Unmerged paths:
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800558 (use "git reset HEAD &lt;file&gt;..." to unstage)
559 (use "git add &lt;file&gt;..." to mark resolution)
Andrew Gerrandd708e922014-12-10 09:29:35 +1100560
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800561 <i>both modified: sin.go</i>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100562</pre>
563
564<p>
565The only important part in that transcript is the italicized "both modified"
566line: Git failed to merge your changes with the conflicting change.
567When this happens, Git leaves both sets of edits in the file,
568with conflicts marked by <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</code> and
Russ Cox696e8022009-11-07 18:56:00 -0800569<code>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</code>.
Tetsuo Kiso48347cc2014-07-07 16:31:20 +1000570It is now your job to edit the file to combine them.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100571Continuing the example, searching for those strings in <code>sin.go</code>
Russ Cox696e8022009-11-07 18:56:00 -0800572might turn up:
573</p>
574
575<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100576 arg = scale(arg)
577&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800578 if arg &lt; 1e9 {
Russ Cox696e8022009-11-07 18:56:00 -0800579=======
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800580 if arg &lh; 1e10 {
Andrew Gerrandd708e922014-12-10 09:29:35 +1100581&gt;&gt;&gt;&gt;&gt;&gt;&gt; mcgillicutty
582 largeReduce(arg)
Russ Cox696e8022009-11-07 18:56:00 -0800583</pre>
584
585<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100586Git doesn't show it, but suppose the original text that both edits
587started with was 1e8; you changed it to 1e10 and the other change to 1e9,
588so the correct answer might now be 1e10. First, edit the section
Russ Cox696e8022009-11-07 18:56:00 -0800589to remove the markers and leave the correct code:
590</p>
591
592<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100593 arg = scale(arg)
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800594 if arg &lt; 1e10 {
Andrew Gerrandd708e922014-12-10 09:29:35 +1100595 largeReduce(arg)
Russ Cox696e8022009-11-07 18:56:00 -0800596</pre>
597
598<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100599Then tell Git that the conflict is resolved by running
Russ Cox696e8022009-11-07 18:56:00 -0800600</p>
601
Russ Coxd55abfd2009-12-09 14:05:12 -0800602<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100603$ git add sin.go
Russ Coxd55abfd2009-12-09 14:05:12 -0800604</pre>
605
Russ Cox696e8022009-11-07 18:56:00 -0800606<p>
Russ Cox830813f2009-11-08 21:08:27 -0800607If you had been editing the file, say for debugging, but do not
608care to preserve your changes, you can run
Andrew Gerrandd708e922014-12-10 09:29:35 +1100609<code>git</code> <code>reset</code> <code>HEAD</code> <code>sin.go</code>
610to abandon your changes.
611Then run <code>git</code> <code>rebase</code> <code>--continue</code> to
612restore the change commit.
Russ Cox696e8022009-11-07 18:56:00 -0800613</p>
614
Dave Cheneyeda95902013-02-10 19:40:33 -0500615<h3>Reviewing code by others</h3>
616
617<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100618You can import a change proposed by someone else into your local Git repository.
619On the Gerrit review page, click the "Download ▼" link in the upper right
620corner, copy the "Checkout" command and run it from your local Git repo.
621It should look something like this:
Dave Cheneyeda95902013-02-10 19:40:33 -0500622</p>
623
624<pre>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800625$ git fetch https://go.googlesource.com/review refs/changes/21/1221/1 &amp;&amp; git checkout FETCH_HEAD
Dave Cheneyeda95902013-02-10 19:40:33 -0500626</pre>
627
628<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100629To revert, change back to the branch you were working in.
Oling Cataecbcd02013-02-15 14:01:12 +1100630</p>
Dave Cheneyeda95902013-02-10 19:40:33 -0500631
Russ Cox5facb842009-12-09 14:39:41 -0800632<h3>Submit the change after the review</h3>
Russ Cox38a41ee2009-11-06 10:04:22 -0800633
634<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100635After the code has been <code>LGTM</code>'ed, an approver may
636submit it to the master branch using the Gerrit UI.
637There is a "Submit" button on the web page for the change
638that appears once the change is approved (marked +2).
Dave Cheneyeda95902013-02-10 19:40:33 -0500639</p>
640
641<p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800642This checks the change into the repository.
643The change description will include a link to the code review,
644and the code review will be updated with a link to the change
645in the repository.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100646Since the method used to integrate the changes is "Cherry Pick",
647the commit hashes in the repository will be changed by
648the submit operation.
Russ Cox38a41ee2009-11-06 10:04:22 -0800649</p>
650
Robert Hencke75ba1812014-04-25 20:09:04 -0700651<h3>More information</h3>
652
653<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100654In addition to the information here, the Go community maintains a <a href="https://golang.org/wiki/CodeReview">CodeReview</a> wiki page.
Robert Hencke75ba1812014-04-25 20:09:04 -0700655Feel free to contribute to this page as you learn the review process.
656</p>
657
Dave Cheneyeda95902013-02-10 19:40:33 -0500658<h2 id="copyright">Copyright</h2>
Russ Cox38a41ee2009-11-06 10:04:22 -0800659
Russ Coxd55abfd2009-12-09 14:05:12 -0800660<p>Files in the Go repository don't list author names,
661both to avoid clutter and to avoid having to keep the lists up to date.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100662Instead, your name will appear in the
663<a href="https://golang.org/change">change log</a>
Russ Coxd55abfd2009-12-09 14:05:12 -0800664and in the <a href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file
665and perhaps the <a href="/AUTHORS"><code>AUTHORS</code></a> file.
666</p>
667
668<p>The <a href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file
669defines who the Go contributors&mdash;the people&mdash;are;
Caleb Spare41f32e02013-01-06 22:44:16 -0500670the <a href="/AUTHORS"><code>AUTHORS</code></a> file defines
Russ Coxd55abfd2009-12-09 14:05:12 -0800671who &ldquo;The Go Authors&rdquo;&mdash;the copyright holders&mdash;are.
Dmitry Savintsev30ab39a2015-06-09 12:01:38 +0200672These files will be periodically updated based on the commit logs.
673
Russ Coxd55abfd2009-12-09 14:05:12 -0800674<p>Code that you contribute should use the standard copyright header:</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800675
676<pre>
David Symonds6cb40332015-01-01 00:00:00 +1100677// Copyright 2015 The Go Authors. All rights reserved.
Russ Cox38a41ee2009-11-06 10:04:22 -0800678// Use of this source code is governed by a BSD-style
679// license that can be found in the LICENSE file.
680</pre>
Dave Cheneyeda95902013-02-10 19:40:33 -0500681
682<p>
683Files in the repository are copyright the year they are added. It is not
684necessary to update the copyright year on files that you change.
685</p>