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