github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/doc/contribute.html (about)

     1  <!--{
     2  	"Title": "Contribution Guide"
     3  }-->
     4  
     5  <p>
     6  The Go project welcomes all contributors.
     7  </p>
     8  
     9  <p>
    10  This document is a guide to help you through the process
    11  of contributing to the Go project, which is a little different
    12  from that used by other open source projects.
    13  We assume you have a basic understanding of Git and Go.
    14  </p>
    15  
    16  <p>
    17  In addition to the information here, the Go community maintains a
    18  <a href="https://golang.org/wiki/CodeReview">CodeReview</a> wiki page.
    19  Feel free to contribute to the wiki as you learn the review process.
    20  </p>
    21  
    22  <p>
    23  Note that the <code>gccgo</code> front end lives elsewhere;
    24  see <a href="gccgo_contribute.html">Contributing to gccgo</a>.
    25  </p>
    26  
    27  <h2 id="contributor">Becoming a contributor</h2>
    28  
    29  <h3>Overview</h3>
    30  
    31  <p>
    32  The first step is registering as a Go contributor and configuring your environment.
    33  Here is a checklist of the required steps to follow:
    34  </p>
    35  
    36  <ul>
    37  <li>
    38  <b>Step 0</b>: Decide on a single Google Account you will be using to contribute to Go.
    39  Use that account for all the following steps and make sure that <code>git</code>
    40  is configured to create commits with that account's e-mail address.
    41  </li>
    42  <li>
    43  <b>Step 1</b>: <a href="https://cla.developers.google.com/clas">Sign and submit</a> a
    44  CLA (Contributor License Agreement).
    45  </li>
    46  <li>
    47  <b>Step 2</b>: Configure authentication credentials for the Go Git repository.
    48  Visit <a href="https://go.googlesource.com/">go.googlesource.com</a>, click
    49  on "Generate Password" (top right), and follow the instructions.
    50  </li>
    51  <li>
    52  <b>Step 3</b>: Register for Gerrit, the code review tool used by the Go team,
    53  by <a href="https://go-review.googlesource.com/login/">visiting this page</a>.
    54  The CLA and the registration need to be done only once for your account.
    55  </li>
    56  <li>
    57  <b>Step 4</b>: Install <code>git-codereview</code> by running
    58  <code>go get -u golang.org/x/review/git-codereview</code>
    59  </li>
    60  </ul>
    61  
    62  <p>
    63  If you prefer, there is an automated tool that walks through these steps.
    64  Just run:
    65  </p>
    66  
    67  <pre>
    68  $ go get -u golang.org/x/tools/cmd/go-contrib-init
    69  $ cd /code/to/edit
    70  $ go-contrib-init
    71  </pre>
    72  
    73  <p>
    74  The rest of this chapter elaborates on these instructions.
    75  If you have completed the steps above (either manually or through the tool), jump to
    76  <a href="#before_contributing">Before contributing code</a>.
    77  </p>
    78  
    79  <h3 id="google_account">Step 0: Select a Google Account</h3>
    80  
    81  <p>
    82  A contribution to Go is made through a Google account with a specific
    83  e-mail address.
    84  Make sure to use the same account throughout the process and
    85  for all your subsequent contributions.
    86  You may need to decide whether to use a personal address or a corporate address.
    87  The choice will depend on who
    88  will own the copyright for the code that you will be writing
    89  and submitting.
    90  You might want to discuss this topic with your employer before deciding which
    91  account to use.
    92  </p>
    93  
    94  <p>
    95  Google accounts can either be Gmail e-mail accounts, G Suite organization accounts, or
    96  accounts associated with an external e-mail address.
    97  For instance, if you need to use
    98  an existing corporate e-mail that is not managed through G Suite, you can create
    99  an account associated
   100  <a href="https://accounts.google.com/SignUpWithoutGmail">with your existing
   101  e-mail address</a>.
   102  </p>
   103  
   104  <p>
   105  You also need to make sure that your Git tool is configured to create commits
   106  using your chosen e-mail address.
   107  You can either configure Git globally
   108  (as a default for all projects), or locally (for a single specific project).
   109  You can check the current configuration with this command:
   110  </p>
   111  
   112  <pre>
   113  $ git config --global user.email  # check current global config
   114  $ git config user.email           # check current local config
   115  </pre>
   116  
   117  <p>
   118  To change the configured address:
   119  </p>
   120  
   121  <pre>
   122  $ git config --global user.email name@example.com   # change global config
   123  $ git config user.email name@example.com            # change local config
   124  </pre>
   125  
   126  
   127  <h3 id="cla">Step 1: Contributor License Agreement</h3>
   128  
   129  <p>
   130  Before sending your first change to the Go project
   131  you must have completed one of the following two CLAs.
   132  Which CLA you should sign depends on who owns the copyright to your work.
   133  </p>
   134  
   135  <ul>
   136  <li>
   137  If you are the copyright holder, you will need to agree to the
   138  <a href="https://developers.google.com/open-source/cla/individual">individual
   139  contributor license agreement</a>, which can be completed online.
   140  </li>
   141  <li>
   142  If your organization is the copyright holder, the organization
   143  will need to agree to the
   144  <a href="https://developers.google.com/open-source/cla/corporate">corporate
   145  contributor license agreement</a>.<br>
   146  </li>
   147  </ul>
   148  
   149  <p>
   150  You can check your currently signed agreements and sign new ones at
   151  the <a href="https://cla.developers.google.com/clas?pli=1&amp;authuser=1">Google Developers
   152  Contributor License Agreements</a> website.
   153  If the copyright holder for your contribution has already completed the
   154  agreement in connection with another Google open source project,
   155  it does not need to be completed again.
   156  </p>
   157  
   158  <p>
   159  If the copyright holder for the code you are submitting changes&mdash;for example,
   160  if you start contributing code on behalf of a new company&mdash;please send mail
   161  to the <a href="mailto:golang-dev@googlegroups.com"><code>golang-dev</code>
   162  mailing list</a>.
   163  This will let us know the situation so we can make sure an appropriate agreement is
   164  completed and update the <code>AUTHORS</code> file.
   165  </p>
   166  
   167  
   168  <h3 id="config_git_auth">Step 2: Configure git authentication</h3>
   169  
   170  <p>
   171  The main Go repository is located at
   172  <a href="https://go.googlesource.com">go.googlesource.com</a>,
   173  a Git server hosted by Google.
   174  Authentication on the web server is made through your Google account, but
   175  you also need to configure <code>git</code> on your computer to access it.
   176  Follow this steps:
   177  </p>
   178  
   179  <ol>
   180  <li>
   181  Visit <a href="https://go.googlesource.com">go.googlesource.com</a>
   182  and click on "Generate Password" in the page's top right menu bar.
   183  You will be redirected to accounts.google.com to sign in.
   184  </li>
   185  <li>
   186  After signing in, you will be taken to a page with the title "Configure Git".
   187  This page contains a personalized script that when run locally will configure Git
   188  to hold your unique authentication key.
   189  This key is paired with one that is generated and stored on the server,
   190  analogous to how SSH keys work.
   191  </li>
   192  <li>
   193  Copy and run this script locally in your terminal to store your secret
   194  authentication token in a <code>.gitcookies</code> file.
   195  If you are using a Windows computer and running <code>cmd</code>,
   196  you should instead follow the instructions in the yellow box to run the command;
   197  otherwise run the regular script.
   198  </li>
   199  </ol>
   200  
   201  <h3 id="auth">Step 3: Create a Gerrit account </h3>
   202  
   203  <p>
   204  Gerrit is an open-source tool used by Go maintainers to discuss and review
   205  code submissions.
   206  </p>
   207  
   208  <p>
   209  To register your account, visit <a href="https://go-review.googlesource.com/login/">
   210  go-review.googlesource.com/login/</a> and sign in once using the same Google Account you used above.
   211  </p>
   212  
   213  <h3 id="git-codereview_install">Step 4: Install the git-codereview command</h3>
   214  
   215  <p>
   216  Changes to Go must be reviewed before they are accepted, no matter who makes the change.
   217  A custom <code>git</code> command called <code>git-codereview</code>
   218  simplifies sending changes to Gerrit.
   219  </p>
   220  
   221  <p>
   222  Install the <code>git-codereview</code> command by running,
   223  </p>
   224  
   225  <pre>
   226  $ go get -u golang.org/x/review/git-codereview
   227  </pre>
   228  
   229  <p>
   230  Make sure <code>git-codereview</code> is installed in your shell path, so that the
   231  <code>git</code> command can find it.
   232  Check that
   233  </p>
   234  
   235  <pre>
   236  $ git codereview help
   237  </pre>
   238  
   239  <p>
   240  prints help text, not an error.
   241  </p>
   242  
   243  <p>
   244  On Windows, when using git-bash you must make sure that
   245  <code>git-codereview.exe</code> is in your <code>git</code> exec-path.
   246  Run <code>git --exec-path</code> to discover the right location then create a
   247  symbolic link or just copy the executable from $GOPATH/bin to this directory.
   248  </p>
   249  
   250  
   251  <h2 id="before_contributing">Before contributing code</h2>
   252  
   253  <p>
   254  The project welcomes code patches, but to make sure things are well
   255  coordinated you should discuss any significant change before starting
   256  the work.
   257  It's recommended that you signal your intention to contribute in the
   258  issue tracker, either by <a href="https://golang.org/issue/new">filing
   259  a new issue</a> or by claiming
   260  an <a href="https://golang.org/issues">existing one</a>.
   261  </p>
   262  
   263  <h3>Check the issue tracker</h3>
   264  
   265  <p>
   266  Whether you already know what contribution to make, or you are searching for
   267  an idea, the <a href="https://github.com/golang/go/issues">issue tracker</a> is
   268  always the first place to go.
   269  Issues are triaged to categorize them and manage the workflow.
   270  </p>
   271  
   272  <p>
   273  Most issues will be marked with one of the following workflow labels:
   274  </p>
   275  
   276  <ul>
   277  	<li>
   278  	<b>NeedsInvestigation</b>: The issue is not fully understood
   279  	and requires analysis to understand the root cause.
   280  	</li>
   281  	<li>
   282  	<b>NeedsDecision</b>: the issue is relatively well understood, but the
   283  	Go team hasn't yet decided the best way to address it.
   284  	It would be better to wait for a decision before writing code.
   285  	If you are interested on working on an issue in this state,
   286  	feel free to "ping" maintainers in the issue's comments
   287  	if some time has passed without a decision.
   288  	</li>
   289  	<li>
   290  	<b>NeedsFix</b>: the issue is fully understood and code can be written
   291  	to fix it.
   292  	</li>
   293  </ul>
   294  
   295  <p>
   296  You can use GitHub's search functionality to find issues to help out with. Examples:
   297  </p>
   298  
   299  <ul>
   300  	<li>
   301  	Issues that need investigation: <a href="https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsInvestigation"><code>is:issue is:open label:NeedsInvestigation</code></a>
   302  	</li>
   303  	<li>
   304  	Issues that need a fix: <a href="https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsFix"><code>is:issue is:open label:NeedsFix</code></a>
   305  	</li>
   306  	<li>
   307  	Issues that need a fix and have a CL: <a href="https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsFix+%22golang.org%2Fcl%22"><code>is:issue is:open label:NeedsFix "golang.org/cl"</code></a>
   308  	</li>
   309  	<li>
   310  	Issues that need a fix and do not have a CL: <a href="https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsFix+NOT+%22golang.org%2Fcl%22"><code>is:issue is:open label:NeedsFix NOT "golang.org/cl"</code></a>
   311  	</li>
   312  </ul>
   313  
   314  <h3 id="design">Open an issue for any new problem</h3>
   315  
   316  <p>
   317  Excluding very trivial changes, all contributions should be connected
   318  to an existing issue.
   319  Feel free to open one and discuss your plans.
   320  This process gives everyone a chance to validate the design,
   321  helps prevent duplication of effort,
   322  and ensures that the idea fits inside the goals for the language and tools.
   323  It also checks that the design is sound before code is written;
   324  the code review tool is not the place for high-level discussions.
   325  </p>
   326  
   327  <p>
   328  When planning work, please note that the Go project follows a <a
   329  href="https://golang.org/wiki/Go-Release-Cycle">six-month development cycle</a>.
   330  The latter half of each cycle is a three-month feature freeze during
   331  which only bug fixes and documentation updates are accepted.
   332  New contributions can be sent during a feature freeze, but they will
   333  not be merged until the freeze is over.
   334  </p>
   335  
   336  <p>
   337  Significant changes to the language, libraries, or tools must go
   338  through the
   339  <a href="https://golang.org/s/proposal-process">change proposal process</a>
   340  before they can be accepted.
   341  </p>
   342  
   343  <p>
   344  Sensitive security-related issues (only!) should be reported to <a href="mailto:security@golang.org">security@golang.org</a>.
   345  </p>
   346  
   347  <h2 id="sending_a_change_github">Sending a change via GitHub</h2>
   348  
   349  <p>
   350  First-time contributors that are already familiar with the
   351  <a href="https://guides.github.com/introduction/flow/">GitHub flow</a>
   352  are encouraged to use the same process for Go contributions.
   353  Even though Go
   354  maintainers use Gerrit for code review, a bot called Gopherbot has been created to sync
   355  GitHub pull requests to Gerrit.
   356  </p>
   357  
   358  <p>
   359  Open a pull request as you normally would.
   360  Gopherbot will create a corresponding Gerrit change and post a link to
   361  it on your GitHub pull request; updates to the pull request will also
   362  get reflected in the Gerrit change.
   363  When somebody comments on the change, their comment will be also
   364  posted in your pull request, so you will get a notification.
   365  </p>
   366  
   367  <p>
   368  Some things to keep in mind:
   369  </p>
   370  
   371  <ul>
   372  <li>
   373  To update the pull request with new code, just push it to the branch; you can either
   374  add more commits, or rebase and force-push (both styles are accepted).
   375  </li>
   376  <li>
   377  If the request is accepted, all commits will be squashed, and the final
   378  commit description will be composed by concatenating the pull request's
   379  title and description.
   380  The individual commits' descriptions will be discarded.
   381  See <a href="#commit_messages">Writing good commit messages</a> for some
   382  suggestions.
   383  </li>
   384  <li>
   385  Gopherbot is unable to sync line-by-line codereview into GitHub: only the
   386  contents of the overall comment on the request will be synced.
   387  Remember you can always visit Gerrit to see the fine-grained review.
   388  </li>
   389  </ul>
   390  
   391  <h2 id="sending_a_change_gerrit">Sending a change via Gerrit</h2>
   392  
   393  <p>
   394  It is not possible to fully sync Gerrit and GitHub, at least at the moment,
   395  so we recommend learning Gerrit.
   396  It's different but powerful and familiarity
   397  with help you understand the flow.
   398  </p>
   399  
   400  <h3>Overview</h3>
   401  
   402  <p>
   403  This is an overview of the overall process:
   404  </p>
   405  
   406  <ul>
   407  <li>
   408  <b>Step 1:</b> Clone the Go source code from <code>go.googlesource.com</code>
   409  and make sure it's stable by compiling and testing it once:
   410  <pre>
   411  $ git clone https://go.googlesource.com/go
   412  $ cd go/src
   413  $ ./all.bash                                # compile and test
   414  </pre>
   415  </li>
   416  
   417  <li>
   418  <b>Step 2:</b> Prepare changes in a new branch, created from the master branch.
   419  To commit the changes, use <code>git</code> <code>codereview</code> <code>change</code>; that
   420  will create or amend a single commit in the branch.
   421  <pre>
   422  $ git checkout -b mybranch
   423  $ [edit files...]
   424  $ git add [files...]
   425  $ git codereview change   # create commit in the branch
   426  $ [edit again...]
   427  $ git add [files...]
   428  $ git codereview change   # amend the existing commit with new changes
   429  $ [etc.]
   430  </pre>
   431  </li>
   432  
   433  <li>
   434  <b>Step 3:</b> Test your changes, re-running <code>all.bash</code>.
   435  <pre>
   436  $ ./all.bash    # recompile and test
   437  </pre>
   438  </li>
   439  
   440  <li>
   441  <b>Step 4:</b> Send the changes for review to Gerrit using <code>git</code>
   442  <code>codereview</code> <code>mail</code> (which doesn't use e-mail, despite the name).
   443  <pre>
   444  $ git codereview mail     # send changes to Gerrit
   445  </pre>
   446  </li>
   447  
   448  <li>
   449  <b>Step 5:</b> After a review, apply changes to the same single commit
   450  and mail them to Gerrit again:
   451  <pre>
   452  $ [edit files...]
   453  $ git add [files...]
   454  $ git codereview change   # update same commit
   455  $ git codereview mail     # send to Gerrit again
   456  </pre>
   457  </li>
   458  </ul>
   459  
   460  <p>
   461  The rest of this section describes these steps in more detail.
   462  </p>
   463  
   464  
   465  <h3 id="checkout_go">Step 1: Clone the Go source code</h3>
   466  
   467  <p>
   468  In addition to a recent Go installation, you need to have a local copy of the source
   469  checked out from the correct repository.
   470  You can check out the Go source repo onto your local file system anywhere
   471  you want as long as it's outside your <code>GOPATH</code>.
   472  Clone from <code>go.googlesource.com</code> (not GitHub):
   473  </p>
   474  
   475  <pre>
   476  $ git clone https://go.googlesource.com/go
   477  $ cd go
   478  </pre>
   479  
   480  <h3 id="make_branch">Step 2: Prepare changes in a new branch</h3>
   481  
   482  <p>
   483  Each Go change must be made in a separate branch, created from the master branch.
   484  You can use
   485  the normal <code>git</code> commands to create a branch and add changes to the
   486  staging area:
   487  </p>
   488  
   489  <pre>
   490  $ git checkout -b mybranch
   491  $ [edit files...]
   492  $ git add [files...]
   493  </pre>
   494  
   495  <p>
   496  To commit changes, instead of <code>git commit</code>, use <code>git codereview change</code>.
   497  </p>
   498  
   499  <pre>
   500  $ git codereview change
   501  (open $EDITOR)
   502  </pre>
   503  
   504  <p>
   505  You can edit the commit description in your favorite editor as usual.
   506  The  <code>git</code> <code>codereview</code> <code>change</code> command
   507  will automatically add a unique Change-Id line near the bottom.
   508  That line is used by Gerrit to match successive uploads of the same change.
   509  Do not edit or delete it.
   510  A Change-Id looks like this:
   511  </p>
   512  
   513  <pre>
   514  Change-Id: I2fbdbffb3aab626c4b6f56348861b7909e3e8990
   515  </pre>
   516  
   517  <p>
   518  The tool also checks that you've
   519  run <code>go</code> <code>fmt</code> over the source code, and that
   520  the commit message follows the <a href="#commit_messages">suggested format</a>.
   521  </p>
   522  
   523  <p>
   524  If you need to edit the files again, you can stage the new changes and
   525  re-run <code>git</code> <code>codereview</code> <code>change</code>: each subsequent
   526  run will amend the existing commit while preserving the Change-Id.
   527  </p>
   528  
   529  <p>
   530  Make sure that you always keep a single commit in each branch.
   531  If you add more
   532  commits by mistake, you can use <code>git</code> <code>rebase</code> to
   533  <a href="https://stackoverflow.com/questions/31668794/squash-all-your-commits-in-one-before-a-pull-request-in-github">squash them together</a>
   534  into a single one.
   535  </p>
   536  
   537  
   538  <h3 id="testing">Step 3: Test your changes</h3>
   539  
   540  <p>
   541  You've <a href="code.html">written and tested your code</a>, but
   542  before sending code out for review, run <i>all the tests for the whole
   543  tree</i> to make sure the changes don't break other packages or programs:
   544  </p>
   545  
   546  <pre>
   547  $ cd go/src
   548  $ ./all.bash
   549  </pre>
   550  
   551  <p>
   552  (To build under Windows use <code>all.bat</code>; this also requires
   553  setting the environment variable <code>GOROOT_BOOTSTRAP</code> to the
   554  directory holding the Go tree for the bootstrap compiler.)
   555  </p>
   556  
   557  <p>
   558  After running for a while and printing a lot of testing output, the command should finish
   559  by printing,
   560  </p>
   561  
   562  <pre>
   563  ALL TESTS PASSED
   564  </pre>
   565  
   566  <p>
   567  You can use <code>make.bash</code> instead of <code>all.bash</code>
   568  to just build the compiler and the standard library without running the test suite.
   569  Once the <code>go</code> tool is built, it will be installed as <code>bin/go</code>
   570  under the directory in which you cloned the Go repository, and you can
   571  run it directly from there.
   572  See also
   573  the section on how to <a href="#quick_test">test your changes quickly</a>.
   574  </p>
   575  
   576  <h3 id="mail">Step 4: Send changes for review</h3>
   577  
   578  <p>
   579  Once the change is ready and tested over the whole tree, send it for review.
   580  This is done with the <code>mail</code> sub-command which, despite its name, doesn't
   581  directly mail anything; it just sends the change to Gerrit:
   582  </p>
   583  
   584  <pre>
   585  $ git codereview mail
   586  </pre>
   587  
   588  <p>
   589  Gerrit assigns your change a number and URL, which <code>git</code> <code>codereview</code> <code>mail</code> will print, something like:
   590  </p>
   591  
   592  <pre>
   593  remote: New Changes:
   594  remote:   https://go-review.googlesource.com/99999 math: improved Sin, Cos and Tan precision for very large arguments
   595  </pre>
   596  
   597  <p>
   598  If you get an error instead, check the
   599  <a href="#troubleshooting_mail">Troubleshooting mail errors</a> section.
   600  </p>
   601  
   602  <p>
   603  If your change relates to an open GitHub issue and you have followed the <a href="#commit_messages">
   604  suggested commit message format</a>, the issue will be updated in a few minutes by a bot,
   605  linking your Gerrit change to it in the comments.
   606  </p>
   607  
   608  
   609  <h3 id="revise">Step 5: Revise changes after a review</h3>
   610  
   611  <p>
   612  Go maintainers will review your code on Gerrit, and you will get notifications via e-mail.
   613  You can see the review on Gerrit and comment on them there.
   614  You can also reply
   615  <a href="https://gerrit-review.googlesource.com/Documentation/intro-user.html#reply-by-email">using e-mail</a>
   616  if you prefer.
   617  </p>
   618  
   619  <p>
   620  If you need to revise your change after the review, edit the files in
   621  the same branch you previously created, add them to the Git staging
   622  area, and then amend the commit with
   623  <code>git</code> <code>codereview</code> <code>change</code>:
   624  </p>
   625  
   626  <pre>
   627  $ git codereview change     # amend current commit
   628  (open $EDITOR)
   629  $ git codereview mail       # send new changes to Gerrit
   630  </pre>
   631  
   632  <p>
   633  If you don't need to change the commit description, just save and exit from the editor.
   634  Remember not to touch the special Change-Id line.
   635  </p>
   636  
   637  <p>
   638  Again, make sure that you always keep a single commit in each branch.
   639  If you add more
   640  commits by mistake, you can use <code>git rebase</code> to
   641  <a href="https://stackoverflow.com/questions/31668794/squash-all-your-commits-in-one-before-a-pull-request-in-github">squash them together</a>
   642  into a single one.
   643  </p>
   644  
   645  <h2 id="commit_messages">Good commit messages</h2>
   646  
   647  <p>
   648  Commit messages in Go follow a specific set of conventions,
   649  which we discuss in this section.
   650  </p>
   651  
   652  <p>
   653  Here is an example of a good one:
   654  </p>
   655  
   656  <pre>
   657  math: improve Sin, Cos and Tan precision for very large arguments
   658  
   659  The existing implementation has poor numerical properties for
   660  large arguments, so use the McGillicutty algorithm to improve
   661  accuracy above 1e10.
   662  
   663  The algorithm is described at https://wikipedia.org/wiki/McGillicutty_Algorithm
   664  
   665  Fixes #159
   666  </pre>
   667  
   668  <h3>First line</h3>
   669  
   670  <p>
   671  The first line of the change description is conventionally a short one-line
   672  summary of the change, prefixed by the primary affected package.
   673  </p>
   674  
   675  <p>
   676  A rule of thumb is that it should be written so to complete the sentence
   677  "This change modifies Go to _____."
   678  That means it does not start with a capital letter, is not a complete sentence,
   679  and actually summarizes the result of the change.
   680  </p>
   681  
   682  <p>
   683  Follow the first line by a blank line.
   684  </p>
   685  
   686  <h3>Main content</h3>
   687  
   688  <p>
   689  The rest of the description elaborates and should provide context for the
   690  change and explain what it does.
   691  Write in complete sentences with correct punctuation, just like
   692  for your comments in Go.
   693  Don't use HTML, Markdown, or any other markup language.
   694  </p>
   695  
   696  <p>
   697  Add any relevant information, such as benchmark data if the change
   698  affects performance.
   699  The <a href="https://godoc.org/golang.org/x/perf/cmd/benchstat">benchstat</a>
   700  tool is conventionally used to format
   701  benchmark data for change descriptions.
   702  </p>
   703  
   704  <h3>Referencing issues</h3>
   705  
   706  <p>
   707  The special notation "Fixes #12345" associates the change with issue 12345 in the
   708  <a href="https://golang.org/issue/12345">Go issue tracker</a>.
   709  When this change is eventually applied, the issue
   710  tracker will automatically mark the issue as fixed.
   711  </p>
   712  
   713  <p>
   714  If the change is a partial step towards the resolution of the issue,
   715  uses the notation "Updates #12345".
   716  This will leave a comment in the issue
   717  linking back to the change in Gerrit, but it will not close the issue
   718  when the change is applied.
   719  </p>
   720  
   721  <p>
   722  If you are sending a change against a subrepository, you must use
   723  the fully-qualified syntax supported by GitHub to make sure the change is
   724  linked to the issue in the main repository, not the subrepository.
   725  All issues are tracked in the main repository's issue tracker.
   726  The correct form is "Fixes golang/go#159".
   727  </p>
   728  
   729  
   730  <h2 id="review">The review process</h2>
   731  
   732  <p>
   733  This section explains the review process in detail and how to approach
   734  reviews after a change has been mailed.
   735  </p>
   736  
   737  
   738  <h3 id="mistakes">Common beginner mistakes</h3>
   739  
   740  <p>
   741  When a change is sent to Gerrit, it is usually triaged within a few days.
   742  A maintainer will have a look and provide some initial review that for first-time
   743  contributors usually focuses on basic cosmetics and common mistakes.
   744  These include things like:
   745  </p>
   746  
   747  <ul>
   748  <li>
   749  Commit message not following the <a href="#commit_messages">suggested
   750  format</a>.
   751  </li>
   752  
   753  <li>
   754  The lack of a linked GitHub issue.
   755  The vast majority of changes
   756  require a linked issue that describes the bug or the feature that the change
   757  fixes or implements, and consensus should have been reached on the tracker
   758  before proceeding with it.
   759  Gerrit reviews do not discuss the merit of the change,
   760  just its implementation.
   761  <br>
   762  Only trivial or cosmetic changes will be accepted without an associated issue.
   763  </li>
   764  
   765  <li>
   766  Change sent during the freeze phase of the development cycle, when the tree
   767  is closed for general changes.
   768  In this case,
   769  a maintainer might review the code with a line such as <code>R=go1.12</code>,
   770  which means that it will be reviewed later when the tree opens for a new
   771  development window.
   772  You can add <code>R=go1.XX</code> as a comment yourself
   773  if you know that it's not the correct time frame for the change.
   774  </li>
   775  </ul>
   776  
   777  <h3 id="trybots">Trybots</h3>
   778  
   779  <p>
   780  After an initial reading of your change, maintainers will trigger trybots,
   781  a cluster of servers that will run the full test suite on several different
   782  architectures.
   783  Most trybots complete in a few minutes, at which point a link will
   784  be posted in Gerrit where you can see the results.
   785  </p>
   786  
   787  <p>
   788  If the trybot run fails, follow the link and check the full logs of the
   789  platforms on which the tests failed.
   790  Try to understand what broke, update your patch to fix it, and upload again.
   791  Maintainers will trigger a new trybot run to see
   792  if the problem was fixed.
   793  </p>
   794  
   795  <p>
   796  Sometimes, the tree can be broken on some platforms for a few hours; if
   797  the failure reported by the trybot doesn't seem related to your patch, go to the
   798  <a href="https://build.golang.org">Build Dashboard</a> and check if the same
   799  failure appears in other recent commits on the same platform.
   800  In this case,
   801  feel free to write a comment in Gerrit to mention that the failure is
   802  unrelated to your change, to help maintainers understand the situation.
   803  </p>
   804  
   805  <h3 id="reviews">Reviews</h3>
   806  
   807  <p>
   808  The Go community values very thorough reviews.
   809  Think of each review comment like a ticket: you are expected to somehow "close" it
   810  by acting on it, either by implementing the suggestion or convincing the
   811  reviewer otherwise.
   812  </p>
   813  
   814  <p>
   815  After you update the change, go through the review comments and make sure
   816  to reply to every one.
   817  You can click the "Done" button to reply
   818  indicating that you've implemented the reviewer's suggestion; otherwise,
   819  click on "Reply" and explain why you have not, or what you have done instead.
   820  </p>
   821  
   822  <p>
   823  It is perfectly normal for changes to go through several round of reviews,
   824  with one or more reviewers making new comments every time
   825  and then waiting for an updated change before reviewing again.
   826  This cycle happens even for experienced contributors, so
   827  don't be discouraged by it.
   828  </p>
   829  
   830  <h3 id="votes">Voting conventions</h3>
   831  
   832  <p>
   833  As they near a decision, reviewers will make a "vote" on your change.
   834  The Gerrit voting system involves an integer in the range -2 to +2:
   835  </p>
   836  
   837  <ul>
   838  	<li>
   839  	<b>+2</b> The change is approved for being merged.
   840  	Only Go maintainers can cast a +2 vote.
   841  	</li>
   842  	<li>
   843  	<b>+1</b> The change looks good, but either the reviewer is requesting
   844  	minor changes before approving it, or they are not a maintainer and cannot
   845  	approve it, but would like to encourage an approval.
   846  	</li>
   847  	<li>
   848  	<b>-1</b> The change is not good the way it is but might be fixable.
   849  	A -1 vote will always have a comment explaining why the change is unacceptable.
   850  	</li>
   851  	<li>
   852  	<b>-2</b> The change is blocked by a maintainer and cannot be approved.
   853  	Again, there will be a comment explaining the decision.
   854  	</li>
   855  </ul>
   856  
   857  <h3 id="submit">Submitting an approved change</h3>
   858  
   859  <p>
   860  After the code has been +2'ed, an approver will
   861  apply it to the master branch using the Gerrit user interface.
   862  This is called "submitting the change".
   863  </p>
   864  
   865  <p>
   866  The two steps (approving and submitting) are separate because in some cases maintainers
   867  may want to approve it but not to submit it right away (for instance,
   868  the tree could be temporarily frozen).
   869  </p>
   870  
   871  <p>
   872  Submitting a change checks it into the repository.
   873  The change description will include a link to the code review,
   874  which will be updated with a link to the change
   875  in the repository.
   876  Since the method used to integrate the changes is Git's "Cherry Pick",
   877  the commit hashes in the repository will be changed by
   878  the submit operation.
   879  </p>
   880  
   881  <p>
   882  If your change has been approved for a few days without being
   883  submitted, feel free to write a comment in Gerrit requesting
   884  submission.
   885  </p>
   886  
   887  
   888  <h3 id="more_information">More information</h3>
   889  
   890  <p>
   891  In addition to the information here, the Go community maintains a <a
   892  href="https://golang.org/wiki/CodeReview">CodeReview</a> wiki page.
   893  Feel free to contribute to this page as you learn more about the review process.
   894  </p>
   895  
   896  
   897  
   898  <h2 id="advanced_topics">Miscellaneous topics</h2>
   899  
   900  <p>
   901  This section collects a number of other comments that are
   902  outside the issue/edit/code review/submit process itself.
   903  </p>
   904  
   905  
   906  <h3 id="copyright">Copyright headers</h3>
   907  
   908  <p>
   909  Files in the Go repository don't list author names, both to avoid clutter
   910  and to avoid having to keep the lists up to date.
   911  Instead, your name will appear in the
   912  <a href="https://golang.org/change">change log</a> and in the <a
   913  href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file and perhaps the <a
   914  href="/AUTHORS"><code>AUTHORS</code></a> file.
   915  These files are automatically generated from the commit logs periodically.
   916  The <a href="/AUTHORS"><code>AUTHORS</code></a> file defines who &ldquo;The Go
   917  Authors&rdquo;&mdash;the copyright holders&mdash;are.
   918  </p>
   919  
   920  <p>
   921  New files that you contribute should use the standard copyright header:
   922  </p>
   923  
   924  <pre>
   925  // Copyright 2018 The Go Authors. All rights reserved.
   926  // Use of this source code is governed by a BSD-style
   927  // license that can be found in the LICENSE file.
   928  </pre>
   929  
   930  <p>
   931  (Use the current year if you're reading this in 2019 or beyond.)
   932  Files in the repository are copyrighted the year they are added.
   933  Do not update the copyright year on files that you change.
   934  </p>
   935  
   936  
   937  
   938  
   939  <h3 id="troubleshooting_mail">Troubleshooting mail errors</h3>
   940  
   941  <p>
   942  The most common way that the <code>git</code> <code>codereview</code> <code>mail</code>
   943  command fails is because the e-mail address in the commit does not match the one
   944  that you used during <a href="#google_account">the registration process</a>.
   945  
   946  <br>
   947  If you see something like...
   948  </p>
   949  
   950  <pre>
   951  remote: Processing changes: refs: 1, done
   952  remote:
   953  remote: ERROR:  In commit ab13517fa29487dcf8b0d48916c51639426c5ee9
   954  remote: ERROR:  author email address XXXXXXXXXXXXXXXXXXX
   955  remote: ERROR:  does not match your user account.
   956  </pre>
   957  
   958  <p>
   959  you need to configure Git for this repository to use the
   960  e-mail address that you registered with.
   961  To change the e-mail address to ensure this doesn't happen again, run:
   962  </p>
   963  
   964  <pre>
   965  $ git config user.email email@address.com
   966  </pre>
   967  
   968  <p>
   969  Then change the commit to use this alternative e-mail address with this command:
   970  </p>
   971  
   972  <pre>
   973  $ git commit --amend --author="Author Name &lt;email@address.com&gt;"
   974  </pre>
   975  
   976  <p>
   977  Then retry by running:
   978  </p>
   979  
   980  <pre>
   981  $ git codereview mail
   982  </pre>
   983  
   984  
   985  <h3 id="quick_test">Quickly testing your changes</h3>
   986  
   987  <p>
   988  Running <code>all.bash</code> for every single change to the code tree
   989  is burdensome.
   990  Even though it is strongly suggested to run it before
   991  sending a change, during the normal development cycle you may want
   992  to compile and test only the package you are developing.
   993  </p>
   994  
   995  <ul>
   996  <li>
   997  In general, you can run <code>make.bash</code> instead of <code>all.bash</code>
   998  to only rebuild the Go tool chain without running the whole test suite.
   999  Or you
  1000  can run <code>run.bash</code> to only run the whole test suite without rebuilding
  1001  the tool chain.
  1002  You can think of <code>all.bash</code> as <code>make.bash</code>
  1003  followed by <code>run.bash</code>.
  1004  </li>
  1005  
  1006  <li>
  1007  In this section, we'll call the directory into which you cloned the Go repository <code>$GODIR</code>.
  1008  The <code>go</code> tool built by <code>$GODIR/make.bash</code> will be installed
  1009  in <code>$GODIR/bin/go</code> and you
  1010  can invoke it to test your code.
  1011  For instance, if you
  1012  have modified the compiler and you want to test how it affects the
  1013  test suite of your own project, just run <code>go</code> <code>test</code>
  1014  using it:
  1015  
  1016  <pre>
  1017  $ cd &lt;MYPROJECTDIR&gt;
  1018  $ $GODIR/bin/go test
  1019  </pre>
  1020  </li>
  1021  
  1022  <li>
  1023  If you're changing the standard library, you probably don't need to rebuild
  1024  the compiler: you can just run the tests for the package you've changed.
  1025  You can do that either with the Go version you normally use, or
  1026  with the Go compiler built from your clone (which is
  1027  sometimes required because the standard library code you're modifying
  1028  might require a newer version than the stable one you have installed).
  1029  
  1030  <pre>
  1031  $ cd $GODIR/src/hash/sha1
  1032  $ [make changes...]
  1033  $ $GODIR/bin/go test .
  1034  </pre>
  1035  </li>
  1036  
  1037  <li>
  1038  If you're modifying the compiler itself, you can just recompile
  1039  the <code>compile</code> tool (which is the internal binary invoked
  1040  by <code>go</code> <code>build</code> to compile each single package).
  1041  After that, you will want to test it by compiling or running something.
  1042  
  1043  <pre>
  1044  $ cd $GODIR/src
  1045  $ [make changes...]
  1046  $ $GODIR/bin/go install cmd/compile
  1047  $ $GODIR/bin/go build [something...]   # test the new compiler
  1048  $ $GODIR/bin/go run [something...]     # test the new compiler
  1049  $ $GODIR/bin/go test [something...]    # test the new compiler
  1050  </pre>
  1051  
  1052  The same applies to other internal tools of the Go tool chain,
  1053  such as <code>asm</code>, <code>cover</code>, <code>link</code>, and so on.
  1054  Just recompile and install the tool using <code>go</code>
  1055  <code>install</code> <code>cmd/&lt;TOOL&gt;</code> and then use
  1056  the built Go binary to test it.
  1057  </li>
  1058  
  1059  <li>
  1060  In addition to the standard per-package tests, there is a top-level
  1061  test suite in <code>$GODIR/test</code> that contains
  1062  several black-box and regression tests.
  1063  The test suite is run
  1064  by <code>all.bash</code> but you can also run it manually:
  1065  
  1066  <pre>
  1067  $ cd $GODIR/test
  1068  $ $GODIR/bin/go run run.go
  1069  </pre>
  1070  </ul>
  1071  
  1072  <h3 id="subrepos">Contributing to subrepositories (golang.org/x/...)</h3>
  1073  
  1074  <p>
  1075  If you are contributing a change to a subrepository, obtain the
  1076  Go package using <code>go get</code>.
  1077  For example, to contribute
  1078  to <code>golang.org/x/oauth2</code>, check out the code by running:
  1079  </p>
  1080  
  1081  <pre>
  1082  $ go get -d golang.org/x/oauth2/...
  1083  </pre>
  1084  
  1085  <p>
  1086  Then, change your directory to the package's source directory
  1087  (<code>$GOPATH/src/golang.org/x/oauth2</code>), and follow the
  1088  normal contribution flow.
  1089  </p>
  1090  
  1091  
  1092  <h3 id="cc">Specifying a reviewer / CCing others</h3>
  1093  
  1094  <p>
  1095  Unless explicitly told otherwise, such as in the discussion leading
  1096  up to sending in the change, it's better not to specify a reviewer.
  1097  All changes are automatically CC'ed to the
  1098  <a href="https://groups.google.com/group/golang-codereviews">golang-codereviews@googlegroups.com</a>
  1099  mailing list.
  1100  If this is your first ever change, there may be a moderation
  1101  delay before it appears on the mailing list, to prevent spam.
  1102  </p>
  1103  
  1104  <p>
  1105  You can specify a reviewer or CC interested parties
  1106  using the <code>-r</code> or <code>-cc</code> options.
  1107  Both accept a comma-separated list of e-mail addresses:
  1108  </p>
  1109  
  1110  <pre>
  1111  $ git codereview mail -r joe@golang.org -cc mabel@example.com,math-nuts@swtch.com
  1112  </pre>
  1113  
  1114  
  1115  <h3 id="sync">Synchronize your client</h3>
  1116  
  1117  <p>
  1118  While you were working, others might have submitted changes to the repository.
  1119  To update your local branch, run
  1120  </p>
  1121  
  1122  <pre>
  1123  $ git codereview sync
  1124  </pre>
  1125  
  1126  <p>
  1127  (Under the covers this runs
  1128  <code>git</code> <code>pull</code> <code>-r</code>.)
  1129  </p>
  1130  
  1131  
  1132  <h3 id="download">Reviewing code by others</h3>
  1133  
  1134  <p>
  1135  As part of the review process reviewers can propose changes directly (in the
  1136  GitHub workflow this would be someone else attaching commits to a pull request).
  1137  
  1138  You can import these changes proposed by someone else into your local Git repository.
  1139  On the Gerrit review page, click the "Download ▼" link in the upper right
  1140  corner, copy the "Checkout" command and run it from your local Git repo.
  1141  It will look something like this:
  1142  </p>
  1143  
  1144  <pre>
  1145  $ git fetch https://go.googlesource.com/review refs/changes/21/13245/1 &amp;&amp; git checkout FETCH_HEAD
  1146  </pre>
  1147  
  1148  <p>
  1149  To revert, change back to the branch you were working in.
  1150  </p>
  1151  
  1152  
  1153  <h3 id="git-config">Set up git aliases</h3>
  1154  
  1155  <p>
  1156  The <code>git-codereview</code> command can be run directly from the shell
  1157  by typing, for instance,
  1158  </p>
  1159  
  1160  <pre>
  1161  $ git codereview sync
  1162  </pre>
  1163  
  1164  <p>
  1165  but it is more convenient to set up aliases for <code>git-codereview</code>'s own
  1166  subcommands, so that the above becomes,
  1167  </p>
  1168  
  1169  <pre>
  1170  $ git sync
  1171  </pre>
  1172  
  1173  <p>
  1174  The <code>git-codereview</code> subcommands have been chosen to be distinct from
  1175  Git's own, so it's safe to define these aliases.
  1176  To install them, copy this text into your
  1177  Git configuration file (usually <code>.gitconfig</code> in your home directory):
  1178  </p>
  1179  
  1180  <pre>
  1181  [alias]
  1182  	change = codereview change
  1183  	gofmt = codereview gofmt
  1184  	mail = codereview mail
  1185  	pending = codereview pending
  1186  	submit = codereview submit
  1187  	sync = codereview sync
  1188  </pre>
  1189  
  1190  
  1191  <h3 id="multiple_changes">Sending multiple dependent changes</h3>
  1192  
  1193  <p>
  1194  Advanced users may want to stack up related commits in a single branch.
  1195  Gerrit allows for changes to be dependent on each other, forming such a dependency chain.
  1196  Each change will need to be approved and submitted separately but the dependency
  1197  will be visible to reviewers.
  1198  </p>
  1199  
  1200  <p>
  1201  To send out a group of dependent changes, keep each change as a different commit under
  1202  the same branch, and then run:
  1203  </p>
  1204  
  1205  <pre>
  1206  $ git codereview mail HEAD
  1207  </pre>
  1208  
  1209  <p>
  1210  Make sure to explicitly specify <code>HEAD</code>, which is usually not required when sending
  1211  single changes.
  1212  </p>