blob: e5312becbb5e1bb3a1aa1346d34ecb4742070bf8 [file] [log] [blame]
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11001<!--{
Steve Francia5f3e7aa2017-02-09 15:33:13 -05002 "Title": "Contribution Guide"
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11003}-->
Russ Coxfb39a4d2009-10-23 15:24:08 -07004
Rob Pike5b72f9c2009-11-01 20:48:21 -08005<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -05006The Go project welcomes all contributors. The process of contributing
7to the Go project may be different than many projects you are used to.
8This document is intended as a guide to help you through the contribution
9process. This guide assumes you have a basic understanding of Git and Go.
Andrew Gerrand968f0df2014-12-12 13:53:29 +110010</p>
Andrew Gerrandd708e922014-12-10 09:29:35 +110011
12<p>
Russ Coxd55abfd2009-12-09 14:05:12 -080013(Note that the <code>gccgo</code> frontend lives elsewhere;
Ian Lance Taylor2528f332009-11-06 14:15:41 -080014see <a href="gccgo_contribute.html">Contributing to gccgo</a>.)
Russ Cox38a41ee2009-11-06 10:04:22 -080015</p>
Russ Coxfb39a4d2009-10-23 15:24:08 -070016
Francesc Campoyba966f52016-04-22 16:27:34 -070017<p>
18Sensitive security-related issues should be reported to <a href="mailto:security@golang.org">security@golang.org</a>.
19</p>
20
Steve Francia5f3e7aa2017-02-09 15:33:13 -050021<h1 id="contributor">Becoming a contributor</h1>
Rob Pike96ee38b2009-12-17 12:12:47 +110022
23<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -050024Before you can contribute to the Go project you need to setup a few prerequisites.
25The Go project uses <a href="https://www.gerritcodereview.com/">Gerrit</a>, an open
26source online tool, to perform all code reviews.
27Gerrit uses your email address as a unique identifier.
28The Go project contributing flow is currently configured to work only with Google Accounts.
29You must go through the following process <em>prior to contributing</em>.
30You only need to do this once per Google Account.
31</p>
32
Mohit Agarwald529aa92018-01-30 00:14:54 +053033<h2 id="go-contrib-init">Automatically set up &amp; diagnose your development environment</h2>
Brad Fitzpatrick491ec4d2017-06-13 22:50:35 +000034<p>
35 The <code>go-contrib-init</code> tool configures and debugs your Go
36 development environment, automatically performing many of the steps
37 on this page, or telling you what you need to do next. If you wish
38 to use it, run:
39</p>
40
41<pre>
42$ go get -u golang.org/x/tools/cmd/go-contrib-init
43$ cd /code/to/edit
44$ go-contrib-init
45</pre>
46
47<p>
48 The tool will either set things up, tell you that everything is
49 configured, or tell you what steps you need to do manually.
50</p>
51
Steve Francia5f3e7aa2017-02-09 15:33:13 -050052<h2 id="auth">Configure Git to use Gerrit</h2>
53<p>
54You'll need a web browser and a command line terminal.
55You should already have Git installed.
Rob Pike96ee38b2009-12-17 12:12:47 +110056</p>
57
58<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -050059Gerrit uses Google Accounts for authentication.
60If you don't have a Google Account, you can create an account which
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080061<a href="https://www.google.com/accounts/NewAccount">includes
62a new Gmail email account</a> or create an account associated
63<a href="https://accounts.google.com/SignUpWithoutGmail">with your existing
64email address</a>.
Andrew Gerrandd708e922014-12-10 09:29:35 +110065</p>
66
Steve Francia5f3e7aa2017-02-09 15:33:13 -050067<h3>Step 1: Sign in to googlesource and generate a password</h3>
Andrew Gerrandd708e922014-12-10 09:29:35 +110068
69<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -050070Visit <a href="https://go.googlesource.com">go.googlesource.com</a>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080071and click on "Generate Password" in the page's top right menu bar.
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080072You will be redirected to accounts.google.com to sign in.
Andrew Gerrandd708e922014-12-10 09:29:35 +110073</p>
74
Steve Francia5f3e7aa2017-02-09 15:33:13 -050075<h3>Step 2: Run the provided script</h3>
Andrew Gerrandd708e922014-12-10 09:29:35 +110076<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -050077After signing in, you are taken to a page on go.googlesource.com with the title "Configure Git".
78This page contains a personalized script which when run locally will configure git
79to have your unique authentication key.
80This key is paired with one generated server side similar to how ssh keys work.
81</p>
82
83<p>
84Copy and run this script locally in your command line terminal.
85(On a Windows computer using cmd you should instead follow the instructions
86in the yellow box to run the command. If you are using git-bash use the same
87script as *nix.)
Andrew Gerrandd708e922014-12-10 09:29:35 +110088</p>
89
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080090<p>
RaviTeja4e0738a2017-08-09 17:23:47 +053091Your secret authentication token is now in a <code>.gitcookies</code> file
Lloyd Dewolffbbf2192015-02-24 21:33:29 -080092and Git is configured to use this file.
93</p>
94
Steve Francia5f3e7aa2017-02-09 15:33:13 -050095<h3 id="gerrit">Step 3: Register with Gerrit</h3>
Andrew Gerrandd708e922014-12-10 09:29:35 +110096
97<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -050098Now that you have your authentication token, you need to register your
99account with Gerrit.
100To do this, visit <a href="https://go-review.googlesource.com/login/">
101go-review.googlesource.com/login/</a>.
102Sign in using the same Google Account you used above.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100103</p>
104
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500105<h2 id="cla">Contributor License Agreement</h2>
Andy Maloneyc53de852015-08-03 10:15:52 -0400106
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500107<h3 id="which_cla">Which CLA</h3>
108<p>
109Before sending your first change to the Go project
110you must have completed one of the following two CLAs.
111Which CLA you should sign depends on who owns the copyright to your work.
112</p>
113
Andy Maloneyc53de852015-08-03 10:15:52 -0400114<ul>
115<li>
116If you are the copyright holder, you will need to agree to the
117<a href="https://developers.google.com/open-source/cla/individual">individual
118contributor license agreement</a>, which can be completed online.
119</li>
120<li>
121If your organization is the copyright holder, the organization
122will need to agree to the
123<a href="https://developers.google.com/open-source/cla/corporate">corporate
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500124contributor license agreement</a>.<br>
Andy Maloneyc53de852015-08-03 10:15:52 -0400125</li>
126</ul>
127
128<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500129<i>If the copyright holder for your contribution has already completed the
130agreement in connection with another Google open source project,
131it does not need to be completed again.</i>
132</p>
133
134<h3 id="signing_cla">Completing the CLA</h3>
135
136<p>
137You can see your currently signed agreements and sign new ones through the Gerrit
138interface.
139To do this, <a href="https://go-review.googlesource.com/login/">Log into Gerrit</a>,
Alberto Donizetti9f6fde32017-05-02 12:38:59 +0200140then visit the <a href="https://go-review.googlesource.com/settings/agreements">Agreements</a>
141page.
142If you do not have a signed agreement listed there, you can create one
143by clicking "New Contributor Agreement" and following the steps.
Andy Maloneyc53de852015-08-03 10:15:52 -0400144</p>
145
146<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500147If the copyright holder for the code you are submitting changes &mdash; for example,
148if you start contributing code on behalf of a new company &mdash; please send email
149to golang-dev and let us know, so that we can make sure an appropriate agreement is
150completed and update the <code>AUTHORS</code> file.
Andy Maloneyc53de852015-08-03 10:15:52 -0400151</p>
152
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500153<span id="Code_review"></span>
154<h1 id="prepare_dev_env">Preparing a Development Environment for Contributing</h1>
155
156<h2 id="git-codereview">Setting up Git for submission to Gerrit</h2>
Russ Cox19e27c72016-01-06 15:23:47 -0500157<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500158Changes to Go must be reviewed before they are accepted, no matter who makes the change.
159A custom git command called <code>git-codereview</code>, discussed below,
160helps manage the code review process through a Google-hosted
Christian Alexander1b53f122017-08-09 08:11:34 -0700161<a href="https://go-review.googlesource.com/">instance</a> of Gerrit.
Russ Cox19e27c72016-01-06 15:23:47 -0500162</p>
163
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500164<h3 id="git-codereview_install">Install the git-codereview command</h3>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100165<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500166Install the <code>git-codereview</code> command by running,
Russ Cox38a41ee2009-11-06 10:04:22 -0800167</p>
168
169<pre>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800170$ go get -u golang.org/x/review/git-codereview
Russ Cox38a41ee2009-11-06 10:04:22 -0800171</pre>
172
Andrew Gerrandd708e922014-12-10 09:29:35 +1100173<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100174Make sure <code>git-codereview</code> is installed in your shell path, so that the
Andrew Gerrandd708e922014-12-10 09:29:35 +1100175<code>git</code> command can find it. Check that
Russ Cox38a41ee2009-11-06 10:04:22 -0800176</p>
177
Andrew Gerrandd708e922014-12-10 09:29:35 +1100178<pre>
Andrew Gerrand0293b7e2014-12-18 12:55:22 +1100179$ git codereview help
Andrew Gerrandd708e922014-12-10 09:29:35 +1100180</pre>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100181
Andrew Gerrandd708e922014-12-10 09:29:35 +1100182<p>
183prints help text, not an error.
Russ Cox38a41ee2009-11-06 10:04:22 -0800184</p>
185
Andrew Gerrandd708e922014-12-10 09:29:35 +1100186<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500187On Windows, when using git-bash you must make sure that
188<code>git-codereview.exe</code> is in your git exec-path.
189Run <code>git --exec-path</code> to discover the right location then create a
Alberto Donizetti28736052017-12-06 10:59:40 +0100190symbolic link or simply copy the executable from $GOPATH/bin to this directory.
Russ Coxf9974752016-02-17 10:46:30 -0500191</p>
192
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500193<p>
194<b>Note to Git aficionados:</b>
195The <code>git-codereview</code> command is not required to
196upload and manage Gerrit code reviews.
197For those who prefer plain Git, the text below gives the Git equivalent of
198each git-codereview command.
199</p>
200
201<p>
202If you do use plain Git, note that you still need the commit hooks that the
203git-codereview command configures; those hooks add a Gerrit
204<code>Change-Id</code> line to the commit message and check that all Go source
205files have been formatted with gofmt.
206Even if you intend to use plain Git for
207daily work, install the hooks in a new Git checkout by running
208<code>git-codereview</code> <code>hooks</code>.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100209</p>
210
Russ Cox19e27c72016-01-06 15:23:47 -0500211<h3 id="git-config">Set up git aliases</h3>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100212
213<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100214The <code>git-codereview</code> command can be run directly from the shell
Andrew Gerrandd708e922014-12-10 09:29:35 +1100215by typing, for instance,
216</p>
217
218<pre>
Andrew Gerrand0293b7e2014-12-18 12:55:22 +1100219$ git codereview sync
Andrew Gerrandd708e922014-12-10 09:29:35 +1100220</pre>
221
222<p>
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100223but it is more convenient to set up aliases for <code>git-codereview</code>'s own
Andrew Gerrandd708e922014-12-10 09:29:35 +1100224subcommands, so that the above becomes,
225</p>
226
227<pre>
228$ git sync
229</pre>
230
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100231<p>
232The <code>git-codereview</code> subcommands have been chosen to be distinct from
Andrew Gerrandd708e922014-12-10 09:29:35 +1100233Git's own, so it's safe to do so.
234</p>
235
236<p>
237The aliases are optional, but in the rest of this document we will assume
238they are installed.
239To install them, copy this text into your Git configuration file
240(usually <code>.gitconfig</code> in your home directory):
241</p>
242
243<pre>
244[alias]
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100245 change = codereview change
246 gofmt = codereview gofmt
247 mail = codereview mail
248 pending = codereview pending
249 submit = codereview submit
250 sync = codereview sync
Andrew Gerrandd708e922014-12-10 09:29:35 +1100251</pre>
252
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500253<span id="help"></span>
254<h3 id="understanding_git-codereview">Understanding the git-codereview command</h3>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100255
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100256<p>After installing the <code>git-codereview</code> command, you can run</p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100257
258<pre>
Andrew Gerrand0293b7e2014-12-18 12:55:22 +1100259$ git codereview help
Andrew Gerrandd708e922014-12-10 09:29:35 +1100260</pre>
261
262<p>
263to learn more about its commands.
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100264You 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 +1100265</p>
266
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500267
268<h1 id="making_a_contribution">Making a Contribution</h1>
269
270<h2 id="Design">Discuss your design</h2>
271
272<p>
273The project welcomes submissions but please let everyone know what
274you're working on if you want to change or add to the Go repositories.
275</p>
276
277<p>
278Before undertaking to write something new for the Go project,
279please <a href="https://golang.org/issue/new">file an issue</a>
280(or claim an <a href="https://golang.org/issues">existing issue</a>).
281Significant changes must go through the
282<a href="https://golang.org/s/proposal-process">change proposal process</a>
283before they can be accepted.
284</p>
285
286<p>
287This process gives everyone a chance to validate the design,
288helps prevent duplication of effort,
289and ensures that the idea fits inside the goals for the language and tools.
290It also checks that the design is sound before code is written;
291the code review tool is not the place for high-level discussions.
292</p>
293
294<p>
295When planning work, please note that the Go project follows a <a
296href="https://golang.org/wiki/Go-Release-Cycle">six-month development cycle</a>.
297The latter half of each cycle is a three-month feature freeze during
298which only bug fixes and doc updates are accepted. New contributions can be
299sent during a feature freeze but will not be accepted until the freeze thaws.
300</p>
301
Kevin Burke1722a2d2017-07-19 07:21:30 -0700302<h3 id="scratch">Not sure what change to make?</h3>
303
304<p>
305If you want to become familiar with Gerrit and the contribution process,
306but aren't sure what you'd like to contribute just yet, you can use the <a
307href="https://go.googlesource.com/scratch">scratch repository</a> to practice
308making a change.
309</p>
310
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500311<h2 id="making_a_change">Making a change</h2>
312
313<h3 id="checkout_go">Getting Go Source</h3>
314<p>
315First you need to have a local copy of the source checked out from the correct
316repository.
317As Go builds Go you will also likely need to have a working version
318of Go installed (some documentation changes may not need this).
319This should be a recent version of Go and can be obtained via any package or
320binary distribution or you can build it from source.
321</p>
322
323<p>
324You should checkout the Go source repo anywhere you want as long as it's
325outside of your $GOPATH.
326Go to a directory where you want the source to appear and run the following
327command in a terminal.
328</p>
329
Adam Bender9dd70592017-05-03 18:57:40 -0700330<pre>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500331$ git clone https://go.googlesource.com/go
332$ cd go
Adam Bender9dd70592017-05-03 18:57:40 -0700333</pre>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500334
335<h3 id="master">Contributing to the main Go tree</h3>
Andrew Gerrand32387052012-06-05 00:55:45 +1000336
337<p>
338Most Go installations use a release branch, but new changes should
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500339only be made based on the master branch. <br>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100340(They may be applied later to a release branch as part of the release process,
341but most contributors won't do this themselves.)
342Before making a change, make sure you start on the master branch:
Andrew Gerrand32387052012-06-05 00:55:45 +1000343</p>
344
345<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100346$ git checkout master
347$ git sync
Andrew Gerrand32387052012-06-05 00:55:45 +1000348</pre>
349
Andrew Gerrandd708e922014-12-10 09:29:35 +1100350<p>
351(In Git terms, <code>git</code> <code>sync</code> runs
352<code>git</code> <code>pull</code> <code>-r</code>.)
353</p>
354
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500355<h3 id="subrepos">Contributing to subrepositories (golang.org/x/...)</h3>
Russ Cox38a41ee2009-11-06 10:04:22 -0800356
357<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500358If you are contributing a change to a subrepository, obtain the
359Go package using <code>go get</code>. For example, to contribute
360to <code>golang.org/x/oauth2</code>, check out the code by running:
361</p>
362
363<pre>
364$ go get -d golang.org/x/oauth2/...
365</pre>
366
367<p>
368Then, change your directory to the package's source directory
369(<code>$GOPATH/src/golang.org/x/oauth2</code>).
370</p>
371
372<h3 id="change">Make your changes</h3>
373
374<p>
375The entire checked-out tree is editable.
376Make your changes as you see fit ensuring that you create appropriate
377tests along with your changes. Test your changes as you go.
378</p>
379
380<h3 id="copyright">Copyright</h3>
381
382<p>
383Files in the Go repository don't list author names, both to avoid clutter
384and to avoid having to keep the lists up to date.
385Instead, your name will appear in the
386<a href="https://golang.org/change">change log</a> and in the <a
387href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file and perhaps the <a
388href="/AUTHORS"><code>AUTHORS</code></a> file.
Alberto Donizetti28736052017-12-06 10:59:40 +0100389These files are automatically generated from the commit logs periodically.
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500390The <a href="/AUTHORS"><code>AUTHORS</code></a> file defines who &ldquo;The Go
391Authors&rdquo;&mdash;the copyright holders&mdash;are.
392</p>
393
394<p>New files that you contribute should use the standard copyright header:</p>
395
396<pre>
Brad Fitzpatrickcd97aca2018-01-01 02:04:51 +0000397// Copyright 2018 The Go Authors. All rights reserved.
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500398// Use of this source code is governed by a BSD-style
399// license that can be found in the LICENSE file.
400</pre>
401
402<p>
403Files in the repository are copyright the year they are added.
404Do not update the copyright year on files that you change.
405</p>
406
407<h3 id="commit_changes">Commit your changes</h3>
408
409<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100410Once you have edited files, you must tell Git that they have been modified.
411You must also tell Git about any files that are added, removed, or renamed files.
412These operations are done with the usual Git commands,
413<code>git</code> <code>add</code>,
414<code>git</code> <code>rm</code>,
415and
416<code>git</code> <code>mv</code>.
Russ Cox38a41ee2009-11-06 10:04:22 -0800417</p>
418
Andrew Gerrandd708e922014-12-10 09:29:35 +1100419<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500420Once you have the changes queued up, you will want to commit them.
Adam Bender9dd70592017-05-03 18:57:40 -0700421In the Go contribution workflow this is done with a <code>git</code>
422<code>change</code> command, which creates a local branch and commits the changes
423directly to that local branch.
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500424</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800425
Leigh McCulloch07a2ffa2017-11-04 20:54:30 +0000426<p>
427The workflow described here assumes a single change per branch.
428It is also possible to prepare a sequence of (usually related) changes in a single branch.
429See the <a href="https://golang.org/x/review/git-codereview">git-codereview documentation</a> for details.
430</p>
431
Russ Cox38a41ee2009-11-06 10:04:22 -0800432<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100433$ git change <i>&lt;branch&gt;</i>
Russ Cox38a41ee2009-11-06 10:04:22 -0800434</pre>
435
Andrew Gerrandd708e922014-12-10 09:29:35 +1100436<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100437The name <i>&lt;branch&gt;</i> is an arbitrary one you choose to identify the
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500438local branch containing your changes and will not be used elsewhere.
439This is an offline operation and nothing will be sent to the server yet.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100440</p>
441
442<p>
443(In Git terms, <code>git</code> <code>change</code> <code>&lt;branch&gt;</code>
444runs <code>git</code> <code>checkout</code> <code>-b</code> <code>branch</code>,
445then <code>git</code> <code>branch</code> <code>--set-upstream-to</code> <code>origin/master</code>,
446then <code>git</code> <code>commit</code>.)
447</p>
448
449<p>
Adam Bender9dd70592017-05-03 18:57:40 -0700450As the <code>git</code> <code>commit</code> is the final step, Git will open an
451editor to ask for a commit message. (It uses the editor named by
452the <code>$EDITOR</code> environment variable,
Andrew Gerrandd708e922014-12-10 09:29:35 +1100453<code>vi</code> by default.)
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500454
Russ Cox38a41ee2009-11-06 10:04:22 -0800455The file will look like:
456</p>
457
458<pre>
Russ Cox38a41ee2009-11-06 10:04:22 -0800459
Andrew Gerrandd708e922014-12-10 09:29:35 +1100460# Please enter the commit message for your changes. Lines starting
461# with '#' will be ignored, and an empty message aborts the commit.
462# On branch foo
463# Changes not staged for commit:
464# modified: editedfile.go
465#
Russ Cox38a41ee2009-11-06 10:04:22 -0800466</pre>
467
468<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100469At the beginning of this file is a blank line; replace it
470with a thorough description of your change.
Nigel Tao3f383422011-01-05 13:00:08 +1100471The first line of the change description is conventionally a one-line
472summary of the change, prefixed by the primary affected package,
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500473and is used as the subject for code review email.
Jeff R. Allen7b6b5e32016-05-25 00:12:22 +0600474It should complete the sentence "This change modifies Go to _____."
475The rest of the description elaborates and should provide context for the
Andrew Gerrandd708e922014-12-10 09:29:35 +1100476change and explain what it does.
Jeff R. Allen7b6b5e32016-05-25 00:12:22 +0600477Write in complete sentences with correct punctuation, just like
478for your comments in Go.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100479If there is a helpful reference, mention it here.
Jeff R. Allen7b6b5e32016-05-25 00:12:22 +0600480If you've fixed an issue, reference it by number with a # before it.
Russ Cox696e8022009-11-07 18:56:00 -0800481</p>
482
483<p>
484After editing, the template might now read:
Russ Cox38a41ee2009-11-06 10:04:22 -0800485</p>
486
487<pre>
Jeff R. Allen7b6b5e32016-05-25 00:12:22 +0600488math: improve Sin, Cos and Tan precision for very large arguments
Russ Cox38a41ee2009-11-06 10:04:22 -0800489
Andrew Gerrandd708e922014-12-10 09:29:35 +1100490The existing implementation has poor numerical properties for
491large arguments, so use the McGillicutty algorithm to improve
492accuracy above 1e10.
Russ Cox38a41ee2009-11-06 10:04:22 -0800493
Andrew Gerrandd708e922014-12-10 09:29:35 +1100494The algorithm is described at http://wikipedia.org/wiki/McGillicutty_Algorithm
Russ Cox696e8022009-11-07 18:56:00 -0800495
Andrew Gerrandd708e922014-12-10 09:29:35 +1100496Fixes #159
Russ Cox38a41ee2009-11-06 10:04:22 -0800497
Andrew Gerrandd708e922014-12-10 09:29:35 +1100498# Please enter the commit message for your changes. Lines starting
499# with '#' will be ignored, and an empty message aborts the commit.
500# On branch foo
501# Changes not staged for commit:
502# modified: editedfile.go
503#
Russ Cox38a41ee2009-11-06 10:04:22 -0800504</pre>
505
506<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100507The commented section of the file lists all the modified files in your client.
Han-Wen Nienhuysd5da1042017-07-14 15:38:49 -0600508It is best to keep unrelated changes in different commits,
Andrew Gerrandd708e922014-12-10 09:29:35 +1100509so if you see a file listed that should not be included, abort
510the command and move that file to a different branch.
Russ Cox38a41ee2009-11-06 10:04:22 -0800511</p>
512
513<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100514The special notation "Fixes #159" associates the change with issue 159 in the
515<a href="https://golang.org/issue/159">Go issue tracker</a>.
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500516When this change is eventually applied, the issue
Andrew Gerrandd708e922014-12-10 09:29:35 +1100517tracker will automatically mark the issue as fixed.
518(There are several such conventions, described in detail in the
519<a href="https://help.github.com/articles/closing-issues-via-commit-messages/">GitHub Issue Tracker documentation</a>.)
520</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800521
522<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100523Once you have finished writing the commit message,
524save the file and exit the editor.
525</p>
526
527<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500528You must have the $EDITOR environment variable set properly and working properly (exiting cleanly)
529for this operation to succeed.
530If you run into any issues at this step, it's likely your editor isn't exiting cleanly.
531Try setting a different editor in your $EDITOR environment variable.
532</p>
533
534<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100535If you wish to do more editing, re-stage your changes using
536<code>git</code> <code>add</code>, and then run
Russ Cox38a41ee2009-11-06 10:04:22 -0800537</p>
538
539<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100540$ git change
Russ Cox38a41ee2009-11-06 10:04:22 -0800541</pre>
542
Andrew Gerrandd708e922014-12-10 09:29:35 +1100543<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500544to update the change description and incorporate the staged changes.
545The change description contains a <code>Change-Id</code> line near the bottom,
Andrew Gerrandd708e922014-12-10 09:29:35 +1100546added by a Git commit hook during the initial
547<code>git</code> <code>change</code>.
548That line is used by Gerrit to match successive uploads of the same change.
549Do not edit or delete it.
550</p>
551
552<p>
553(In Git terms, <code>git</code> <code>change</code> with no branch name
554runs <code>git</code> <code>commit</code> <code>--amend</code>.)
Andrew Gerrand722f7d22014-12-18 11:42:25 +1100555</p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100556
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500557<h3 id="Testing">Testing</h3>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400558
559<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500560You've <a href="code.html">written and tested your code</a>, but
561before sending code out for review, run all the tests for the whole
562tree to make sure the changes don't break other packages or programs:
563</p>
564
565<pre>
566$ cd go/src
567$ ./all.bash
568</pre>
569
570<p>
571(To build under Windows use <code>all.bat</code>.)
572</p>
573
574<p>
575After running for a while, the command should print
576</p>
577
578<pre>
579"ALL TESTS PASSED".
580</pre>
581
582<h3 id="mail">Send the change for review</h3>
583
584<p>
585Once the change is ready, send it for review.
586This is similar to a <code>git push</code> in a GitHub style workflow.
587This is done via the mail alias setup earlier which despite its name, doesn't
588directly mail anything, it simply sends the change to Gerrit via git push.
Bill Thiede822b2cb2014-07-03 17:42:23 -0400589</p>
590
591<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100592$ git mail
Bill Thiede822b2cb2014-07-03 17:42:23 -0400593</pre>
594
Andrew Gerrandd708e922014-12-10 09:29:35 +1100595<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100596(In Git terms, <code>git</code> <code>mail</code> pushes the local committed
597changes to Gerrit using <code>git</code> <code>push</code> <code>origin</code>
598<code>HEAD:refs/for/master</code>.)
599</p>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400600
601<p>
602If your change relates to an open issue, please add a comment to the issue
Jaana Burcu Dogane2390ec2017-02-08 11:17:47 -0800603announcing your proposed fix, including a link to your change.
Bill Thiede822b2cb2014-07-03 17:42:23 -0400604</p>
605
Andrew Gerrandd708e922014-12-10 09:29:35 +1100606<p>
607The code review server assigns your change an issue number and URL,
608which <code>git</code> <code>mail</code> will print, something like:
609</p>
610
611<pre>
612remote: New Changes:
613remote: https://go-review.googlesource.com/99999 math: improved Sin, Cos and Tan precision for very large arguments
614</pre>
615
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500616<h3>Troubleshooting</h3>
617
618<p>
619The most common way that the <code>git mail</code> command fails is because the
620email address used has not gone through the setup above.
621<br>
622If you see something like...
623</p>
624
625<pre>
626remote: Processing changes: refs: 1, done
627remote:
628remote: ERROR: In commit ab13517fa29487dcf8b0d48916c51639426c5ee9
629remote: ERROR: author email address XXXXXXXXXXXXXXXXXXX
630remote: ERROR: does not match your user account.
631</pre>
632
633<p>
634You need to either add the email address listed to the CLA or set this repo to use
635another email address already approved.
636</p>
637
638<p>
639First let's change the email address for this repo so this doesn't happen again.
640You can change your email address for this repo with the following command:
641</p>
642
643<pre>
644$ git config user.email email@address.com
645</pre>
646
647<p>
648Then change the previous commit to use this alternative email address.
649You can do that with:
650</p>
651
652<pre>
653$ git commit --amend --author="Author Name &lt;email@address.com&gt;"
654</pre>
655
656<p>
657Finally try to resend with:
658</p>
659
660<pre>
661$ git mail
662</pre>
663
664<h3 id="cc">Specifying a reviewer / CCing others</h3>
665
666<p>
667Unless explicitly told otherwise, such as in the discussion leading
Han-Wen Nienhuysd5da1042017-07-14 15:38:49 -0600668up to sending in the change, it's better not to specify a reviewer.
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500669All changes are automatically CC'ed to the
670<a href="https://groups.google.com/group/golang-codereviews">golang-codereviews@googlegroups.com</a>
671mailing list. If this is your first ever change, there may be a moderation
672delay before it appears on the mailing list, to prevent spam.
673</p>
674
675<p>
676You can specify a reviewer or CC interested parties
677using the <code>-r</code> or <code>-cc</code> options.
678Both accept a comma-separated list of email addresses:
679</p>
680
681<pre>
682$ git mail -r joe@golang.org -cc mabel@example.com,math-nuts@swtch.com
683</pre>
684
685<h2 id="review">Going through the review process</h2>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400686
687<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100688Running <code>git</code> <code>mail</code> will send an email to you and the
689reviewers asking them to visit the issue's URL and make comments on the change.
690When done, the reviewer adds comments through the Gerrit user interface
691and clicks "Reply" to send comments back.
692You will receive a mail notification when this happens.
Andrew Bonventre2e405bd2017-10-04 00:02:37 -0400693You may reply through the web interface or
694<a href="https://gerrit-review.googlesource.com/Documentation/intro-user.html#reply-by-email">via email</a>.
Bill Thiede822b2cb2014-07-03 17:42:23 -0400695</p>
696
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500697<h3 id="revise">Revise and resend</h3>
698
699<p>
700The Go contribution workflow is optimized for iterative revisions based on
701feedback.
702It is rare that an initial contribution will be ready to be applied as is.
703As you revise your contribution and resend Gerrit will retain a history of
704all the changes and comments made in the single URL.
705</p>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400706
707<p>
Andrew Bonventre2e405bd2017-10-04 00:02:37 -0400708You may respond to review comments through the web interface or
709<a href="https://gerrit-review.googlesource.com/Documentation/intro-user.html#reply-by-email">via email</a>.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100710</p>
711
712<p>
Bill Thiede822b2cb2014-07-03 17:42:23 -0400713When you have revised the code and are ready for another round of review,
Andrew Gerrandd708e922014-12-10 09:29:35 +1100714stage those changes and use <code>git</code> <code>change</code> to update the
715commit.
Han-Wen Nienhuysd5da1042017-07-14 15:38:49 -0600716To send the updated change for another round of review,
Andrew Gerrandd708e922014-12-10 09:29:35 +1100717run <code>git</code> <code>mail</code> again.
Bill Thiede822b2cb2014-07-03 17:42:23 -0400718</p>
719
720<p>
721The reviewer can comment on the new copy, and the process repeats.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100722The reviewer approves the change by giving it a positive score
723(+1 or +2) and replying <code>LGTM</code>: looks good to me.
Bill Thiede822b2cb2014-07-03 17:42:23 -0400724</p>
725
726<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100727You can see a list of your pending changes by running <code>git</code>
728<code>pending</code>, and switch between change branches with <code>git</code>
729<code>change</code> <code><i>&lt;branch&gt;</i></code>.
Russ Cox38a41ee2009-11-06 10:04:22 -0800730</p>
731
Russ Cox19e27c72016-01-06 15:23:47 -0500732<h3 id="sync">Synchronize your client</h3>
Russ Cox38a41ee2009-11-06 10:04:22 -0800733
Andrew Gerrandd708e922014-12-10 09:29:35 +1100734<p>
735While you were working, others might have submitted changes to the repository.
736To update your local branch, run
737</p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800738
739<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100740$ git sync
Russ Cox38a41ee2009-11-06 10:04:22 -0800741</pre>
742
Russ Cox38a41ee2009-11-06 10:04:22 -0800743<p>
Oling Catce365522014-12-14 14:32:56 +0800744(In git terms, <code>git</code> <code>sync</code> runs
Andrew Gerrandd708e922014-12-10 09:29:35 +1100745<code>git</code> <code>pull</code> <code>-r</code>.)
Russ Cox696e8022009-11-07 18:56:00 -0800746</p>
747
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500748<h3 id="resolving_conflicts">Resolving Conflicts</h3>
749
Russ Cox696e8022009-11-07 18:56:00 -0800750<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100751If files you were editing have changed, Git does its best to merge the
752remote changes into your local changes.
753It may leave some files to merge by hand.
754</p>
755
756<p>
757For example, suppose you have edited <code>sin.go</code> but
Russ Cox696e8022009-11-07 18:56:00 -0800758someone else has committed an independent change.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100759When you run <code>git</code> <code>sync</code>,
760you will get the (scary-looking) output:
Russ Cox38a41ee2009-11-06 10:04:22 -0800761
762<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100763$ git sync
764Failed to merge in the changes.
765Patch failed at 0023 math: improved Sin, Cos and Tan precision for very large arguments
766The copy of the patch that failed is found in:
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800767 /home/you/repo/.git/rebase-apply/patch
Andrew Gerrandd708e922014-12-10 09:29:35 +1100768
769When you have resolved this problem, run "git rebase --continue".
770If you prefer to skip this patch, run "git rebase --skip" instead.
771To check out the original branch and stop rebasing, run "git rebase --abort".
Russ Cox38a41ee2009-11-06 10:04:22 -0800772</pre>
773
Russ Cox696e8022009-11-07 18:56:00 -0800774<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100775If this happens, run
776</p>
777
778<pre>
779$ git status
780</pre>
781
782<p>
783to see which files failed to merge.
784The output will look something like this:
785</p>
786
787<pre>
788rebase in progress; onto a24c3eb
789You are currently rebasing branch 'mcgillicutty' on 'a24c3eb'.
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800790 (fix conflicts and then run "git rebase --continue")
791 (use "git rebase --skip" to skip this patch)
792 (use "git rebase --abort" to check out the original branch)
Andrew Gerrandd708e922014-12-10 09:29:35 +1100793
794Unmerged paths:
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800795 (use "git reset HEAD &lt;file&gt;..." to unstage)
796 (use "git add &lt;file&gt;..." to mark resolution)
Andrew Gerrandd708e922014-12-10 09:29:35 +1100797
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800798 <i>both modified: sin.go</i>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100799</pre>
800
801<p>
802The only important part in that transcript is the italicized "both modified"
803line: Git failed to merge your changes with the conflicting change.
804When this happens, Git leaves both sets of edits in the file,
805with conflicts marked by <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</code> and
Russ Cox696e8022009-11-07 18:56:00 -0800806<code>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</code>.
Tetsuo Kiso48347cc2014-07-07 16:31:20 +1000807It is now your job to edit the file to combine them.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100808Continuing the example, searching for those strings in <code>sin.go</code>
Russ Cox696e8022009-11-07 18:56:00 -0800809might turn up:
810</p>
811
812<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100813 arg = scale(arg)
814&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800815 if arg &lt; 1e9 {
Russ Cox696e8022009-11-07 18:56:00 -0800816=======
Katrina Owenbc953b22015-10-05 21:15:23 -0600817 if arg &lt; 1e10 {
Andrew Gerrandd708e922014-12-10 09:29:35 +1100818&gt;&gt;&gt;&gt;&gt;&gt;&gt; mcgillicutty
819 largeReduce(arg)
Russ Cox696e8022009-11-07 18:56:00 -0800820</pre>
821
822<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100823Git doesn't show it, but suppose the original text that both edits
824started with was 1e8; you changed it to 1e10 and the other change to 1e9,
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500825so the correct answer might now be 1e10.
826First, edit the section to remove the markers and leave the correct code:
Russ Cox696e8022009-11-07 18:56:00 -0800827</p>
828
829<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100830 arg = scale(arg)
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800831 if arg &lt; 1e10 {
Andrew Gerrandd708e922014-12-10 09:29:35 +1100832 largeReduce(arg)
Russ Cox696e8022009-11-07 18:56:00 -0800833</pre>
834
835<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100836Then tell Git that the conflict is resolved by running
Russ Cox696e8022009-11-07 18:56:00 -0800837</p>
838
Russ Coxd55abfd2009-12-09 14:05:12 -0800839<pre>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100840$ git add sin.go
Russ Coxd55abfd2009-12-09 14:05:12 -0800841</pre>
842
Russ Cox696e8022009-11-07 18:56:00 -0800843<p>
Russ Cox830813f2009-11-08 21:08:27 -0800844If you had been editing the file, say for debugging, but do not
845care to preserve your changes, you can run
Andrew Gerrandd708e922014-12-10 09:29:35 +1100846<code>git</code> <code>reset</code> <code>HEAD</code> <code>sin.go</code>
847to abandon your changes.
848Then run <code>git</code> <code>rebase</code> <code>--continue</code> to
849restore the change commit.
Russ Cox696e8022009-11-07 18:56:00 -0800850</p>
851
Russ Cox19e27c72016-01-06 15:23:47 -0500852<h3 id="download">Reviewing code by others</h3>
Dave Cheneyeda95902013-02-10 19:40:33 -0500853
854<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500855As part of the review process reviewers can propose changes directly (in the
856GitHub workflow this would be someone else attaching commits to a pull request).
857
858You can import these changes proposed by someone else into your local Git repository.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100859On the Gerrit review page, click the "Download ▼" link in the upper right
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500860corner, copy the "Checkout" command and run it from your local Git repo. It
861should look something like this:
Dave Cheneyeda95902013-02-10 19:40:33 -0500862</p>
863
864<pre>
Lloyd Dewolffbbf2192015-02-24 21:33:29 -0800865$ 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 -0500866</pre>
867
868<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100869To revert, change back to the branch you were working in.
Oling Cataecbcd02013-02-15 14:01:12 +1100870</p>
Dave Cheneyeda95902013-02-10 19:40:33 -0500871
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500872<h2 id="submit">Apply the change to the master branch</h2>
Russ Cox38a41ee2009-11-06 10:04:22 -0800873
874<p>
Andrew Gerrandd708e922014-12-10 09:29:35 +1100875After the code has been <code>LGTM</code>'ed, an approver may
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500876apply it to the master branch using the Gerrit UI.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100877There is a "Submit" button on the web page for the change
878that appears once the change is approved (marked +2).
Dave Cheneyeda95902013-02-10 19:40:33 -0500879</p>
880
881<p>
Russ Cox38a41ee2009-11-06 10:04:22 -0800882This checks the change into the repository.
883The change description will include a link to the code review,
884and the code review will be updated with a link to the change
885in the repository.
Andrew Gerrandd708e922014-12-10 09:29:35 +1100886Since the method used to integrate the changes is "Cherry Pick",
887the commit hashes in the repository will be changed by
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500888the "Submit" operation.
Russ Cox38a41ee2009-11-06 10:04:22 -0800889</p>
890
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500891<h2 id="more">More information</h2>
Robert Hencke75ba1812014-04-25 20:09:04 -0700892
893<p>
Steve Francia5f3e7aa2017-02-09 15:33:13 -0500894In addition to the information here, the Go community maintains a <a
895href="https://golang.org/wiki/CodeReview">CodeReview</a> wiki page.
Robert Hencke75ba1812014-04-25 20:09:04 -0700896Feel free to contribute to this page as you learn the review process.
897</p>