Andrew Gerrand | 7cb21a7 | 2012-01-19 11:24:54 +1100 | [diff] [blame] | 1 | <!--{ |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 2 | "Title": "Contribution Guide" |
Andrew Gerrand | 7cb21a7 | 2012-01-19 11:24:54 +1100 | [diff] [blame] | 3 | }--> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 4 | |
Rob Pike | 5b72f9c | 2009-11-01 20:48:21 -0800 | [diff] [blame] | 5 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 6 | The Go project welcomes all contributors. The process of contributing |
| 7 | to the Go project may be different than many projects you are used to. |
| 8 | This document is intended as a guide to help you through the contribution |
| 9 | process. This guide assumes you have a basic understanding of Git and Go. |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 10 | </p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 11 | |
| 12 | <p> |
Russ Cox | d55abfd | 2009-12-09 14:05:12 -0800 | [diff] [blame] | 13 | (Note that the <code>gccgo</code> frontend lives elsewhere; |
Ian Lance Taylor | 2528f33 | 2009-11-06 14:15:41 -0800 | [diff] [blame] | 14 | see <a href="gccgo_contribute.html">Contributing to gccgo</a>.) |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 15 | </p> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 16 | |
Francesc Campoy | ba966f5 | 2016-04-22 16:27:34 -0700 | [diff] [blame] | 17 | <p> |
| 18 | Sensitive security-related issues should be reported to <a href="mailto:security@golang.org">security@golang.org</a>. |
| 19 | </p> |
| 20 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 21 | <h1 id="contributor">Becoming a contributor</h1> |
Rob Pike | 96ee38b | 2009-12-17 12:12:47 +1100 | [diff] [blame] | 22 | |
| 23 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 24 | Before you can contribute to the Go project you need to setup a few prerequisites. |
| 25 | The Go project uses <a href="https://www.gerritcodereview.com/">Gerrit</a>, an open |
| 26 | source online tool, to perform all code reviews. |
| 27 | Gerrit uses your email address as a unique identifier. |
| 28 | The Go project contributing flow is currently configured to work only with Google Accounts. |
| 29 | You must go through the following process <em>prior to contributing</em>. |
| 30 | You only need to do this once per Google Account. |
| 31 | </p> |
| 32 | |
Mohit Agarwal | d529aa9 | 2018-01-30 00:14:54 +0530 | [diff] [blame] | 33 | <h2 id="go-contrib-init">Automatically set up & diagnose your development environment</h2> |
Brad Fitzpatrick | 491ec4d | 2017-06-13 22:50:35 +0000 | [diff] [blame] | 34 | <p> |
| 35 | The <code>go-contrib-init</code> tool configures and debugs your Go |
| 36 | development environment, automatically performing many of the steps |
| 37 | on this page, or telling you what you need to do next. If you wish |
| 38 | to use it, run: |
| 39 | </p> |
| 40 | |
| 41 | <pre> |
| 42 | $ go get -u golang.org/x/tools/cmd/go-contrib-init |
| 43 | $ cd /code/to/edit |
| 44 | $ go-contrib-init |
| 45 | </pre> |
| 46 | |
| 47 | <p> |
| 48 | The tool will either set things up, tell you that everything is |
| 49 | configured, or tell you what steps you need to do manually. |
| 50 | </p> |
| 51 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 52 | <h2 id="auth">Configure Git to use Gerrit</h2> |
| 53 | <p> |
| 54 | You'll need a web browser and a command line terminal. |
| 55 | You should already have Git installed. |
Rob Pike | 96ee38b | 2009-12-17 12:12:47 +1100 | [diff] [blame] | 56 | </p> |
| 57 | |
| 58 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 59 | Gerrit uses Google Accounts for authentication. |
| 60 | If you don't have a Google Account, you can create an account which |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 61 | <a href="https://www.google.com/accounts/NewAccount">includes |
| 62 | a new Gmail email account</a> or create an account associated |
| 63 | <a href="https://accounts.google.com/SignUpWithoutGmail">with your existing |
| 64 | email address</a>. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 65 | </p> |
| 66 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 67 | <h3>Step 1: Sign in to googlesource and generate a password</h3> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 68 | |
| 69 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 70 | Visit <a href="https://go.googlesource.com">go.googlesource.com</a> |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 71 | and click on "Generate Password" in the page's top right menu bar. |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 72 | You will be redirected to accounts.google.com to sign in. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 73 | </p> |
| 74 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 75 | <h3>Step 2: Run the provided script</h3> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 76 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 77 | After signing in, you are taken to a page on go.googlesource.com with the title "Configure Git". |
| 78 | This page contains a personalized script which when run locally will configure git |
| 79 | to have your unique authentication key. |
| 80 | This key is paired with one generated server side similar to how ssh keys work. |
| 81 | </p> |
| 82 | |
| 83 | <p> |
| 84 | Copy and run this script locally in your command line terminal. |
| 85 | (On a Windows computer using cmd you should instead follow the instructions |
| 86 | in the yellow box to run the command. If you are using git-bash use the same |
| 87 | script as *nix.) |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 88 | </p> |
| 89 | |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 90 | <p> |
RaviTeja | 4e0738a | 2017-08-09 17:23:47 +0530 | [diff] [blame] | 91 | Your secret authentication token is now in a <code>.gitcookies</code> file |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 92 | and Git is configured to use this file. |
| 93 | </p> |
| 94 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 95 | <h3 id="gerrit">Step 3: Register with Gerrit</h3> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 96 | |
| 97 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 98 | Now that you have your authentication token, you need to register your |
| 99 | account with Gerrit. |
| 100 | To do this, visit <a href="https://go-review.googlesource.com/login/"> |
| 101 | go-review.googlesource.com/login/</a>. |
| 102 | Sign in using the same Google Account you used above. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 103 | </p> |
| 104 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 105 | <h2 id="cla">Contributor License Agreement</h2> |
Andy Maloney | c53de85 | 2015-08-03 10:15:52 -0400 | [diff] [blame] | 106 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 107 | <h3 id="which_cla">Which CLA</h3> |
| 108 | <p> |
| 109 | Before sending your first change to the Go project |
| 110 | you must have completed one of the following two CLAs. |
| 111 | Which CLA you should sign depends on who owns the copyright to your work. |
| 112 | </p> |
| 113 | |
Andy Maloney | c53de85 | 2015-08-03 10:15:52 -0400 | [diff] [blame] | 114 | <ul> |
| 115 | <li> |
| 116 | If you are the copyright holder, you will need to agree to the |
| 117 | <a href="https://developers.google.com/open-source/cla/individual">individual |
| 118 | contributor license agreement</a>, which can be completed online. |
| 119 | </li> |
| 120 | <li> |
| 121 | If your organization is the copyright holder, the organization |
| 122 | will need to agree to the |
| 123 | <a href="https://developers.google.com/open-source/cla/corporate">corporate |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 124 | contributor license agreement</a>.<br> |
Andy Maloney | c53de85 | 2015-08-03 10:15:52 -0400 | [diff] [blame] | 125 | </li> |
| 126 | </ul> |
| 127 | |
| 128 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 129 | <i>If the copyright holder for your contribution has already completed the |
| 130 | agreement in connection with another Google open source project, |
| 131 | it does not need to be completed again.</i> |
| 132 | </p> |
| 133 | |
| 134 | <h3 id="signing_cla">Completing the CLA</h3> |
| 135 | |
| 136 | <p> |
| 137 | You can see your currently signed agreements and sign new ones through the Gerrit |
| 138 | interface. |
| 139 | To do this, <a href="https://go-review.googlesource.com/login/">Log into Gerrit</a>, |
Alberto Donizetti | 9f6fde3 | 2017-05-02 12:38:59 +0200 | [diff] [blame] | 140 | then visit the <a href="https://go-review.googlesource.com/settings/agreements">Agreements</a> |
| 141 | page. |
| 142 | If you do not have a signed agreement listed there, you can create one |
| 143 | by clicking "New Contributor Agreement" and following the steps. |
Andy Maloney | c53de85 | 2015-08-03 10:15:52 -0400 | [diff] [blame] | 144 | </p> |
| 145 | |
| 146 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 147 | If the copyright holder for the code you are submitting changes — for example, |
| 148 | if you start contributing code on behalf of a new company — please send email |
| 149 | to golang-dev and let us know, so that we can make sure an appropriate agreement is |
| 150 | completed and update the <code>AUTHORS</code> file. |
Andy Maloney | c53de85 | 2015-08-03 10:15:52 -0400 | [diff] [blame] | 151 | </p> |
| 152 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 153 | <span id="Code_review"></span> |
| 154 | <h1 id="prepare_dev_env">Preparing a Development Environment for Contributing</h1> |
| 155 | |
| 156 | <h2 id="git-codereview">Setting up Git for submission to Gerrit</h2> |
Russ Cox | 19e27c7 | 2016-01-06 15:23:47 -0500 | [diff] [blame] | 157 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 158 | Changes to Go must be reviewed before they are accepted, no matter who makes the change. |
| 159 | A custom git command called <code>git-codereview</code>, discussed below, |
| 160 | helps manage the code review process through a Google-hosted |
Christian Alexander | 1b53f12 | 2017-08-09 08:11:34 -0700 | [diff] [blame] | 161 | <a href="https://go-review.googlesource.com/">instance</a> of Gerrit. |
Russ Cox | 19e27c7 | 2016-01-06 15:23:47 -0500 | [diff] [blame] | 162 | </p> |
| 163 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 164 | <h3 id="git-codereview_install">Install the git-codereview command</h3> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 165 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 166 | Install the <code>git-codereview</code> command by running, |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 167 | </p> |
| 168 | |
| 169 | <pre> |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 170 | $ go get -u golang.org/x/review/git-codereview |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 171 | </pre> |
| 172 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 173 | <p> |
Andrew Gerrand | 722f7d2 | 2014-12-18 11:42:25 +1100 | [diff] [blame] | 174 | Make sure <code>git-codereview</code> is installed in your shell path, so that the |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 175 | <code>git</code> command can find it. Check that |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 176 | </p> |
| 177 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 178 | <pre> |
Andrew Gerrand | 0293b7e | 2014-12-18 12:55:22 +1100 | [diff] [blame] | 179 | $ git codereview help |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 180 | </pre> |
Andrew Gerrand | 722f7d2 | 2014-12-18 11:42:25 +1100 | [diff] [blame] | 181 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 182 | <p> |
| 183 | prints help text, not an error. |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 184 | </p> |
| 185 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 186 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 187 | On Windows, when using git-bash you must make sure that |
| 188 | <code>git-codereview.exe</code> is in your git exec-path. |
| 189 | Run <code>git --exec-path</code> to discover the right location then create a |
Alberto Donizetti | 2873605 | 2017-12-06 10:59:40 +0100 | [diff] [blame] | 190 | symbolic link or simply copy the executable from $GOPATH/bin to this directory. |
Russ Cox | f997475 | 2016-02-17 10:46:30 -0500 | [diff] [blame] | 191 | </p> |
| 192 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 193 | <p> |
| 194 | <b>Note to Git aficionados:</b> |
| 195 | The <code>git-codereview</code> command is not required to |
| 196 | upload and manage Gerrit code reviews. |
| 197 | For those who prefer plain Git, the text below gives the Git equivalent of |
| 198 | each git-codereview command. |
| 199 | </p> |
| 200 | |
| 201 | <p> |
| 202 | If you do use plain Git, note that you still need the commit hooks that the |
| 203 | git-codereview command configures; those hooks add a Gerrit |
| 204 | <code>Change-Id</code> line to the commit message and check that all Go source |
| 205 | files have been formatted with gofmt. |
| 206 | Even if you intend to use plain Git for |
| 207 | daily work, install the hooks in a new Git checkout by running |
| 208 | <code>git-codereview</code> <code>hooks</code>. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 209 | </p> |
| 210 | |
Russ Cox | 19e27c7 | 2016-01-06 15:23:47 -0500 | [diff] [blame] | 211 | <h3 id="git-config">Set up git aliases</h3> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 212 | |
| 213 | <p> |
Andrew Gerrand | 722f7d2 | 2014-12-18 11:42:25 +1100 | [diff] [blame] | 214 | The <code>git-codereview</code> command can be run directly from the shell |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 215 | by typing, for instance, |
| 216 | </p> |
| 217 | |
| 218 | <pre> |
Andrew Gerrand | 0293b7e | 2014-12-18 12:55:22 +1100 | [diff] [blame] | 219 | $ git codereview sync |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 220 | </pre> |
| 221 | |
| 222 | <p> |
Andrew Gerrand | 722f7d2 | 2014-12-18 11:42:25 +1100 | [diff] [blame] | 223 | but it is more convenient to set up aliases for <code>git-codereview</code>'s own |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 224 | subcommands, so that the above becomes, |
| 225 | </p> |
| 226 | |
| 227 | <pre> |
| 228 | $ git sync |
| 229 | </pre> |
| 230 | |
Andrew Gerrand | 722f7d2 | 2014-12-18 11:42:25 +1100 | [diff] [blame] | 231 | <p> |
| 232 | The <code>git-codereview</code> subcommands have been chosen to be distinct from |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 233 | Git's own, so it's safe to do so. |
| 234 | </p> |
| 235 | |
| 236 | <p> |
| 237 | The aliases are optional, but in the rest of this document we will assume |
| 238 | they are installed. |
| 239 | To install them, copy this text into your Git configuration file |
| 240 | (usually <code>.gitconfig</code> in your home directory): |
| 241 | </p> |
| 242 | |
| 243 | <pre> |
| 244 | [alias] |
Andrew Gerrand | 722f7d2 | 2014-12-18 11:42:25 +1100 | [diff] [blame] | 245 | change = codereview change |
| 246 | gofmt = codereview gofmt |
| 247 | mail = codereview mail |
| 248 | pending = codereview pending |
| 249 | submit = codereview submit |
| 250 | sync = codereview sync |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 251 | </pre> |
| 252 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 253 | <span id="help"></span> |
| 254 | <h3 id="understanding_git-codereview">Understanding the git-codereview command</h3> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 255 | |
Andrew Gerrand | 722f7d2 | 2014-12-18 11:42:25 +1100 | [diff] [blame] | 256 | <p>After installing the <code>git-codereview</code> command, you can run</p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 257 | |
| 258 | <pre> |
Andrew Gerrand | 0293b7e | 2014-12-18 12:55:22 +1100 | [diff] [blame] | 259 | $ git codereview help |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 260 | </pre> |
| 261 | |
| 262 | <p> |
| 263 | to learn more about its commands. |
Andrew Gerrand | 722f7d2 | 2014-12-18 11:42:25 +1100 | [diff] [blame] | 264 | You can also read the <a href="https://godoc.org/golang.org/x/review/git-codereview">command documentation</a>. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 265 | </p> |
| 266 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 267 | |
| 268 | <h1 id="making_a_contribution">Making a Contribution</h1> |
| 269 | |
| 270 | <h2 id="Design">Discuss your design</h2> |
| 271 | |
| 272 | <p> |
| 273 | The project welcomes submissions but please let everyone know what |
| 274 | you're working on if you want to change or add to the Go repositories. |
| 275 | </p> |
| 276 | |
| 277 | <p> |
| 278 | Before undertaking to write something new for the Go project, |
| 279 | please <a href="https://golang.org/issue/new">file an issue</a> |
| 280 | (or claim an <a href="https://golang.org/issues">existing issue</a>). |
| 281 | Significant changes must go through the |
| 282 | <a href="https://golang.org/s/proposal-process">change proposal process</a> |
| 283 | before they can be accepted. |
| 284 | </p> |
| 285 | |
| 286 | <p> |
| 287 | This process gives everyone a chance to validate the design, |
| 288 | helps prevent duplication of effort, |
| 289 | and ensures that the idea fits inside the goals for the language and tools. |
| 290 | It also checks that the design is sound before code is written; |
| 291 | the code review tool is not the place for high-level discussions. |
| 292 | </p> |
| 293 | |
| 294 | <p> |
| 295 | When planning work, please note that the Go project follows a <a |
| 296 | href="https://golang.org/wiki/Go-Release-Cycle">six-month development cycle</a>. |
| 297 | The latter half of each cycle is a three-month feature freeze during |
| 298 | which only bug fixes and doc updates are accepted. New contributions can be |
| 299 | sent during a feature freeze but will not be accepted until the freeze thaws. |
| 300 | </p> |
| 301 | |
Kevin Burke | 1722a2d | 2017-07-19 07:21:30 -0700 | [diff] [blame] | 302 | <h3 id="scratch">Not sure what change to make?</h3> |
| 303 | |
| 304 | <p> |
| 305 | If you want to become familiar with Gerrit and the contribution process, |
| 306 | but aren't sure what you'd like to contribute just yet, you can use the <a |
| 307 | href="https://go.googlesource.com/scratch">scratch repository</a> to practice |
| 308 | making a change. |
| 309 | </p> |
| 310 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 311 | <h2 id="making_a_change">Making a change</h2> |
| 312 | |
| 313 | <h3 id="checkout_go">Getting Go Source</h3> |
| 314 | <p> |
| 315 | First you need to have a local copy of the source checked out from the correct |
| 316 | repository. |
| 317 | As Go builds Go you will also likely need to have a working version |
| 318 | of Go installed (some documentation changes may not need this). |
| 319 | This should be a recent version of Go and can be obtained via any package or |
| 320 | binary distribution or you can build it from source. |
| 321 | </p> |
| 322 | |
| 323 | <p> |
| 324 | You should checkout the Go source repo anywhere you want as long as it's |
| 325 | outside of your $GOPATH. |
| 326 | Go to a directory where you want the source to appear and run the following |
| 327 | command in a terminal. |
| 328 | </p> |
| 329 | |
Adam Bender | 9dd7059 | 2017-05-03 18:57:40 -0700 | [diff] [blame] | 330 | <pre> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 331 | $ git clone https://go.googlesource.com/go |
| 332 | $ cd go |
Adam Bender | 9dd7059 | 2017-05-03 18:57:40 -0700 | [diff] [blame] | 333 | </pre> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 334 | |
| 335 | <h3 id="master">Contributing to the main Go tree</h3> |
Andrew Gerrand | 3238705 | 2012-06-05 00:55:45 +1000 | [diff] [blame] | 336 | |
| 337 | <p> |
| 338 | Most Go installations use a release branch, but new changes should |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 339 | only be made based on the master branch. <br> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 340 | (They may be applied later to a release branch as part of the release process, |
| 341 | but most contributors won't do this themselves.) |
| 342 | Before making a change, make sure you start on the master branch: |
Andrew Gerrand | 3238705 | 2012-06-05 00:55:45 +1000 | [diff] [blame] | 343 | </p> |
| 344 | |
| 345 | <pre> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 346 | $ git checkout master |
| 347 | $ git sync |
Andrew Gerrand | 3238705 | 2012-06-05 00:55:45 +1000 | [diff] [blame] | 348 | </pre> |
| 349 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 350 | <p> |
| 351 | (In Git terms, <code>git</code> <code>sync</code> runs |
| 352 | <code>git</code> <code>pull</code> <code>-r</code>.) |
| 353 | </p> |
| 354 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 355 | <h3 id="subrepos">Contributing to subrepositories (golang.org/x/...)</h3> |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 356 | |
| 357 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 358 | If you are contributing a change to a subrepository, obtain the |
| 359 | Go package using <code>go get</code>. For example, to contribute |
| 360 | to <code>golang.org/x/oauth2</code>, check out the code by running: |
| 361 | </p> |
| 362 | |
| 363 | <pre> |
| 364 | $ go get -d golang.org/x/oauth2/... |
| 365 | </pre> |
| 366 | |
| 367 | <p> |
| 368 | Then, change your directory to the package's source directory |
| 369 | (<code>$GOPATH/src/golang.org/x/oauth2</code>). |
| 370 | </p> |
| 371 | |
| 372 | <h3 id="change">Make your changes</h3> |
| 373 | |
| 374 | <p> |
| 375 | The entire checked-out tree is editable. |
| 376 | Make your changes as you see fit ensuring that you create appropriate |
| 377 | tests along with your changes. Test your changes as you go. |
| 378 | </p> |
| 379 | |
| 380 | <h3 id="copyright">Copyright</h3> |
| 381 | |
| 382 | <p> |
| 383 | Files in the Go repository don't list author names, both to avoid clutter |
| 384 | and to avoid having to keep the lists up to date. |
| 385 | Instead, your name will appear in the |
| 386 | <a href="https://golang.org/change">change log</a> and in the <a |
| 387 | href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file and perhaps the <a |
| 388 | href="/AUTHORS"><code>AUTHORS</code></a> file. |
Alberto Donizetti | 2873605 | 2017-12-06 10:59:40 +0100 | [diff] [blame] | 389 | These files are automatically generated from the commit logs periodically. |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 390 | The <a href="/AUTHORS"><code>AUTHORS</code></a> file defines who “The Go |
| 391 | Authors”—the copyright holders—are. |
| 392 | </p> |
| 393 | |
| 394 | <p>New files that you contribute should use the standard copyright header:</p> |
| 395 | |
| 396 | <pre> |
Brad Fitzpatrick | cd97aca | 2018-01-01 02:04:51 +0000 | [diff] [blame] | 397 | // Copyright 2018 The Go Authors. All rights reserved. |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 398 | // Use of this source code is governed by a BSD-style |
| 399 | // license that can be found in the LICENSE file. |
| 400 | </pre> |
| 401 | |
| 402 | <p> |
| 403 | Files in the repository are copyright the year they are added. |
| 404 | Do not update the copyright year on files that you change. |
| 405 | </p> |
| 406 | |
| 407 | <h3 id="commit_changes">Commit your changes</h3> |
| 408 | |
| 409 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 410 | Once you have edited files, you must tell Git that they have been modified. |
| 411 | You must also tell Git about any files that are added, removed, or renamed files. |
| 412 | These operations are done with the usual Git commands, |
| 413 | <code>git</code> <code>add</code>, |
| 414 | <code>git</code> <code>rm</code>, |
| 415 | and |
| 416 | <code>git</code> <code>mv</code>. |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 417 | </p> |
| 418 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 419 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 420 | Once you have the changes queued up, you will want to commit them. |
Adam Bender | 9dd7059 | 2017-05-03 18:57:40 -0700 | [diff] [blame] | 421 | In the Go contribution workflow this is done with a <code>git</code> |
| 422 | <code>change</code> command, which creates a local branch and commits the changes |
| 423 | directly to that local branch. |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 424 | </p> |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 425 | |
Leigh McCulloch | 07a2ffa | 2017-11-04 20:54:30 +0000 | [diff] [blame] | 426 | <p> |
| 427 | The workflow described here assumes a single change per branch. |
| 428 | It is also possible to prepare a sequence of (usually related) changes in a single branch. |
| 429 | See the <a href="https://golang.org/x/review/git-codereview">git-codereview documentation</a> for details. |
| 430 | </p> |
| 431 | |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 432 | <pre> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 433 | $ git change <i><branch></i> |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 434 | </pre> |
| 435 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 436 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 437 | The name <i><branch></i> is an arbitrary one you choose to identify the |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 438 | local branch containing your changes and will not be used elsewhere. |
| 439 | This is an offline operation and nothing will be sent to the server yet. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 440 | </p> |
| 441 | |
| 442 | <p> |
| 443 | (In Git terms, <code>git</code> <code>change</code> <code><branch></code> |
| 444 | runs <code>git</code> <code>checkout</code> <code>-b</code> <code>branch</code>, |
| 445 | then <code>git</code> <code>branch</code> <code>--set-upstream-to</code> <code>origin/master</code>, |
| 446 | then <code>git</code> <code>commit</code>.) |
| 447 | </p> |
| 448 | |
| 449 | <p> |
Adam Bender | 9dd7059 | 2017-05-03 18:57:40 -0700 | [diff] [blame] | 450 | As the <code>git</code> <code>commit</code> is the final step, Git will open an |
| 451 | editor to ask for a commit message. (It uses the editor named by |
| 452 | the <code>$EDITOR</code> environment variable, |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 453 | <code>vi</code> by default.) |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 454 | |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 455 | The file will look like: |
| 456 | </p> |
| 457 | |
| 458 | <pre> |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 459 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 460 | # Please enter the commit message for your changes. Lines starting |
| 461 | # with '#' will be ignored, and an empty message aborts the commit. |
| 462 | # On branch foo |
| 463 | # Changes not staged for commit: |
| 464 | # modified: editedfile.go |
| 465 | # |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 466 | </pre> |
| 467 | |
| 468 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 469 | At the beginning of this file is a blank line; replace it |
| 470 | with a thorough description of your change. |
Nigel Tao | 3f38342 | 2011-01-05 13:00:08 +1100 | [diff] [blame] | 471 | The first line of the change description is conventionally a one-line |
| 472 | summary of the change, prefixed by the primary affected package, |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 473 | and is used as the subject for code review email. |
Jeff R. Allen | 7b6b5e3 | 2016-05-25 00:12:22 +0600 | [diff] [blame] | 474 | It should complete the sentence "This change modifies Go to _____." |
| 475 | The rest of the description elaborates and should provide context for the |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 476 | change and explain what it does. |
Jeff R. Allen | 7b6b5e3 | 2016-05-25 00:12:22 +0600 | [diff] [blame] | 477 | Write in complete sentences with correct punctuation, just like |
| 478 | for your comments in Go. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 479 | If there is a helpful reference, mention it here. |
Jeff R. Allen | 7b6b5e3 | 2016-05-25 00:12:22 +0600 | [diff] [blame] | 480 | If you've fixed an issue, reference it by number with a # before it. |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 481 | </p> |
| 482 | |
| 483 | <p> |
| 484 | After editing, the template might now read: |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 485 | </p> |
| 486 | |
| 487 | <pre> |
Jeff R. Allen | 7b6b5e3 | 2016-05-25 00:12:22 +0600 | [diff] [blame] | 488 | math: improve Sin, Cos and Tan precision for very large arguments |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 489 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 490 | The existing implementation has poor numerical properties for |
| 491 | large arguments, so use the McGillicutty algorithm to improve |
| 492 | accuracy above 1e10. |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 493 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 494 | The algorithm is described at http://wikipedia.org/wiki/McGillicutty_Algorithm |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 495 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 496 | Fixes #159 |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 497 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 498 | # Please enter the commit message for your changes. Lines starting |
| 499 | # with '#' will be ignored, and an empty message aborts the commit. |
| 500 | # On branch foo |
| 501 | # Changes not staged for commit: |
| 502 | # modified: editedfile.go |
| 503 | # |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 504 | </pre> |
| 505 | |
| 506 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 507 | The commented section of the file lists all the modified files in your client. |
Han-Wen Nienhuys | d5da104 | 2017-07-14 15:38:49 -0600 | [diff] [blame] | 508 | It is best to keep unrelated changes in different commits, |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 509 | so if you see a file listed that should not be included, abort |
| 510 | the command and move that file to a different branch. |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 511 | </p> |
| 512 | |
| 513 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 514 | The special notation "Fixes #159" associates the change with issue 159 in the |
| 515 | <a href="https://golang.org/issue/159">Go issue tracker</a>. |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 516 | When this change is eventually applied, the issue |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 517 | tracker will automatically mark the issue as fixed. |
| 518 | (There are several such conventions, described in detail in the |
| 519 | <a href="https://help.github.com/articles/closing-issues-via-commit-messages/">GitHub Issue Tracker documentation</a>.) |
| 520 | </p> |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 521 | |
| 522 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 523 | Once you have finished writing the commit message, |
| 524 | save the file and exit the editor. |
| 525 | </p> |
| 526 | |
| 527 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 528 | You must have the $EDITOR environment variable set properly and working properly (exiting cleanly) |
| 529 | for this operation to succeed. |
| 530 | If you run into any issues at this step, it's likely your editor isn't exiting cleanly. |
| 531 | Try setting a different editor in your $EDITOR environment variable. |
| 532 | </p> |
| 533 | |
| 534 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 535 | If you wish to do more editing, re-stage your changes using |
| 536 | <code>git</code> <code>add</code>, and then run |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 537 | </p> |
| 538 | |
| 539 | <pre> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 540 | $ git change |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 541 | </pre> |
| 542 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 543 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 544 | to update the change description and incorporate the staged changes. |
| 545 | The change description contains a <code>Change-Id</code> line near the bottom, |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 546 | added by a Git commit hook during the initial |
| 547 | <code>git</code> <code>change</code>. |
| 548 | That line is used by Gerrit to match successive uploads of the same change. |
| 549 | Do not edit or delete it. |
| 550 | </p> |
| 551 | |
| 552 | <p> |
| 553 | (In Git terms, <code>git</code> <code>change</code> with no branch name |
| 554 | runs <code>git</code> <code>commit</code> <code>--amend</code>.) |
Andrew Gerrand | 722f7d2 | 2014-12-18 11:42:25 +1100 | [diff] [blame] | 555 | </p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 556 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 557 | <h3 id="Testing">Testing</h3> |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 558 | |
| 559 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 560 | You've <a href="code.html">written and tested your code</a>, but |
| 561 | before sending code out for review, run all the tests for the whole |
| 562 | tree to make sure the changes don't break other packages or programs: |
| 563 | </p> |
| 564 | |
| 565 | <pre> |
| 566 | $ cd go/src |
| 567 | $ ./all.bash |
| 568 | </pre> |
| 569 | |
| 570 | <p> |
| 571 | (To build under Windows use <code>all.bat</code>.) |
| 572 | </p> |
| 573 | |
| 574 | <p> |
| 575 | After running for a while, the command should print |
| 576 | </p> |
| 577 | |
| 578 | <pre> |
| 579 | "ALL TESTS PASSED". |
| 580 | </pre> |
| 581 | |
| 582 | <h3 id="mail">Send the change for review</h3> |
| 583 | |
| 584 | <p> |
| 585 | Once the change is ready, send it for review. |
| 586 | This is similar to a <code>git push</code> in a GitHub style workflow. |
| 587 | This is done via the mail alias setup earlier which despite its name, doesn't |
| 588 | directly mail anything, it simply sends the change to Gerrit via git push. |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 589 | </p> |
| 590 | |
| 591 | <pre> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 592 | $ git mail |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 593 | </pre> |
| 594 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 595 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 596 | (In Git terms, <code>git</code> <code>mail</code> pushes the local committed |
| 597 | changes to Gerrit using <code>git</code> <code>push</code> <code>origin</code> |
| 598 | <code>HEAD:refs/for/master</code>.) |
| 599 | </p> |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 600 | |
| 601 | <p> |
| 602 | If your change relates to an open issue, please add a comment to the issue |
Jaana Burcu Dogan | e2390ec | 2017-02-08 11:17:47 -0800 | [diff] [blame] | 603 | announcing your proposed fix, including a link to your change. |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 604 | </p> |
| 605 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 606 | <p> |
| 607 | The code review server assigns your change an issue number and URL, |
| 608 | which <code>git</code> <code>mail</code> will print, something like: |
| 609 | </p> |
| 610 | |
| 611 | <pre> |
| 612 | remote: New Changes: |
| 613 | remote: https://go-review.googlesource.com/99999 math: improved Sin, Cos and Tan precision for very large arguments |
| 614 | </pre> |
| 615 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 616 | <h3>Troubleshooting</h3> |
| 617 | |
| 618 | <p> |
| 619 | The most common way that the <code>git mail</code> command fails is because the |
| 620 | email address used has not gone through the setup above. |
| 621 | <br> |
| 622 | If you see something like... |
| 623 | </p> |
| 624 | |
| 625 | <pre> |
| 626 | remote: Processing changes: refs: 1, done |
| 627 | remote: |
| 628 | remote: ERROR: In commit ab13517fa29487dcf8b0d48916c51639426c5ee9 |
| 629 | remote: ERROR: author email address XXXXXXXXXXXXXXXXXXX |
| 630 | remote: ERROR: does not match your user account. |
| 631 | </pre> |
| 632 | |
| 633 | <p> |
| 634 | You need to either add the email address listed to the CLA or set this repo to use |
| 635 | another email address already approved. |
| 636 | </p> |
| 637 | |
| 638 | <p> |
| 639 | First let's change the email address for this repo so this doesn't happen again. |
| 640 | You can change your email address for this repo with the following command: |
| 641 | </p> |
| 642 | |
| 643 | <pre> |
| 644 | $ git config user.email email@address.com |
| 645 | </pre> |
| 646 | |
| 647 | <p> |
| 648 | Then change the previous commit to use this alternative email address. |
| 649 | You can do that with: |
| 650 | </p> |
| 651 | |
| 652 | <pre> |
| 653 | $ git commit --amend --author="Author Name <email@address.com>" |
| 654 | </pre> |
| 655 | |
| 656 | <p> |
| 657 | Finally try to resend with: |
| 658 | </p> |
| 659 | |
| 660 | <pre> |
| 661 | $ git mail |
| 662 | </pre> |
| 663 | |
| 664 | <h3 id="cc">Specifying a reviewer / CCing others</h3> |
| 665 | |
| 666 | <p> |
| 667 | Unless explicitly told otherwise, such as in the discussion leading |
Han-Wen Nienhuys | d5da104 | 2017-07-14 15:38:49 -0600 | [diff] [blame] | 668 | up to sending in the change, it's better not to specify a reviewer. |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 669 | All changes are automatically CC'ed to the |
| 670 | <a href="https://groups.google.com/group/golang-codereviews">golang-codereviews@googlegroups.com</a> |
| 671 | mailing list. If this is your first ever change, there may be a moderation |
| 672 | delay before it appears on the mailing list, to prevent spam. |
| 673 | </p> |
| 674 | |
| 675 | <p> |
| 676 | You can specify a reviewer or CC interested parties |
| 677 | using the <code>-r</code> or <code>-cc</code> options. |
| 678 | Both accept a comma-separated list of email addresses: |
| 679 | </p> |
| 680 | |
| 681 | <pre> |
| 682 | $ git mail -r joe@golang.org -cc mabel@example.com,math-nuts@swtch.com |
| 683 | </pre> |
| 684 | |
| 685 | <h2 id="review">Going through the review process</h2> |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 686 | |
| 687 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 688 | Running <code>git</code> <code>mail</code> will send an email to you and the |
| 689 | reviewers asking them to visit the issue's URL and make comments on the change. |
| 690 | When done, the reviewer adds comments through the Gerrit user interface |
| 691 | and clicks "Reply" to send comments back. |
| 692 | You will receive a mail notification when this happens. |
Andrew Bonventre | 2e405bd | 2017-10-04 00:02:37 -0400 | [diff] [blame] | 693 | You may reply through the web interface or |
| 694 | <a href="https://gerrit-review.googlesource.com/Documentation/intro-user.html#reply-by-email">via email</a>. |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 695 | </p> |
| 696 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 697 | <h3 id="revise">Revise and resend</h3> |
| 698 | |
| 699 | <p> |
| 700 | The Go contribution workflow is optimized for iterative revisions based on |
| 701 | feedback. |
| 702 | It is rare that an initial contribution will be ready to be applied as is. |
| 703 | As you revise your contribution and resend Gerrit will retain a history of |
| 704 | all the changes and comments made in the single URL. |
| 705 | </p> |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 706 | |
| 707 | <p> |
Andrew Bonventre | 2e405bd | 2017-10-04 00:02:37 -0400 | [diff] [blame] | 708 | You may respond to review comments through the web interface or |
| 709 | <a href="https://gerrit-review.googlesource.com/Documentation/intro-user.html#reply-by-email">via email</a>. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 710 | </p> |
| 711 | |
| 712 | <p> |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 713 | When you have revised the code and are ready for another round of review, |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 714 | stage those changes and use <code>git</code> <code>change</code> to update the |
| 715 | commit. |
Han-Wen Nienhuys | d5da104 | 2017-07-14 15:38:49 -0600 | [diff] [blame] | 716 | To send the updated change for another round of review, |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 717 | run <code>git</code> <code>mail</code> again. |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 718 | </p> |
| 719 | |
| 720 | <p> |
| 721 | The reviewer can comment on the new copy, and the process repeats. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 722 | The reviewer approves the change by giving it a positive score |
| 723 | (+1 or +2) and replying <code>LGTM</code>: looks good to me. |
Bill Thiede | 822b2cb | 2014-07-03 17:42:23 -0400 | [diff] [blame] | 724 | </p> |
| 725 | |
| 726 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 727 | You can see a list of your pending changes by running <code>git</code> |
| 728 | <code>pending</code>, and switch between change branches with <code>git</code> |
| 729 | <code>change</code> <code><i><branch></i></code>. |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 730 | </p> |
| 731 | |
Russ Cox | 19e27c7 | 2016-01-06 15:23:47 -0500 | [diff] [blame] | 732 | <h3 id="sync">Synchronize your client</h3> |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 733 | |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 734 | <p> |
| 735 | While you were working, others might have submitted changes to the repository. |
| 736 | To update your local branch, run |
| 737 | </p> |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 738 | |
| 739 | <pre> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 740 | $ git sync |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 741 | </pre> |
| 742 | |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 743 | <p> |
Oling Cat | ce36552 | 2014-12-14 14:32:56 +0800 | [diff] [blame] | 744 | (In git terms, <code>git</code> <code>sync</code> runs |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 745 | <code>git</code> <code>pull</code> <code>-r</code>.) |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 746 | </p> |
| 747 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 748 | <h3 id="resolving_conflicts">Resolving Conflicts</h3> |
| 749 | |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 750 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 751 | If files you were editing have changed, Git does its best to merge the |
| 752 | remote changes into your local changes. |
| 753 | It may leave some files to merge by hand. |
| 754 | </p> |
| 755 | |
| 756 | <p> |
| 757 | For example, suppose you have edited <code>sin.go</code> but |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 758 | someone else has committed an independent change. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 759 | When you run <code>git</code> <code>sync</code>, |
| 760 | you will get the (scary-looking) output: |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 761 | |
| 762 | <pre> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 763 | $ git sync |
| 764 | Failed to merge in the changes. |
| 765 | Patch failed at 0023 math: improved Sin, Cos and Tan precision for very large arguments |
| 766 | The copy of the patch that failed is found in: |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 767 | /home/you/repo/.git/rebase-apply/patch |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 768 | |
| 769 | When you have resolved this problem, run "git rebase --continue". |
| 770 | If you prefer to skip this patch, run "git rebase --skip" instead. |
| 771 | To check out the original branch and stop rebasing, run "git rebase --abort". |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 772 | </pre> |
| 773 | |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 774 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 775 | If this happens, run |
| 776 | </p> |
| 777 | |
| 778 | <pre> |
| 779 | $ git status |
| 780 | </pre> |
| 781 | |
| 782 | <p> |
| 783 | to see which files failed to merge. |
| 784 | The output will look something like this: |
| 785 | </p> |
| 786 | |
| 787 | <pre> |
| 788 | rebase in progress; onto a24c3eb |
| 789 | You are currently rebasing branch 'mcgillicutty' on 'a24c3eb'. |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 790 | (fix conflicts and then run "git rebase --continue") |
| 791 | (use "git rebase --skip" to skip this patch) |
| 792 | (use "git rebase --abort" to check out the original branch) |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 793 | |
| 794 | Unmerged paths: |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 795 | (use "git reset HEAD <file>..." to unstage) |
| 796 | (use "git add <file>..." to mark resolution) |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 797 | |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 798 | <i>both modified: sin.go</i> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 799 | </pre> |
| 800 | |
| 801 | <p> |
| 802 | The only important part in that transcript is the italicized "both modified" |
| 803 | line: Git failed to merge your changes with the conflicting change. |
| 804 | When this happens, Git leaves both sets of edits in the file, |
| 805 | with conflicts marked by <code><<<<<<<</code> and |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 806 | <code>>>>>>>></code>. |
Tetsuo Kiso | 48347cc | 2014-07-07 16:31:20 +1000 | [diff] [blame] | 807 | It is now your job to edit the file to combine them. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 808 | Continuing the example, searching for those strings in <code>sin.go</code> |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 809 | might turn up: |
| 810 | </p> |
| 811 | |
| 812 | <pre> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 813 | arg = scale(arg) |
| 814 | <<<<<<< HEAD |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 815 | if arg < 1e9 { |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 816 | ======= |
Katrina Owen | bc953b2 | 2015-10-05 21:15:23 -0600 | [diff] [blame] | 817 | if arg < 1e10 { |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 818 | >>>>>>> mcgillicutty |
| 819 | largeReduce(arg) |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 820 | </pre> |
| 821 | |
| 822 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 823 | Git doesn't show it, but suppose the original text that both edits |
| 824 | started with was 1e8; you changed it to 1e10 and the other change to 1e9, |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 825 | so the correct answer might now be 1e10. |
| 826 | First, edit the section to remove the markers and leave the correct code: |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 827 | </p> |
| 828 | |
| 829 | <pre> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 830 | arg = scale(arg) |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 831 | if arg < 1e10 { |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 832 | largeReduce(arg) |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 833 | </pre> |
| 834 | |
| 835 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 836 | Then tell Git that the conflict is resolved by running |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 837 | </p> |
| 838 | |
Russ Cox | d55abfd | 2009-12-09 14:05:12 -0800 | [diff] [blame] | 839 | <pre> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 840 | $ git add sin.go |
Russ Cox | d55abfd | 2009-12-09 14:05:12 -0800 | [diff] [blame] | 841 | </pre> |
| 842 | |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 843 | <p> |
Russ Cox | 830813f | 2009-11-08 21:08:27 -0800 | [diff] [blame] | 844 | If you had been editing the file, say for debugging, but do not |
| 845 | care to preserve your changes, you can run |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 846 | <code>git</code> <code>reset</code> <code>HEAD</code> <code>sin.go</code> |
| 847 | to abandon your changes. |
| 848 | Then run <code>git</code> <code>rebase</code> <code>--continue</code> to |
| 849 | restore the change commit. |
Russ Cox | 696e802 | 2009-11-07 18:56:00 -0800 | [diff] [blame] | 850 | </p> |
| 851 | |
Russ Cox | 19e27c7 | 2016-01-06 15:23:47 -0500 | [diff] [blame] | 852 | <h3 id="download">Reviewing code by others</h3> |
Dave Cheney | eda9590 | 2013-02-10 19:40:33 -0500 | [diff] [blame] | 853 | |
| 854 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 855 | As part of the review process reviewers can propose changes directly (in the |
| 856 | GitHub workflow this would be someone else attaching commits to a pull request). |
| 857 | |
| 858 | You can import these changes proposed by someone else into your local Git repository. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 859 | On the Gerrit review page, click the "Download ▼" link in the upper right |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 860 | corner, copy the "Checkout" command and run it from your local Git repo. It |
| 861 | should look something like this: |
Dave Cheney | eda9590 | 2013-02-10 19:40:33 -0500 | [diff] [blame] | 862 | </p> |
| 863 | |
| 864 | <pre> |
Lloyd Dewolf | fbbf219 | 2015-02-24 21:33:29 -0800 | [diff] [blame] | 865 | $ git fetch https://go.googlesource.com/review refs/changes/21/1221/1 && git checkout FETCH_HEAD |
Dave Cheney | eda9590 | 2013-02-10 19:40:33 -0500 | [diff] [blame] | 866 | </pre> |
| 867 | |
| 868 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 869 | To revert, change back to the branch you were working in. |
Oling Cat | aecbcd0 | 2013-02-15 14:01:12 +1100 | [diff] [blame] | 870 | </p> |
Dave Cheney | eda9590 | 2013-02-10 19:40:33 -0500 | [diff] [blame] | 871 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 872 | <h2 id="submit">Apply the change to the master branch</h2> |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 873 | |
| 874 | <p> |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 875 | After the code has been <code>LGTM</code>'ed, an approver may |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 876 | apply it to the master branch using the Gerrit UI. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 877 | There is a "Submit" button on the web page for the change |
| 878 | that appears once the change is approved (marked +2). |
Dave Cheney | eda9590 | 2013-02-10 19:40:33 -0500 | [diff] [blame] | 879 | </p> |
| 880 | |
| 881 | <p> |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 882 | This checks the change into the repository. |
| 883 | The change description will include a link to the code review, |
| 884 | and the code review will be updated with a link to the change |
| 885 | in the repository. |
Andrew Gerrand | d708e92 | 2014-12-10 09:29:35 +1100 | [diff] [blame] | 886 | Since the method used to integrate the changes is "Cherry Pick", |
| 887 | the commit hashes in the repository will be changed by |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 888 | the "Submit" operation. |
Russ Cox | 38a41ee | 2009-11-06 10:04:22 -0800 | [diff] [blame] | 889 | </p> |
| 890 | |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 891 | <h2 id="more">More information</h2> |
Robert Hencke | 75ba181 | 2014-04-25 20:09:04 -0700 | [diff] [blame] | 892 | |
| 893 | <p> |
Steve Francia | 5f3e7aa | 2017-02-09 15:33:13 -0500 | [diff] [blame] | 894 | In addition to the information here, the Go community maintains a <a |
| 895 | href="https://golang.org/wiki/CodeReview">CodeReview</a> wiki page. |
Robert Hencke | 75ba181 | 2014-04-25 20:09:04 -0700 | [diff] [blame] | 896 | Feel free to contribute to this page as you learn the review process. |
| 897 | </p> |