github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/doc/contribute.html (about) 1 <!--{ 2 "Title": "Contribution Guidelines" 3 }--> 4 5 <h2 id="Introduction">Introduction</h2> 6 7 <p> 8 This document explains how to contribute changes to the Go project. 9 It assumes you have followed the 10 <a href="/doc/install/source">installation instructions</a> and 11 have <a href="code.html">written and tested your code</a>. 12 </p> 13 14 <p> 15 (Note that the <code>gccgo</code> frontend lives elsewhere; 16 see <a href="gccgo_contribute.html">Contributing to gccgo</a>.) 17 </p> 18 19 <h2 id="Design">Discuss your design</h2> 20 21 <p> 22 The project welcomes submissions but please let everyone know what 23 you're working on if you want it to become part of the main repository. 24 </p> 25 26 <p> 27 Before undertaking to write something new for the Go project, send 28 mail to the <a href="https://groups.google.com/group/golang-nuts">mailing 29 list</a> to discuss what you plan to do. This gives everyone a 30 chance to validate the design, helps prevent duplication of effort, 31 and ensures that the idea fits inside the goals for the language 32 and tools. It also guarantees that the design is sound before code 33 is written; the code review tool is not the place for high-level 34 discussions. 35 </p> 36 37 <p> 38 In short, send mail before you code. 39 And don't start the discussion by mailing a change list! 40 </p> 41 42 <h2 id="Testing">Testing redux</h2> 43 44 <p> 45 You've <a href="code.html">written and tested your code</a>, but 46 before sending code out for review, run all the tests for the whole 47 tree to make sure the changes don't break other packages or programs: 48 </p> 49 50 <pre> 51 $ cd go/src 52 $ ./all.bash 53 </pre> 54 55 <p> 56 (To build under Windows use <code>all.bat</code>.) 57 </p> 58 59 <p> 60 After running for a while, the command should print 61 "<code>ALL</code> <code>TESTS</code> <code>PASSED</code>". 62 </p> 63 64 <h2 id="Code_review">Code review</h2> 65 66 <p> 67 Changes to Go must be reviewed before they are submitted, 68 no matter who makes the change. 69 (In exceptional cases, such as fixing a build, the review can 70 follow shortly after submitting.) 71 A custom git command called <code>git-codereview</code>, 72 discussed below, helps manage the code review process through a Google-hosted 73 <a href="https://go-review.googlesource.com/">instance</a> of the code review 74 system called <a href="https://code.google.com/p/gerrit/">Gerrit</a>. 75 </p> 76 77 <h3>Set up authentication for code review</h3> 78 79 <p> 80 The Git code hosting server and Gerrit code review server both use a Google 81 Account to authenticate. You therefore need a Google Account to proceed. 82 (If you can use the account to 83 <a href="https://www.google.com/accounts/Login">sign in at google.com</a>, 84 you can use it to sign in to the code review server.) 85 The email address you use with the code review system 86 will be recorded in the <a href="https://go.googlesource.com/go">change log</a> 87 and in the <a href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file. 88 You can <a href="https://www.google.com/accounts/NewAccount">create a Google Account</a> 89 associated with any address where you receive email. 90 </p> 91 92 <p> 93 Visit the site <a href="https://go.googlesource.com">go.googlesource.com</a> 94 and log in using your Google Account. 95 Click on the "Generate Password" link that appears at the top of the page. 96 </p> 97 98 <p> 99 Click the radio button that says "Only <code>go.googlesource.com</code>" 100 to use this authentication token only for the Go project. 101 </p> 102 103 <p> 104 Further down the page is a box containing commands to install 105 the authentication cookie in file called <code>.gitcookies</code> in your home 106 directory. 107 Copy the text for the commands into a Unix shell window to execute it. 108 That will install the authentication token. 109 </p> 110 111 <p> 112 (If you are on a Windows computer, you should instead follow the instructions 113 in the yellow box to run the command.) 114 </p> 115 116 <h3>Register with Gerrit</h3> 117 118 <p> 119 Now that you have a Google account and the authentication token, 120 you need to register your account with Gerrit, the code review system. 121 To do this, visit <a href="https://golang.org/cl">golang.org/cl</a> 122 and log in using the same Google Account you used above. 123 That is all that is required. 124 </p> 125 126 <h3>Install the git-codereview command</h3> 127 128 <p> 129 Now install the <code>git-codereview</code> command by running, 130 </p> 131 132 <pre> 133 go get -u golang.org/x/review/git-codereview 134 </pre> 135 136 <p> 137 Make sure <code>git-codereview</code> is installed in your shell path, so that the 138 <code>git</code> command can find it. Check that 139 </p> 140 141 <pre> 142 $ git codereview help 143 </pre> 144 145 <p> 146 prints help text, not an error. 147 </p> 148 149 <p> 150 Note to Git aficionados: The <code>git-codereview</code> command is not required to 151 upload and manage Gerrit code reviews. For those who prefer plain Git, the text 152 below gives the Git equivalent of each git-codereview command. If you do use plain 153 Git, note that you still need the commit hooks that the git-codereview command 154 configures; those hooks add a Gerrit <code>Change-Id</code> line to the commit 155 message and check that all Go source files have been formatted with gofmt. Even 156 if you intend to use plain Git for daily work, install the hooks in a new Git 157 checkout by running <code>git-codereview</code> <code>hooks</code>. 158 </p> 159 160 <h3>Set up git aliases</h3> 161 162 <p> 163 The <code>git-codereview</code> command can be run directly from the shell 164 by typing, for instance, 165 </p> 166 167 <pre> 168 $ git codereview sync 169 </pre> 170 171 <p> 172 but it is more convenient to set up aliases for <code>git-codereview</code>'s own 173 subcommands, so that the above becomes, 174 </p> 175 176 <pre> 177 $ git sync 178 </pre> 179 180 <p> 181 The <code>git-codereview</code> subcommands have been chosen to be distinct from 182 Git's own, so it's safe to do so. 183 </p> 184 185 <p> 186 The aliases are optional, but in the rest of this document we will assume 187 they are installed. 188 To install them, copy this text into your Git configuration file 189 (usually <code>.gitconfig</code> in your home directory): 190 </p> 191 192 <pre> 193 [alias] 194 change = codereview change 195 gofmt = codereview gofmt 196 mail = codereview mail 197 pending = codereview pending 198 submit = codereview submit 199 sync = codereview sync 200 </pre> 201 202 <h3>Understanding the git-codereview command</h3> 203 204 <p>After installing the <code>git-codereview</code> command, you can run</p> 205 206 <pre> 207 $ git codereview help 208 </pre> 209 210 <p> 211 to learn more about its commands. 212 You can also read the <a href="https://godoc.org/golang.org/x/review/git-codereview">command documentation</a>. 213 </p> 214 215 <h3>Switch to the master branch</h3> 216 217 <p> 218 Most Go installations use a release branch, but new changes should 219 only be made based on the master branch. 220 (They may be applied later to a release branch as part of the release process, 221 but most contributors won't do this themselves.) 222 Before making a change, make sure you start on the master branch: 223 </p> 224 225 <pre> 226 $ git checkout master 227 $ git sync 228 </pre> 229 230 <p> 231 (In Git terms, <code>git</code> <code>sync</code> runs 232 <code>git</code> <code>pull</code> <code>-r</code>.) 233 </p> 234 235 <h3>Make a change</h3> 236 237 <p> 238 The entire checked-out tree is writable. 239 Once you have edited files, you must tell Git that they have been modified. 240 You must also tell Git about any files that are added, removed, or renamed files. 241 These operations are done with the usual Git commands, 242 <code>git</code> <code>add</code>, 243 <code>git</code> <code>rm</code>, 244 and 245 <code>git</code> <code>mv</code>. 246 </p> 247 248 <p> 249 If you wish to checkpoint your work, or are ready to send the code out for review, run</p> 250 251 <pre> 252 $ git change <i><branch></i> 253 </pre> 254 255 <p> 256 from any directory in your Go repository to commit the changes so far. 257 The name <i><branch></i> is an arbitrary one you choose to identify the 258 local branch containing your changes. 259 </p> 260 261 <p> 262 (In Git terms, <code>git</code> <code>change</code> <code><branch></code> 263 runs <code>git</code> <code>checkout</code> <code>-b</code> <code>branch</code>, 264 then <code>git</code> <code>branch</code> <code>--set-upstream-to</code> <code>origin/master</code>, 265 then <code>git</code> <code>commit</code>.) 266 </p> 267 268 <p> 269 Git will open a change description file in your editor. 270 (It uses the editor named by the <code>$EDITOR</code> environment variable, 271 <code>vi</code> by default.) 272 The file will look like: 273 </p> 274 275 <pre> 276 277 # Please enter the commit message for your changes. Lines starting 278 # with '#' will be ignored, and an empty message aborts the commit. 279 # On branch foo 280 # Changes not staged for commit: 281 # modified: editedfile.go 282 # 283 </pre> 284 285 <p> 286 At the beginning of this file is a blank line; replace it 287 with a thorough description of your change. 288 The first line of the change description is conventionally a one-line 289 summary of the change, prefixed by the primary affected package, 290 and is used as the subject for code review mail. 291 The rest of the 292 description elaborates and should provide context for the 293 change and explain what it does. 294 If there is a helpful reference, mention it here. 295 </p> 296 297 <p> 298 After editing, the template might now read: 299 </p> 300 301 <pre> 302 math: improved Sin, Cos and Tan precision for very large arguments 303 304 The existing implementation has poor numerical properties for 305 large arguments, so use the McGillicutty algorithm to improve 306 accuracy above 1e10. 307 308 The algorithm is described at http://wikipedia.org/wiki/McGillicutty_Algorithm 309 310 Fixes #159 311 312 # Please enter the commit message for your changes. Lines starting 313 # with '#' will be ignored, and an empty message aborts the commit. 314 # On branch foo 315 # Changes not staged for commit: 316 # modified: editedfile.go 317 # 318 </pre> 319 320 <p> 321 The commented section of the file lists all the modified files in your client. 322 It is best to keep unrelated changes in different change lists, 323 so if you see a file listed that should not be included, abort 324 the command and move that file to a different branch. 325 </p> 326 327 <p> 328 The special notation "Fixes #159" associates the change with issue 159 in the 329 <a href="https://golang.org/issue/159">Go issue tracker</a>. 330 When this change is eventually submitted, the issue 331 tracker will automatically mark the issue as fixed. 332 (There are several such conventions, described in detail in the 333 <a href="https://help.github.com/articles/closing-issues-via-commit-messages/">GitHub Issue Tracker documentation</a>.) 334 </p> 335 336 <p> 337 Once you have finished writing the commit message, 338 save the file and exit the editor. 339 </p> 340 341 <p> 342 If you wish to do more editing, re-stage your changes using 343 <code>git</code> <code>add</code>, and then run 344 </p> 345 346 <pre> 347 $ git change 348 </pre> 349 350 <p> 351 to update the change description and incorporate the staged changes. The 352 change description contains a <code>Change-Id</code> line near the bottom, 353 added by a Git commit hook during the initial 354 <code>git</code> <code>change</code>. 355 That line is used by Gerrit to match successive uploads of the same change. 356 Do not edit or delete it. 357 </p> 358 359 <p> 360 (In Git terms, <code>git</code> <code>change</code> with no branch name 361 runs <code>git</code> <code>commit</code> <code>--amend</code>.) 362 </p> 363 364 <h3>Mail the change for review</h3> 365 366 <p> 367 Once the change is ready, mail it out for review: 368 </p> 369 370 <pre> 371 $ git mail 372 </pre> 373 374 <p> 375 You can specify a reviewer or CC interested parties 376 using the <code>-r</code> or <code>-cc</code> options. 377 Both accept a comma-separated list of email addresses: 378 </p> 379 380 <pre> 381 $ git mail -r joe@golang.org -cc mabel@example.com,math-nuts@swtch.com 382 </pre> 383 384 <p> 385 Unless explicitly told otherwise, such as in the discussion leading 386 up to sending in the change list, it's better not to specify a reviewer. 387 All changes are automatically CC'ed to the 388 <a href="https://groups.google.com/group/golang-codereviews">golang-codereviews@googlegroups.com</a> 389 mailing list. 390 </p> 391 392 <p> 393 (In Git terms, <code>git</code> <code>mail</code> pushes the local committed 394 changes to Gerrit using <code>git</code> <code>push</code> <code>origin</code> 395 <code>HEAD:refs/for/master</code>.) 396 </p> 397 398 <p> 399 If your change relates to an open issue, please add a comment to the issue 400 announcing your proposed fix, including a link to your CL. 401 </p> 402 403 <p> 404 The code review server assigns your change an issue number and URL, 405 which <code>git</code> <code>mail</code> will print, something like: 406 </p> 407 408 <pre> 409 remote: New Changes: 410 remote: https://go-review.googlesource.com/99999 math: improved Sin, Cos and Tan precision for very large arguments 411 </pre> 412 413 <h3>Reviewing code</h3> 414 415 <p> 416 Running <code>git</code> <code>mail</code> will send an email to you and the 417 reviewers asking them to visit the issue's URL and make comments on the change. 418 When done, the reviewer adds comments through the Gerrit user interface 419 and clicks "Reply" to send comments back. 420 You will receive a mail notification when this happens. 421 You must reply through the web interface. 422 (Unlike with the old Rietveld review system, replying by mail has no effect.) 423 </p> 424 425 <h3>Revise and upload</h3> 426 427 <p> 428 You must respond to review comments through the web interface. 429 (Unlike with the old Rietveld review system, responding by mail has no effect.) 430 </p> 431 432 <p> 433 When you have revised the code and are ready for another round of review, 434 stage those changes and use <code>git</code> <code>change</code> to update the 435 commit. 436 To send the update change list for another round of review, 437 run <code>git</code> <code>mail</code> again. 438 </p> 439 440 <p> 441 The reviewer can comment on the new copy, and the process repeats. 442 The reviewer approves the change by giving it a positive score 443 (+1 or +2) and replying <code>LGTM</code>: looks good to me. 444 </p> 445 446 <p> 447 You can see a list of your pending changes by running <code>git</code> 448 <code>pending</code>, and switch between change branches with <code>git</code> 449 <code>change</code> <code><i><branch></i></code>. 450 </p> 451 452 <h3>Synchronize your client</h3> 453 454 <p> 455 While you were working, others might have submitted changes to the repository. 456 To update your local branch, run 457 </p> 458 459 <pre> 460 $ git sync 461 </pre> 462 463 <p> 464 (In git terms, <code>git</code> <code>sync</code> runs 465 <code>git</code> <code>pull</code> <code>-r</code>.) 466 </p> 467 468 <p> 469 If files you were editing have changed, Git does its best to merge the 470 remote changes into your local changes. 471 It may leave some files to merge by hand. 472 </p> 473 474 <p> 475 For example, suppose you have edited <code>sin.go</code> but 476 someone else has committed an independent change. 477 When you run <code>git</code> <code>sync</code>, 478 you will get the (scary-looking) output: 479 480 <pre> 481 $ git sync 482 Failed to merge in the changes. 483 Patch failed at 0023 math: improved Sin, Cos and Tan precision for very large arguments 484 The copy of the patch that failed is found in: 485 /home/you/repo/.git/rebase-apply/patch 486 487 When you have resolved this problem, run "git rebase --continue". 488 If you prefer to skip this patch, run "git rebase --skip" instead. 489 To check out the original branch and stop rebasing, run "git rebase --abort". 490 </pre> 491 492 <p> 493 If this happens, run 494 </p> 495 496 <pre> 497 $ git status 498 </pre> 499 500 <p> 501 to see which files failed to merge. 502 The output will look something like this: 503 </p> 504 505 <pre> 506 rebase in progress; onto a24c3eb 507 You are currently rebasing branch 'mcgillicutty' on 'a24c3eb'. 508 (fix conflicts and then run "git rebase --continue") 509 (use "git rebase --skip" to skip this patch) 510 (use "git rebase --abort" to check out the original branch) 511 512 Unmerged paths: 513 (use "git reset HEAD <file>..." to unstage) 514 (use "git add <file>..." to mark resolution) 515 516 <i>both modified: sin.go</i> 517 </pre> 518 519 <p> 520 The only important part in that transcript is the italicized "both modified" 521 line: Git failed to merge your changes with the conflicting change. 522 When this happens, Git leaves both sets of edits in the file, 523 with conflicts marked by <code><<<<<<<</code> and 524 <code>>>>>>>></code>. 525 It is now your job to edit the file to combine them. 526 Continuing the example, searching for those strings in <code>sin.go</code> 527 might turn up: 528 </p> 529 530 <pre> 531 arg = scale(arg) 532 <<<<<<< HEAD 533 if arg > 1e9 { 534 ======= 535 if arg > 1e10 { 536 >>>>>>> mcgillicutty 537 largeReduce(arg) 538 </pre> 539 540 <p> 541 Git doesn't show it, but suppose the original text that both edits 542 started with was 1e8; you changed it to 1e10 and the other change to 1e9, 543 so the correct answer might now be 1e10. First, edit the section 544 to remove the markers and leave the correct code: 545 </p> 546 547 <pre> 548 arg = scale(arg) 549 if arg > 1e10 { 550 largeReduce(arg) 551 </pre> 552 553 <p> 554 Then tell Git that the conflict is resolved by running 555 </p> 556 557 <pre> 558 $ git add sin.go 559 </pre> 560 561 <p> 562 If you had been editing the file, say for debugging, but do not 563 care to preserve your changes, you can run 564 <code>git</code> <code>reset</code> <code>HEAD</code> <code>sin.go</code> 565 to abandon your changes. 566 Then run <code>git</code> <code>rebase</code> <code>--continue</code> to 567 restore the change commit. 568 </p> 569 570 <h3>Reviewing code by others</h3> 571 572 <p> 573 You can import a change proposed by someone else into your local Git repository. 574 On the Gerrit review page, click the "Download ▼" link in the upper right 575 corner, copy the "Checkout" command and run it from your local Git repo. 576 It should look something like this: 577 </p> 578 579 <pre> 580 $ git fetch https://go.googlesource.com/review refs/changes/21/1221/1 && git checkout FETCH_HEAD 581 </pre> 582 583 <p> 584 To revert, change back to the branch you were working in. 585 </p> 586 587 <h3>Submit the change after the review</h3> 588 589 <p> 590 After the code has been <code>LGTM</code>'ed, an approver may 591 submit it to the master branch using the Gerrit UI. 592 There is a "Submit" button on the web page for the change 593 that appears once the change is approved (marked +2). 594 </p> 595 596 <p> 597 This checks the change into the repository. 598 The change description will include a link to the code review, 599 and the code review will be updated with a link to the change 600 in the repository. 601 Since the method used to integrate the changes is "Cherry Pick", 602 the commit hashes in the repository will be changed by 603 the submit operation. 604 </p> 605 606 <h3>More information</h3> 607 608 <p> 609 In addition to the information here, the Go community maintains a <a href="https://golang.org/wiki/CodeReview">CodeReview</a> wiki page. 610 Feel free to contribute to this page as you learn the review process. 611 </p> 612 613 <h2 id="copyright">Copyright</h2> 614 615 <p>Files in the Go repository don't list author names, 616 both to avoid clutter and to avoid having to keep the lists up to date. 617 Instead, your name will appear in the 618 <a href="https://golang.org/change">change log</a> 619 and in the <a href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file 620 and perhaps the <a href="/AUTHORS"><code>AUTHORS</code></a> file. 621 </p> 622 623 <p>The <a href="/CONTRIBUTORS"><code>CONTRIBUTORS</code></a> file 624 defines who the Go contributors—the people—are; 625 the <a href="/AUTHORS"><code>AUTHORS</code></a> file defines 626 who “The Go Authors”—the copyright holders—are. 627 The Go developers at Google will update these files when submitting 628 your first change. 629 In order for them to do that, you need to have completed one of the 630 contributor license agreements: 631 <ul> 632 <li> 633 If you are the copyright holder, you will need to agree to the 634 <a href="https://developers.google.com/open-source/cla/individual">individual 635 contributor license agreement</a>, which can be completed online. 636 </li> 637 <li> 638 If your organization is the copyright holder, the organization 639 will need to agree to the 640 <a href="https://developers.google.com/open-source/cla/corporate">corporate 641 contributor license agreement</a>. 642 (If the copyright holder for your code has already completed the 643 agreement in connection with another Google open source project, 644 it does not need to be completed again.) 645 </li> 646 </ul> 647 648 <p> 649 This rigmarole needs to be done only for your first submission. 650 </p> 651 652 <p>Code that you contribute should use the standard copyright header:</p> 653 654 <pre> 655 // Copyright 2015 The Go Authors. All rights reserved. 656 // Use of this source code is governed by a BSD-style 657 // license that can be found in the LICENSE file. 658 </pre> 659 660 <p> 661 Files in the repository are copyright the year they are added. It is not 662 necessary to update the copyright year on files that you change. 663 </p>