From: Giovanni Bajo Date: Tue, 13 Feb 2018 01:51:23 +0000 (+0100) Subject: doc: first version of new contribute guide X-Git-Tag: go1.11beta1~1143 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a3d8326993f25869ffb01f27a085abcfabbb42ef;p=gostls13.git doc: first version of new contribute guide I've reorganized the guide and rewritten large sections. The structure is now more clear and logical, and can be understood and navigated using the summary displayed at the top of the page (before, the summary was confusing because the guide contained H1s that were being ignored by the summary). Both the initial onboarding process and the Gerrit change submission process have been reworked to include a concise checklist of steps that can be read and understood in a few seconds, for people that don't want or need to bother with details. More in-depth descriptions have been moved into separate sections, one per each checklist step. This is by far the biggest improvement, as the previous approach of having to read several pages just to understand the requires steps was very scaring for beginners, in addition of being harder to navigate. GitHub pull requests have been integrated as a different way to submit a change, suggested for first time contributors. The review process has been described in more details, documenting the workflow and the used conventions. Most miscellanea have been moved into an "advanced topics" chapter. Paragraphs describing how to use git have been removed to simplify reading. This guide should focus on Go contribution, and not help users getting familiar with git, for which many guides are available. Change-Id: I6f4b76583c9878b230ba1d0225745a1708fad2e8 Reviewed-on: https://go-review.googlesource.com/93495 Reviewed-by: Rob Pike --- diff --git a/doc/contribute.html b/doc/contribute.html index e5312becbb..4664f65069 100644 --- a/doc/contribute.html +++ b/doc/contribute.html @@ -10,32 +10,54 @@ process. This guide assumes you have a basic understanding of Git and Go.

-(Note that the gccgo frontend lives elsewhere; -see Contributing to gccgo.) +In addition to the information here, the Go community maintains a +CodeReview wiki page. +Feel free to contribute to the wiki as you learn the review process.

-Sensitive security-related issues should be reported to security@golang.org. +Note that the gccgo front end lives elsewhere; +see Contributing to gccgo.

-

Becoming a contributor

+

Becoming a contributor

+ +

Overview

-Before you can contribute to the Go project you need to setup a few prerequisites. -The Go project uses Gerrit, an open -source online tool, to perform all code reviews. -Gerrit uses your email address as a unique identifier. -The Go project contributing flow is currently configured to work only with Google Accounts. -You must go through the following process prior to contributing. -You only need to do this once per Google Account. +The first step is registering as a Go contributor and configuring your environment. +Here is a very quick checklist of the required steps, that you will need +to follow:

-

Automatically set up & diagnose your development environment

+ +

- The go-contrib-init tool configures and debugs your Go - development environment, automatically performing many of the steps - on this page, or telling you what you need to do next. If you wish - to use it, run: +If you prefer, we have an automated tool that walks through these steps. Just +run:

@@ -45,71 +67,57 @@ $ go-contrib-init
 

- The tool will either set things up, tell you that everything is - configured, or tell you what steps you need to do manually. +The rest of this chapter elaborates on these steps. +If you have completed the steps above (either manually or through the tool), jump to +Making a change.

-

Configure Git to use Gerrit

+

Step 0: Select a Google Account

+

-You'll need a web browser and a command line terminal. -You should already have Git installed. +A contribution to Go is made through a Google account, with a specific +e-mail address. Make sure to pick one and use it throughout the process and +for all your contributions. You may need to decide whether to +use a personal address or a corporate address. The choice will depend on who +will own the copyright for the code that you will be writing +and submitting. Consider discussing this with your employer.

-Gerrit uses Google Accounts for authentication. -If you don't have a Google Account, you can create an account which -includes -a new Gmail email account or create an account associated +Google Accounts can either be Gmail email accounts, G-Suite organization accounts, or +accounts associated with an external e-mail address. For instance, if you need to use +an existing corporate e-mail that is not managed through G-Suite, you can create +an account associated with your existing email address.

-

Step 1: Sign in to googlesource and generate a password

-

-Visit go.googlesource.com -and click on "Generate Password" in the page's top right menu bar. -You will be redirected to accounts.google.com to sign in. -

- -

Step 2: Run the provided script

+You also need to make sure that git is configured to author commits +using the same e-mail address. You can either configure it globally +(as a default for all projects), or locally (for a single specific project). +You can check the current configuration with this command:

-After signing in, you are taken to a page on go.googlesource.com with the title "Configure Git". -This page contains a personalized script which when run locally will configure git -to have your unique authentication key. -This key is paired with one generated server side similar to how ssh keys work. -

-

-Copy and run this script locally in your command line terminal. -(On a Windows computer using cmd you should instead follow the instructions -in the yellow box to run the command. If you are using git-bash use the same -script as *nix.) -

+
+$ git config --global user.email  # check current global config
+$ git config user.email           # check current local config
+
-

-Your secret authentication token is now in a .gitcookies file -and Git is configured to use this file. -

+

To change the configured address:

-

Step 3: Register with Gerrit

+
+$ git config --global user.email name@example.com   # change global config
+$ git config user.email name@example.com            # change local config
+
-

-Now that you have your authentication token, you need to register your -account with Gerrit. -To do this, visit -go-review.googlesource.com/login/. -Sign in using the same Google Account you used above. -

-

Contributor License Agreement

+

Step 1: Contributor License Agreement

-

Which CLA

Before sending your first change to the Go project you must have completed one of the following two CLAs. Which CLA you should sign depends on who owns the copyright to your work. -

-If the copyright holder for your contribution has already completed the +You can check your currently signed agreements and sign new ones, through +the Google Developers +Contributor License Agreements website. +If the copyright holder for your contribution has already completed the agreement in connection with another Google open source project, -it does not need to be completed again. -

- -

Completing the CLA

- -

-You can see your currently signed agreements and sign new ones through the Gerrit -interface. -To do this, Log into Gerrit, -then visit the Agreements -page. -If you do not have a signed agreement listed there, you can create one -by clicking "New Contributor Agreement" and following the steps. +it does not need to be completed again.

@@ -150,18 +149,58 @@ to golang-dev and let us know, so that we can make sure an appropriate agreement completed and update the AUTHORS file.

- -

Preparing a Development Environment for Contributing

-

Setting up Git for submission to Gerrit

+

Step 2: Configure git authentication

+ +

+Go development happens on go.googlesource.com, +a git server hosted by Google. +Authentication on the web server is made through your Google account, but +you also need to configure git on your computer to access it. +Follow this steps: +

+ +
    +
  1. +Visit go.googlesource.com +and click on "Generate Password" in the page's top right menu bar. +You will be redirected to accounts.google.com to sign in. +
  2. +
  3. +After signing in, you are taken to a page with the title "Configure Git". +This page contains a personalized script that when run locally will configure git +to have your unique authentication key. +This key is paired with one generated server side, analogous to how SSH keys work. +
  4. +
  5. +Copy and run this script locally in your command line terminal, to store your +secret authentication token in a .gitcookies file. +(On a Windows computer using cmd you should instead follow the instructions +in the yellow box to run the command. If you are using git-bash use the same +script as *nix.). +
  6. +
+ +

Step 3: Create a Gerrit account

+ +

+Gerrit is an open-source tool used by Go maintainers to discuss and review +code submissions. +

+ +

+To register your account, visit +go-review.googlesource.com/login/ and sign in once using the same Google Account you used above. +

+ +

Step 4: Install the git-codereview command

+

Changes to Go must be reviewed before they are accepted, no matter who makes the change. A custom git command called git-codereview, discussed below, -helps manage the code review process through a Google-hosted -instance of Gerrit. +helps to send changes to Gerrit.

-

Install the git-codereview command

Install the git-codereview command by running,

@@ -190,300 +229,345 @@ Run git --exec-path to discover the right location then create a symbolic link or simply copy the executable from $GOPATH/bin to this directory.

+ +

Before contributing code

+

-Note to Git aficionados: -The git-codereview command is not required to -upload and manage Gerrit code reviews. -For those who prefer plain Git, the text below gives the Git equivalent of -each git-codereview command. +The project welcomes submissions but please let everyone know what +you're working on if you want to change or add to the Go repositories.

-If you do use plain Git, note that you still need the commit hooks that the -git-codereview command configures; those hooks add a Gerrit -Change-Id line to the commit message and check that all Go source -files have been formatted with gofmt. -Even if you intend to use plain Git for -daily work, install the hooks in a new Git checkout by running -git-codereview hooks. +Before undertaking to write something new for the Go project, +please file an issue +(or claim an existing issue).

-

Set up git aliases

+

Check the issue tracker

-

-The git-codereview command can be run directly from the shell -by typing, for instance, +

Whether you already know what contribution to make, or you are searching for +an idea, the issue tracker is +always the first place to go. Issues are triaged to categorize them and manage +the workflow.

-
-$ git codereview sync
-
- -

-but it is more convenient to set up aliases for git-codereview's own -subcommands, so that the above becomes, +

Most issues will be marked with one of the following workflow labels: +

-
-$ git sync
-
+

Open an issue for any new problem

-The git-codereview subcommands have been chosen to be distinct from -Git's own, so it's safe to do so. +Excluding very trivial changes, all contributions should be connected +to an existing issue. Feel free to open one and discuss what your +plans are. This process gives everyone a chance to validate the design, +helps prevent duplication of effort, +and ensures that the idea fits inside the goals for the language and tools. +It also checks that the design is sound before code is written; +the code review tool is not the place for high-level discussions.

-The aliases are optional, but in the rest of this document we will assume -they are installed. -To install them, copy this text into your Git configuration file -(usually .gitconfig in your home directory): +When planning work, please note that the Go project follows a six-month development cycle. +The latter half of each cycle is a three-month feature freeze during +which only bug fixes and doc updates are accepted. New contributions can be +sent during a feature freeze but will not be accepted until the freeze thaws.

-
-[alias]
-	change = codereview change
-	gofmt = codereview gofmt
-	mail = codereview mail
-	pending = codereview pending
-	submit = codereview submit
-	sync = codereview sync
-
- - -

Understanding the git-codereview command

- -

After installing the git-codereview command, you can run

- -
-$ git codereview help
-
+

Significant changes must go through the +change proposal process +before they can be accepted.

-to learn more about its commands. -You can also read the command documentation. +Sensitive security-related issues should be reported to security@golang.org.

- -

Making a Contribution

- -

Discuss your design

+

Sending a change via GitHub

-The project welcomes submissions but please let everyone know what -you're working on if you want to change or add to the Go repositories. +First-time contributors that are already familiar with the +GitHub flow +are encouraged to use the same process for Go contributions. Even though Go +maintainers use Gerrit for code review, a bot has been created to sync +GitHub pull requests to Gerrit.

-Before undertaking to write something new for the Go project, -please file an issue -(or claim an existing issue). -Significant changes must go through the -change proposal process -before they can be accepted. +Open a pull request as you would normally do. Gopherbot will automatically +sync the code and post a link to Gerrit. When somebody comments on the +change, it will be posted in the pull request, so you will also get a notification.

-

-This process gives everyone a chance to validate the design, -helps prevent duplication of effort, -and ensures that the idea fits inside the goals for the language and tools. -It also checks that the design is sound before code is written; -the code review tool is not the place for high-level discussions. -

+

Some things to keep in mind: -

-When planning work, please note that the Go project follows a six-month development cycle. -The latter half of each cycle is a three-month feature freeze during -which only bug fixes and doc updates are accepted. New contributions can be -sent during a feature freeze but will not be accepted until the freeze thaws. +

-

Not sure what change to make?

+

Sending a change via Gerrit

-If you want to become familiar with Gerrit and the contribution process, -but aren't sure what you'd like to contribute just yet, you can use the scratch repository to practice -making a change. +It is not possible to fully sync Gerrit and GitHub, at least at the moment, +so we recommend learning Gerrit. It's different but powerful and familiarity +with help you understand the flow.

-

Making a change

+

Overview

-

Getting Go Source

-

-First you need to have a local copy of the source checked out from the correct -repository. -As Go builds Go you will also likely need to have a working version -of Go installed (some documentation changes may not need this). -This should be a recent version of Go and can be obtained via any package or -binary distribution or you can build it from source. +

This is an overview of the overall process: +

+

The rest of this chapter describes these steps in more detail.

+ + +

Step 1: Clone the Go source code

+

-You should checkout the Go source repo anywhere you want as long as it's -outside of your $GOPATH. -Go to a directory where you want the source to appear and run the following -command in a terminal. +In addition to a recent Go installation, you need to have a local copy of the source +checked out from the correct repository. You should check out the Go source repo anywhere +you want as long as it's outside of your GOPATH. Either clone from +go.googlesource.com or GitHub:

-$ git clone https://go.googlesource.com/go
+$ git clone https://github.com/golang/go   # or https://go.googlesource.com/go
 $ cd go
 
-

Contributing to the main Go tree

+

Step 2: Prepare changes in a new branch

-Most Go installations use a release branch, but new changes should -only be made based on the master branch.
-(They may be applied later to a release branch as part of the release process, -but most contributors won't do this themselves.) -Before making a change, make sure you start on the master branch: +Each Go change must be made in a separate branch, created from the master branch. You can use +the normal git commands to create a branch and add changes to the +staging area:

-$ git checkout master
-$ git sync
+$ git checkout -b mybranch
+$ [edit files...]
+$ git add [files...]
 

-(In Git terms, git sync runs -git pull -r.) +To commit changes, instead of git commit, use git codereview change.

-

Contributing to subrepositories (golang.org/x/...)

+
+$ git codereview change
+(open $EDITOR)
+

-If you are contributing a change to a subrepository, obtain the -Go package using go get. For example, to contribute -to golang.org/x/oauth2, check out the code by running: +You can edit the commit description in your favorite editor as usual. +git codereview change will automatically +add a Change-Id line near the bottom. That line is used by +Gerrit to match successive uploads of the same change. Do not edit or delete it. +This is an example:

-$ go get -d golang.org/x/oauth2/...
+commit fef82cf89a34935a41bd0e3c1e0c2d9d6de29ee2 (HEAD -> test)
+Author: Giovanni Bajo 
+Date:   Tue Feb 13 01:07:15 2018 +0100
+
+    cmd/compile: test
+
+    Change-Id: I2fbdbffb3aab626c4b6f56348861b7909e3e8990
 

-Then, change your directory to the package's source directory -($GOPATH/src/golang.org/x/oauth2). +git codereview change also checks that you've +run go fmt over the source code, and that +the commit message follows the suggested format.

-

Make your changes

+

+If you need to edit the files again, you can stage the new changes and +re-run git codereview change: each subsequent +run will amend the existing commit. +

-The entire checked-out tree is editable. -Make your changes as you see fit ensuring that you create appropriate -tests along with your changes. Test your changes as you go. +Make sure that you always keep a single commit in each branch. If you add more +commits by mistake, you can use git rebase to +squash them together +into a single one.

- + +

Step 3: Test changes

-Files in the Go repository don't list author names, both to avoid clutter -and to avoid having to keep the lists up to date. -Instead, your name will appear in the -change log and in the CONTRIBUTORS file and perhaps the AUTHORS file. -These files are automatically generated from the commit logs periodically. -The AUTHORS file defines who “The Go -Authors”—the copyright holders—are. +You've written and tested your code, but +before sending code out for review, run all the tests for the whole +tree to make sure the changes don't break other packages or programs:

-

New files that you contribute should use the standard copyright header:

-
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
+$ cd go/src
+$ ./all.bash
 

-Files in the repository are copyright the year they are added. -Do not update the copyright year on files that you change. +(To build under Windows use all.bat; this also requires +setting the environment variable GOROOT_BOOTSTRAP to the +bootstrap compiler)

-

Commit your changes

-

-Once you have edited files, you must tell Git that they have been modified. -You must also tell Git about any files that are added, removed, or renamed files. -These operations are done with the usual Git commands, -git add, -git rm, -and -git mv. +After running for a while, the command should print:

+
+"ALL TESTS PASSED".
+
+ +

Notice that you can use make.bash instead of all.bash +to just build the compiler without running the testsuite. Once the compiler is +built, you can run it directly from <GOCLONEDIR>/bin/go; see also +the section on quickly test your changes.

+ +

Step 4: Send changes for review

+

-Once you have the changes queued up, you will want to commit them. -In the Go contribution workflow this is done with a git -change command, which creates a local branch and commits the changes -directly to that local branch. +Once the change is ready, send it for review. +This is done via the mail sub-command which despite its name, doesn't +directly mail anything, it just sends the change to Gerrit:

+
+$ git codereview mail
+
+

-The workflow described here assumes a single change per branch. -It is also possible to prepare a sequence of (usually related) changes in a single branch. -See the git-codereview documentation for details. +Gerrit assigns your change a number and URL, which git codereview mail will print, something like:

-$ git change <branch>
+remote: New Changes:
+remote:   https://go-review.googlesource.com/99999 math: improved Sin, Cos and Tan precision for very large arguments
 

-The name <branch> is an arbitrary one you choose to identify the -local branch containing your changes and will not be used elsewhere. -This is an offline operation and nothing will be sent to the server yet. +If you get an error instead, check the +Troubleshooting mail errors section.

-(In Git terms, git change <branch> -runs git checkout -b branch, -then git branch --set-upstream-to origin/master, -then git commit.) +If your change relates to an open GitHub issue and you have followed the +suggested commit message format, the issue will be updated in a few minutes by a bot, +linking your Gerrit change in it.

+ +

Step 5: Revise changes after a review

+

-As the git commit is the final step, Git will open an -editor to ask for a commit message. (It uses the editor named by -the $EDITOR environment variable, -vi by default.) +Go maintainers will review your code on Gerrit, and you will get notifications via email. +You can see the review on Gerrit, and comment on them. You can also reply +via email +if you prefer. +

-The file will look like: +

+When you're ready to revise your submitted code, edit the files in correct branch, +add them to the git staging area, and then amend the commit with +git codereview change:

-
-# Please enter the commit message for your changes. Lines starting
-# with '#' will be ignored, and an empty message aborts the commit.
-# On branch foo
-# Changes not staged for commit:
-#	modified:   editedfile.go
-#
+$ git codereview change     # amend current commit
+(open $EDITOR)
+$ git codereview mail       # send new changes to Gerrit
 

-At the beginning of this file is a blank line; replace it -with a thorough description of your change. -The first line of the change description is conventionally a one-line -summary of the change, prefixed by the primary affected package, -and is used as the subject for code review email. -It should complete the sentence "This change modifies Go to _____." -The rest of the description elaborates and should provide context for the -change and explain what it does. -Write in complete sentences with correct punctuation, just like -for your comments in Go. -If there is a helpful reference, mention it here. -If you've fixed an issue, reference it by number with a # before it. +If you don't need to change the commit description, just save and exit from the editor. +Remember not to touch the special Change-Id line.

-After editing, the template might now read: +Make sure that you always keep a single commit in each branch. If you add more +commits by mistake, you can use git rebase to +squash them together +into a single one.

+

Writing good commit messages

+ +

Commit messages in Go follow a specific convention. Read this chapter +to learn more about it. This is an example of a good one: +

 math: improve Sin, Cos and Tan precision for very large arguments
 
@@ -494,130 +578,231 @@ accuracy above 1e10.
 The algorithm is described at http://wikipedia.org/wiki/McGillicutty_Algorithm
 
 Fixes #159
-
-# Please enter the commit message for your changes. Lines starting
-# with '#' will be ignored, and an empty message aborts the commit.
-# On branch foo
-# Changes not staged for commit:
-#	modified:   editedfile.go
-#
 
+

+ +

First line

-The commented section of the file lists all the modified files in your client. -It is best to keep unrelated changes in different commits, -so if you see a file listed that should not be included, abort -the command and move that file to a different branch. +The first line of the change description is conventionally a one-line +summary of the change, prefixed by the primary affected package.

+ +

It should be written so to complete the sentence "This change modifies Go to _____."

+ +

Main content

+ +

The rest of the description elaborates and should provide context for the +change and explain what it does. +Write in complete sentences with correct punctuation, just like +for your comments in Go. +If there is a helpful reference, mention it here.

+

Referencing issues

+

The special notation "Fixes #159" associates the change with issue 159 in the Go issue tracker. When this change is eventually applied, the issue tracker will automatically mark the issue as fixed. -(There are several such conventions, described in detail in the -GitHub Issue Tracker documentation.)

-Once you have finished writing the commit message, -save the file and exit the editor. +If the change is a partial step towards the resolution of the issue, +uses the notation "Updates #159". This will leave a comment in the issue +linking back to the change in Gerrit, but it will not close the issue +when the change is applied.

-You must have the $EDITOR environment variable set properly and working properly (exiting cleanly) -for this operation to succeed. -If you run into any issues at this step, it's likely your editor isn't exiting cleanly. -Try setting a different editor in your $EDITOR environment variable. +If you are sending a change against a subrepository, you must use +the fully-qualified syntax supported by GitHub, to make sure the change is +linked to the issue in the main repository. The correct form is "Fixes golang/go#159".

+ + + + + +

The review process

+

-If you wish to do more editing, re-stage your changes using -git add, and then run +This section explains the review process in details, and how to approach +reviews after a change was submitted.

-
-$ git change
-
+ +

Common beginner mistakes

-to update the change description and incorporate the staged changes. -The change description contains a Change-Id line near the bottom, -added by a Git commit hook during the initial -git change. -That line is used by Gerrit to match successive uploads of the same change. -Do not edit or delete it. +When a change is submitted to Gerrit, it is usually triaged in the next few days. +A maintainer will give a look and submit some initial review, that for first-time +contributors usually focus on basic cosmetics and common mistakes. For instance:

+ + +

Trybots

+ +

After an initial reading of your patch, maintainers will trigger trybots, +a cluster of servers that will run the full testsuite on several different +architectures. Most trybots run complete in a few minutes, and a link will +be posted in Gerrit where you can see the results.

+ +

If the trybot run fails, follow the link and check the full logs of the +platforms on which the tests failed. Try to understand what broke, and +update your patch. Maintainers will trigger a new trybot run to see +if the problem was fixed.

+ +

Sometimes, the tree can be broken on some platforms for a few hours; if +the failure in trybot logs doesn't seem related to your patch, go to the +Build Dashboard and check if the same +failures appears in the recent commits, on the same platform. In this case, +feel free to write a comment in Gerrit to mention that the failure is +unrelated to your change, to help maintainers understanding the situation.

+ +

Reviews

+ +

The Go team values very thorough reviews. Consider +each line comment like a ticket: you are expected to somehow "close" it +by acting on it, either by implementing the suggestion or convincing the +reviewer otherwise.

+ +

After you update the change, go through line comments and make sure +to reply on every one. You can click the "Done" button to reply +indicating that you've implemented the reviewer's suggestion; otherwise, +click on "Reply" and explain why you have not.

+ +

It is absolutely normal for changes to go through several round of reviews, +in which the reviewer make new comments every time and then wait for an updated +change to be uploaded. This also happens for experienced contributors, so +don't feel discouraged by it.

+ +

Voting conventions

+

-(In Git terms, git change with no branch name -runs git commit --amend.) +At some point, reviewers will express a vote on your change. This is the +voting convention: +

-

Testing

+

Submitting an approved change

-You've written and tested your code, but -before sending code out for review, run all the tests for the whole -tree to make sure the changes don't break other packages or programs: +After the code has been +2'ed, an approver will +apply it to the master branch using the Gerrit UI. This is +called "submission".

-
-$ cd go/src
-$ ./all.bash
-
-

-(To build under Windows use all.bat.) +The two steps are separate because in some cases maintainers +may want to approve it but not to submit it right away (e.g. +the tree could be temporarily frozen).

-After running for a while, the command should print +Submission checks the change into the repository. +The change description will include a link to the code review, +and the code review will be updated with a link to the change +in the repository. +Since the method used to integrate the changes is "Cherry Pick", +the commit hashes in the repository will be changed by +the "Submit" operation.

-
-"ALL TESTS PASSED".
-
+

If your change has been approved for a few days without being +submitted, feel free to write a comment in Gerrit requesting +submission.

+ -

Send the change for review

+

More information

-Once the change is ready, send it for review. -This is similar to a git push in a GitHub style workflow. -This is done via the mail alias setup earlier which despite its name, doesn't -directly mail anything, it simply sends the change to Gerrit via git push. +In addition to the information here, the Go community maintains a CodeReview wiki page. +Feel free to contribute to this page as you learn the review process.

-
-$ git mail
-
-

-(In Git terms, git mail pushes the local committed -changes to Gerrit using git push origin -HEAD:refs/for/master.) -

+ +

Advanced topics

-If your change relates to an open issue, please add a comment to the issue -announcing your proposed fix, including a link to your change. +This section contains more in-depth topics on how to contribute to Go. Read it to +get a better understanding of the contribution process.

+ + +

-The code review server assigns your change an issue number and URL, -which git mail will print, something like: +Files in the Go repository don't list author names, both to avoid clutter +and to avoid having to keep the lists up to date. +Instead, your name will appear in the +change log and in the CONTRIBUTORS file and perhaps the AUTHORS file. +These files are automatically generated from the commit logs periodically. +The AUTHORS file defines who “The Go +Authors”—the copyright holders—are.

+

New files that you contribute should use the standard copyright header:

+
-remote: New Changes:
-remote:   https://go-review.googlesource.com/99999 math: improved Sin, Cos and Tan precision for very large arguments
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
 
-

Troubleshooting

+

+Files in the repository are copyright the year they are added. +Do not update the copyright year on files that you change. +

+ + + + +

Troubleshooting mail errors

-The most common way that the git mail command fails is because the -email address used has not gone through the setup above. +The most common way that the git codereview mail +command fails is because the email address in the commit does not match the one +that you used during the registration process. +
If you see something like...

@@ -631,12 +816,8 @@ remote: ERROR: does not match your user account.

-You need to either add the email address listed to the CLA or set this repo to use -another email address already approved. -

- -

-First let's change the email address for this repo so this doesn't happen again. +You need to set this repo to use the email address that you registered with. +First, let's change the email address for this repo so this doesn't happen again. You can change your email address for this repo with the following command:

@@ -645,7 +826,7 @@ $ git config user.email email@address.com

-Then change the previous commit to use this alternative email address. +Then change the commit to use this alternative email address. You can do that with:

@@ -658,8 +839,107 @@ Finally try to resend with:

-$ git mail
+$ git codereview mail
+
+ + +

Quickly testing your changes

+ +

Running all.bash for every single change to the code tree +is burdensome. Even though it is strongly suggested to run it before +sending a change, during the normal development cycle you may want +to quickly compile and locally test your change.

+ + + +

Contributing to subrepositories (golang.org/x/...)

+ +

+If you are contributing a change to a subrepository, obtain the +Go package using go get. For example, to contribute +to golang.org/x/oauth2, check out the code by running: +

+ +
+$ go get -d golang.org/x/oauth2/...
+
+ +

+Then, change your directory to the package's source directory +($GOPATH/src/golang.org/x/oauth2), and follow the +normal contribution flow. +

+ +

Specifying a reviewer / CCing others

@@ -679,55 +959,16 @@ Both accept a comma-separated list of email addresses:

-$ git mail -r joe@golang.org -cc mabel@example.com,math-nuts@swtch.com
+$ git codereview mail -r joe@golang.org -cc mabel@example.com,math-nuts@swtch.com
 
-

Going through the review process

-

-Running git mail will send an email to you and the -reviewers asking them to visit the issue's URL and make comments on the change. -When done, the reviewer adds comments through the Gerrit user interface -and clicks "Reply" to send comments back. -You will receive a mail notification when this happens. -You may reply through the web interface or -via email. -

-

Revise and resend

-

-The Go contribution workflow is optimized for iterative revisions based on -feedback. -It is rare that an initial contribution will be ready to be applied as is. -As you revise your contribution and resend Gerrit will retain a history of -all the changes and comments made in the single URL. -

-

-You may respond to review comments through the web interface or -via email. -

-

-When you have revised the code and are ready for another round of review, -stage those changes and use git change to update the -commit. -To send the updated change for another round of review, -run git mail again. -

-

-The reviewer can comment on the new copy, and the process repeats. -The reviewer approves the change by giving it a positive score -(+1 or +2) and replying LGTM: looks good to me. -

-

-You can see a list of your pending changes by running git -pending, and switch between change branches with git -change <branch>. -

Synchronize your client

@@ -745,153 +986,80 @@ $ git sync git pull -r.)

-

Resolving Conflicts

-

-If files you were editing have changed, Git does its best to merge the -remote changes into your local changes. -It may leave some files to merge by hand. -

-

-For example, suppose you have edited sin.go but -someone else has committed an independent change. -When you run git sync, -you will get the (scary-looking) output: -

-$ git sync
-Failed to merge in the changes.
-Patch failed at 0023 math: improved Sin, Cos and Tan precision for very large arguments
-The copy of the patch that failed is found in:
-   /home/you/repo/.git/rebase-apply/patch
 
-When you have resolved this problem, run "git rebase --continue".
-If you prefer to skip this patch, run "git rebase --skip" instead.
-To check out the original branch and stop rebasing, run "git rebase --abort".
-
+

Reviewing code by others

-If this happens, run +As part of the review process reviewers can propose changes directly (in the +GitHub workflow this would be someone else attaching commits to a pull request). + +You can import these changes proposed by someone else into your local Git repository. +On the Gerrit review page, click the "Download ▼" link in the upper right +corner, copy the "Checkout" command and run it from your local Git repo. It +should look something like this:

-$ git status
+$ git fetch https://go.googlesource.com/review refs/changes/21/1221/1 && git checkout FETCH_HEAD
 

-to see which files failed to merge. -The output will look something like this: +To revert, change back to the branch you were working in.

-
-rebase in progress; onto a24c3eb
-You are currently rebasing branch 'mcgillicutty' on 'a24c3eb'.
-  (fix conflicts and then run "git rebase --continue")
-  (use "git rebase --skip" to skip this patch)
-  (use "git rebase --abort" to check out the original branch)
-
-Unmerged paths:
-  (use "git reset HEAD <file>..." to unstage)
-  (use "git add <file>..." to mark resolution)
 
-	both modified: sin.go
-
+

Set up git aliases

-The only important part in that transcript is the italicized "both modified" -line: Git failed to merge your changes with the conflicting change. -When this happens, Git leaves both sets of edits in the file, -with conflicts marked by <<<<<<< and ->>>>>>>. -It is now your job to edit the file to combine them. -Continuing the example, searching for those strings in sin.go -might turn up: +The git-codereview command can be run directly from the shell +by typing, for instance,

-	arg = scale(arg)
-<<<<<<< HEAD
-	if arg < 1e9 {
-=======
-	if arg < 1e10 {
->>>>>>> mcgillicutty
-		largeReduce(arg)
+$ git codereview sync
 

-Git doesn't show it, but suppose the original text that both edits -started with was 1e8; you changed it to 1e10 and the other change to 1e9, -so the correct answer might now be 1e10. -First, edit the section to remove the markers and leave the correct code: +but it is more convenient to set up aliases for git-codereview's own +subcommands, so that the above becomes,

-	arg = scale(arg)
-	if arg < 1e10 {
-		largeReduce(arg)
+$ git sync
 

-Then tell Git that the conflict is resolved by running +The git-codereview subcommands have been chosen to be distinct from +Git's own, so it's safe to do so. To install them, copy this text into your +Git configuration file (usually .gitconfig in your home directory):

-$ git add sin.go
+[alias]
+	change = codereview change
+	gofmt = codereview gofmt
+	mail = codereview mail
+	pending = codereview pending
+	submit = codereview submit
+	sync = codereview sync
 
-

-If you had been editing the file, say for debugging, but do not -care to preserve your changes, you can run -git reset HEAD sin.go -to abandon your changes. -Then run git rebase --continue to -restore the change commit. -

-

Reviewing code by others

+

Sending multiple dependent changes

-

-As part of the review process reviewers can propose changes directly (in the -GitHub workflow this would be someone else attaching commits to a pull request). +

Gerrit allows for changes to be dependent on each other, forming a dependency chain. +This is an indication for maintainers to better review your code, even though each +change will technically need to be approved and submitted separately.

-You can import these changes proposed by someone else into your local Git repository. -On the Gerrit review page, click the "Download ▼" link in the upper right -corner, copy the "Checkout" command and run it from your local Git repo. It -should look something like this: -

+

To submit a group of dependent changes, keep each change as a different commit under +the same branch, and then run:

-$ git fetch https://go.googlesource.com/review refs/changes/21/1221/1 && git checkout FETCH_HEAD
+$ git codereview mail HEAD
 
-

-To revert, change back to the branch you were working in. -

- -

Apply the change to the master branch

- -

-After the code has been LGTM'ed, an approver may -apply it to the master branch using the Gerrit UI. -There is a "Submit" button on the web page for the change -that appears once the change is approved (marked +2). -

- -

-This checks the change into the repository. -The change description will include a link to the code review, -and the code review will be updated with a link to the change -in the repository. -Since the method used to integrate the changes is "Cherry Pick", -the commit hashes in the repository will be changed by -the "Submit" operation. -

- -

More information

- -

-In addition to the information here, the Go community maintains a CodeReview wiki page. -Feel free to contribute to this page as you learn the review process. -

+Make sure to explicitly specify HEAD, which is usually not required when sending +single changes.