cuelang.org/go@v0.13.0/CONTRIBUTING.md (about) 1 # Contribution Guide 2 3 There are many ways to contribute to CUE without writing code! 4 5 * Ask or answer questions via GitHub discussions, Slack, and Discord 6 * Raise issues such as bug reports or feature requests on GitHub 7 * Contributing thoughts and use cases to proposals. CUE can be and is 8 being used in many varied different ways. Sharing experience reports helps 9 to shape proposals and designs. 10 * Create content: share blog posts, tutorials, videos, meetup talks, etc 11 * Add your project to [Unity](https://cuelabs.dev/unity/) to help us test changes to CUE 12 13 ## Before contributing code 14 15 As with many open source projects, CUE uses the GitHub [issue 16 tracker](https://github.com/cue-lang/cue/issues) to not only track bugs, but 17 also coordinate work on new features, bugs, designs and proposals. Given the 18 inherently distributed nature of open-source this coordination is important 19 because it very often serves as the main form of communication between 20 contributors. 21 22 You can also exchange ideas or feedback with other contributors via the 23 `#contributing` [Slack channel](https://cuelang.slack.com/archives/CMY132JKY), 24 as well as the contributor office hours calls which we hold via the 25 [community calendar](https://cuelang.org/s/community-calendar) once per week. 26 27 ### Check the issue tracker 28 29 Whether you already know what contribution to make, or you are searching for an 30 idea, the [issue tracker](https://cuelang.org/issues) is always the first place 31 to go. Issues are triaged to categorize them and manage the workflow. 32 33 Most issues will be marked with one of the following workflow labels (links are 34 to queries in the issue tracker): 35 36 - [**Triage**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3ATriage): 37 Requires review by one of the core project maintainers. 38 - [**NeedsInvestigation**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsInvestigation): 39 The issue is not fully understood and requires analysis to understand the root 40 cause. 41 - [**NeedsDecision**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsDecision): 42 the issue is relatively well understood, but the CUE team hasn't yet decided 43 the best way to address it. It would be better to wait for a decision before 44 writing code. If you are interested on working on an issue in this state, feel 45 free to "ping" maintainers in the issue's comments if some time has passed 46 without a decision. 47 - [**NeedsFix**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsFix): 48 the issue is fully understood and code can be written to fix it. 49 - [**help 50 wanted**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3A"help+wanted"): 51 project maintainers need input from someone who has experience or expertise to 52 answer or progress this issue. 53 - [**good first 54 issue**](https://cuelang.org/issues?q=is%3Aissue+is%3Aopen+label%3A"good+first+issue"): 55 often combined with `NeedsFix`, `good first issue` indicates an issue is very 56 likely a good candidate for someone 57 looking to make their first code contribution. 58 59 60 ### Open an issue for any new problem 61 62 Excluding very trivial changes, all contributions should be connected to an 63 existing issue. Feel free to open one and discuss your plans. This process 64 gives everyone a chance to validate the design, helps prevent duplication of 65 effort, and ensures that the idea fits inside the goals for the language and 66 tools. It also checks that the design is sound before code is written; the code 67 review tool is not the place for high-level discussions. 68 69 Sensitive security-related issues should be reported to <a 70 href="mailto:security@cuelang.org">security@cuelang.org</a>. 71 72 ## Becoming a code contributor 73 74 The code contribution process used by the CUE project is a little different from 75 that used by other open source projects. We assume you have a basic 76 understanding of [`git`](https://git-scm.com/) and [Go](https://golang.org) 77 (1.23 or later). 78 79 The first thing to decide is whether you want to contribute a code change via 80 GitHub or GerritHub. Both workflows are fully supported, and whilst GerritHub is 81 used by the core project maintainers as the "source of truth", the GitHub Pull 82 Request workflow is 100% supported - contributors should feel entirely 83 comfortable contributing this way if they prefer. 84 85 Contributions via either workflow must be accompanied by a Developer Certificate 86 of Origin. 87 88 ### Asserting a Developer Certificate of Origin 89 90 Contributions to the CUE project must be accompanied by a [Developer Certificate 91 of Origin](https://developercertificate.org/), we are using version 1.1. 92 93 All commit messages must contain the `Signed-off-by` line with an email address 94 that matches the commit author. This line asserts the Developer Certificate of Origin. 95 96 When committing, use the `--signoff` (or `-s`) flag: 97 98 ```console 99 $ git commit -s 100 ``` 101 102 You can also [set up a prepare-commit-msg git 103 hook](#do-i-really-have-to-add-the--s-flag-to-each-commit) to not have to supply 104 the `-s` flag. 105 106 The explanations of the GitHub and GerritHub contribution workflows that follow 107 assume all commits you create are signed-off in this way. 108 109 110 ## Preparing for GitHub Pull Request (PR) Contributions 111 112 First-time contributors that are already familiar with the <a 113 href="https://guides.github.com/introduction/flow/">GitHub flow</a> are 114 encouraged to use the same process for CUE contributions. Even though CUE 115 maintainers use GerritHub for code review, the GitHub PR workflow is 100% 116 supported. 117 118 Here is a checklist of the steps to follow when contributing via GitHub PR 119 workflow: 120 121 - **Step 0**: Review the guidelines on [Good Commit 122 Messages](#good-commit-messages), [The Review Process](#the-review-process) 123 and [Miscellaneous Topics](#miscellaneous-topics) 124 - **Step 1**: Create a GitHub account if you do not have one. 125 - **Step 2**: 126 [Fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) the CUE 127 project, and clone your fork locally 128 129 130 That's it! You are now ready to send a change via GitHub, the subject of the 131 next section. 132 133 134 135 ## Sending a change via GitHub 136 137 The GitHub documentation around [working with 138 forks](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/getting-started/about-collaborative-development-models) 139 is extensive so we will not cover that ground here. 140 141 Before making any changes it's a good idea to verify that you have a stable 142 baseline by running the tests: 143 144 ```console 145 $ go test ./... 146 ``` 147 148 Then make your planned changes and create a commit from the staged changes: 149 150 ```console 151 # Edit files 152 $ git add file1 file2 153 $ git commit -s 154 ``` 155 156 Notice as we explained above, the `-s` flag asserts the Developer Certificate of 157 Origin by adding a `Signed-off-by` line to a commit. When writing a commit 158 message, remember the guidelines on [good commit 159 messages](#good-commit-messages). 160 161 You’ve written and tested your code, but before sending code out for review, run 162 all the tests from the root of the repository to ensure the changes don’t break 163 other packages or programs: 164 165 ```console 166 $ go test ./... 167 ``` 168 169 Your change is now ready! [Submit a 170 PR](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) 171 in the usual way. 172 173 Once your PR is submitted, a maintainer will trigger continuous integration (CI) 174 workflows to run and [review your proposed 175 change](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request). 176 The results from CI and the review might indicate further changes are required, 177 and this is where the CUE project differs from others: 178 179 ### Making changes to a PR 180 181 Some projects accept and encourage multiple commits in a single PR. Either as a 182 way of breaking down the change into smaller parts, or simply as a record of the 183 various changes during the review process. 184 185 The CUE project follows the Gerrit model of a single commit being the unit of 186 change. Therefore, all PRs must only contain a single commit. But how does this 187 work if you need to make changes requested during the review process? Does this 188 not require you to create additional commits? 189 190 The easiest way to maintain a single commit is to amend an existing commit. 191 Rather misleadingly, this doesn't actually amend a commit, but instead creates a 192 new commit which is the result of combining the last commit and any new changes: 193 194 ```console 195 # PR is submitted, feedback received. Time to make some changes! 196 197 $ git add file1 file2 # stage the files we have added/removed/changed 198 $ git commit --amend # amend the last commit 199 $ git push -f # push the amended commit to your PR 200 ``` 201 202 The `-f` flag is required to force push your branch to GitHub: this overrides a 203 warning from `git` telling you that GitHub knows nothing about the relationship 204 between the original commit in your PR and the amended commit. 205 206 What happens if you accidentally create an additional commit and now have two 207 commits on your branch? No worries, you can "squash" commits on a branch to 208 create a single commit. See the GitHub documentation on [how to squash commits 209 with GitHub 210 Desktop](https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/managing-commits/squashing-commits), 211 or using the [`git` command 212 interactively](https://medium.com/@slamflipstrom/a-beginners-guide-to-squashing-commits-with-git-rebase-8185cf6e62ec). 213 214 ### PR approved! 215 216 With the review cycle complete, the CI checks green and your PR approved, it 217 will be imported into GerritHub and then submitted. Your PR will close 218 automatically as it is "merged" in GerritHub. Congratulations! You will have 219 made your first contribution to the CUE project. 220 221 222 ## Preparing for GerritHub [CL](https://google.github.io/eng-practices/#terminology) Contributions 223 224 CUE maintainers use GerritHub for code review. It has a powerful review 225 interface with comments that are attributed to patchsets (versions of a change). 226 Orienting changes around a single commit allows for "stacked" changes, and also 227 encourages unrelated changes to be broken into separate CLs because the process 228 of creating and linking CLs is so easy. 229 230 For those more comfortable with contributing via GitHub PRs, please continue to 231 do so: the CUE project supports both workflows so that people have a choice. 232 233 For those who would like to contribute via GerritHub, read on! 234 235 ### Overview 236 237 The first step in the GerritHub flow is registering as a CUE contributor and 238 configuring your environment. Here is a checklist of the required steps to 239 follow: 240 241 - **Step 0**: Review the guidelines on [Good Commit Messages](#good-commit-messages), [The Review Process](#the-review-process) and [Miscellaneous Topics](#miscellaneous-topics) 242 - **Step 1**: Decide which email address you want to use for contributions. 243 - **Step 2**: Set up a [GerritHub](http://gerrithub.io/) account. 244 - **Step 3**: [Install `git-codereview`](#step-3-install-the-git-codereview-command) 245 - **Step 4**: Clone the CUE repository locally. 246 247 248 We cover steps 1-4 in more detail below. 249 250 ### Step 1: Decide which email address you want to use for contributions 251 252 A contribution to CUE is made through a specific e-mail address. Make sure to 253 use the same account throughout the process and for all your subsequent 254 contributions. You may need to decide whether to use a personal address or a 255 corporate address. The choice will depend on who will own the copyright for the 256 code that you will be writing and submitting. You might want to discuss this 257 topic with your employer before deciding which account to use. 258 259 You also need to make sure that your `git` tool is configured to create commits 260 using your chosen e-mail address. You can either configure Git globally (as a 261 default for all projects), or locally (for a single specific project). You can 262 check the current configuration with this command: 263 264 ```console 265 $ git config --global user.email # check current global config 266 $ git config user.email # check current local config 267 ``` 268 269 To change the configured address: 270 271 ```console 272 $ git config --global user.email name@example.com # change global config 273 $ git config user.email name@example.com # change local config 274 ``` 275 276 ### Step 2: Setup a GerritHub account 277 278 If you have not used GerritHub before, setting up an account is a simple 279 process: 280 281 - Visit [GerritHub](http://gerrithub.io/). 282 - Click "First Time Sign In". 283 - Click the green "Sign In" button, to sign in using your GitHub 284 credentials. 285 - When prompted "Which level of GitHub access do you need?", choose 286 "Default" and then click "Login." 287 - Click "Authorize gerritforge-ltd" on the GitHub auth page. 288 - Confirm account profile details and click "Next." 289 290 If you want to use SSH for authentication *to GerritHub*, SSH keys can be 291 [configured in your user 292 profile](https://review.gerrithub.io/settings/#SSHKeys). If you choose to use 293 SSH for authentication, you will not be able to use the `git-codereview` 294 command that's suggested later in this document, as the command [doesn't 295 support SSH-based git 296 origins](https://github.com/golang/go/issues/9599#issuecomment-70538097). 297 298 For HTTP Credentials, [generate a password via your user 299 profile](https://review.gerrithub.io/settings/#HTTPCredentials). Then use an 300 existing HTTP authentication mechanism like `.netrc`, macOS KeyChain, or some 301 other [credential helper](https://git-scm.com/docs/gitcredentials). If you have 302 any troubles with this step, please [raise an 303 issue](https://cuelang.org/issues/new). 304 305 306 ### Step 3: Install the `git-codereview` command 307 308 Changes to CUE must be reviewed before they are accepted, no matter who makes 309 the change. A custom `git` command called `git-codereview` simplifies sending 310 changes to Gerrit. 311 312 Install the `git-codereview` command by running, 313 314 ```console 315 $ go install golang.org/x/review/git-codereview@master 316 ``` 317 318 Make sure `git-codereview` is installed in your shell `PATH`, so that the 319 `git` command can find it. 320 Check that 321 322 ```console 323 $ git codereview help 324 ``` 325 326 prints help text, not an error. 327 328 On Windows, when using git-bash you must make sure that `git-codereview.exe` is 329 in your `git` exec-path. Run `git --exec-path` to discover the right location 330 then create a symbolic link or just copy the executable from $GOPATH/bin to this 331 directory. 332 333 ### Step 4: Clone the CUE repository locally 334 335 Visit https://review.gerrithub.io/admin/repos/cue-lang/cue, then click "SSH" or 336 "HTTP" depending on which authentication mechanism you configured in step 2. 337 Then copy and run the corresponding "Clone" command. Make sure not to use 338 "ANONYMOUS HTTP", as that will not work with `git-codereview` command. 339 340 ## Sending a change via GerritHub 341 342 Sending a change via GerritHub is quite different to the GitHub PR flow. At 343 first the differences might be jarring, but with practice the workflow is 344 incredibly intuitive and far more powerful when it comes to chains of "stacked" 345 changes. 346 347 ### Step 1: Ensure you have a stable baseline 348 349 With a working directory of your local clone of the CUE repository, run the tests: 350 351 ```console 352 $ go test ./... 353 ``` 354 355 ### Step 2: Prepare changes in a new branch 356 357 Each CUE change must be made in a branch, created from the `master` branch. You 358 can use the normal `git` commands to create a branch and stage changes: 359 360 361 ```console 362 $ git checkout -b mybranch 363 $ [edit files...] 364 $ git add [files...] 365 ``` 366 367 To commit changes, instead of `git commit -s`, use `git codereview change -s`. 368 369 370 ```console 371 $ git codereview change -s 372 (opens $EDITOR) 373 ``` 374 375 You can edit the commit description in your favorite editor as usual. The 376 `git codereview change` command will automatically add a unique Change-Id 377 line near the bottom. That line is used by Gerrit to match successive uploads 378 of the same change. Do not edit or delete it. A Change-Id looks like this: 379 380 381 ``` 382 Change-Id: I2fbdbffb3aab626c4b6f56348861b7909e3e8990 383 ``` 384 385 The `git-codereview` command also checks that you've run `go fmt` over the 386 source code, and that the commit message follows the suggested format. 387 388 389 If you need to edit the files again, you can stage the new changes and re-run 390 `git codereview change -s`: each subsequent run will amend the existing commit 391 while preserving the Change-Id. 392 393 Make sure that you always keep a single commit in each branch. If you add more 394 commits by mistake, you can use `git rebase` to [squash them 395 together](https://medium.com/@slamflipstrom/a-beginners-guide-to-squashing-commits-with-git-rebase-8185cf6e62ec) 396 into a single one. 397 398 399 400 401 402 ### Step 3: Test your changes 403 404 You've written and tested your code, but before sending code out for review, run 405 all the tests for the whole tree to ensure the changes don't break other 406 packages or programs: 407 408 409 ```console 410 $ go test ./... 411 ``` 412 413 414 ### Step 4: Send changes for review 415 416 Once the change is ready and tested over the whole tree, send it for review. 417 This is done with the `mail` sub-command which, despite its name, doesn't 418 directly mail anything; it just sends the change to Gerrit: 419 420 421 ```console 422 $ git codereview mail 423 ``` 424 425 Gerrit assigns your change a number and URL, which `git codereview mail` will 426 print, something like: 427 428 429 ``` 430 remote: New Changes: 431 remote: https://review.gerrithub.io/99999 math: improved Sin, Cos and Tan precision for very large arguments 432 ``` 433 434 If you get an error instead, see the ["Troubleshooting mail 435 errors"](#troubleshooting-gerrithub-mail-errors). 436 437 438 ### Step 5: Revise changes after a review 439 440 CUE maintainers will review your code on Gerrit, and you will get notifications 441 via e-mail. You can see the review on Gerrit and comment on them there. You 442 can also reply [using 443 e-mail](https://gerrit-review.googlesource.com/Documentation/intro-user.html#reply-by-email) 444 if you prefer. 445 446 447 If you need to revise your change after the review, edit the files in the same 448 branch you previously created, add them to the Git staging area, and then amend 449 the commit with `git codereview change`: 450 451 452 ```console 453 $ git codereview change # amend current commit (without -s because we already signed-off, above) 454 (open $EDITOR) 455 $ git codereview mail # send new changes to Gerrit 456 ``` 457 458 If you don't need to change the commit description, just save and exit from the 459 editor. Remember not to touch the special `Change-Id` line. 460 461 462 Again, make sure that you always keep a single commit in each branch. If you 463 add more commits by mistake, you can use `git rebase` to [squash them 464 together](https://medium.com/@slamflipstrom/a-beginners-guide-to-squashing-commits-with-git-rebase-8185cf6e62ec) 465 into a single one. 466 467 468 ### CL approved! 469 470 With the review cycle complete, the CI checks green and your CL approved with 471 `+2`, it will be submitted. Congratulations! You will have made your first 472 contribution to the CUE project. 473 474 475 ## Good commit messages 476 477 Commit messages in CUE follow a specific set of conventions, which we discuss in 478 this section. 479 480 481 Here is an example of a good one: 482 483 484 ``` 485 cue/ast/astutil: fix resolution bugs 486 487 This fixes several bugs and documentation bugs in 488 identifier resolution. 489 490 1. Resolution in comprehensions would resolve identifiers 491 to themselves. 492 493 2. Label aliases now no longer bind to references outside 494 the scope of the field. The compiler would catch this invalid 495 bind and report an error, but it is better not to bind in the 496 first place. 497 498 3. Remove some more mentions of Template labels. 499 500 4. Documentation for comprehensions was incorrect 501 (Scope and Node were reversed). 502 503 5. Aliases X in `X=[string]: foo` should only be visible 504 in foo. 505 506 Fixes #946 507 ``` 508 509 ### First line 510 511 The first line of the change description is conventionally a short one-line 512 summary of the change, prefixed by the primary affected package 513 (`cue/ast/astutil` in the example above). 514 515 516 A rule of thumb is that it should be written so to complete the sentence "This 517 change modifies CUE to \_\_\_\_." That means it does not start with a capital 518 letter, is not a complete sentence, and actually summarizes the result of the 519 change. 520 521 522 Follow the first line by a blank line. 523 524 525 ### Main content 526 527 The rest of the description elaborates and should provide context for the change 528 and explain what it does. Write in complete sentences with correct punctuation, 529 just like for your comments in CUE. Don't use HTML, Markdown, or any other 530 markup language. 531 532 533 534 ### Referencing issues 535 536 The special notation `Fixes #12345` associates the change with issue 12345 in 537 the [CUE issue tracker](https://cuelang.org/issue/12345) When this change is 538 eventually applied, the issue tracker will automatically mark the issue as 539 fixed. 540 541 542 If the change is a partial step towards the resolution of the issue, uses the 543 notation `Updates #12345`. This will leave a comment in the issue linking back 544 to the change in Gerrit, but it will not close the issue when the change is 545 applied. 546 547 548 All issues are tracked in the main repository's issue tracker. 549 If you are sending a change against a subrepository, you must use the 550 fully-qualified syntax supported by GitHub to make sure the change is linked to 551 the issue in the main repository, not the subrepository (eg. `Fixes cue-lang/cue#999`). 552 553 554 555 ## The review process 556 557 This section explains the review process in detail and how to approach reviews 558 after a change has been sent to either GerritHub or GitHub. 559 560 561 562 ### Common mistakes 563 564 When a change is sent to Gerrit, it is usually triaged within a few days. A 565 maintainer will have a look and provide some initial review that for first-time 566 contributors usually focuses on basic cosmetics and common mistakes. These 567 include things like: 568 569 570 - Commit message not following the suggested format. 571 - The lack of a linked GitHub issue. The vast majority of changes require a 572 linked issue that describes the bug or the feature that the change fixes or 573 implements, and consensus should have been reached on the tracker before 574 proceeding with it. Gerrit reviews do not discuss the merit of the change, just 575 its implementation. Only trivial or cosmetic changes will be accepted without 576 an associated issue. 577 578 ### Continuous Integration (CI) checks 579 580 After an initial reading of your change, maintainers will trigger CI checks, 581 that run a full test suite and [Unity](https://cuelabs.dev/unity/) 582 checks. Most CI tests complete in a few minutes, at which point a link will be 583 posted in Gerrit where you can see the results, or if you are submitting a PR 584 results are presented as checks towards the bottom of the PR. 585 586 587 If any of the CI checks fail, follow the link and check the full logs. Try to 588 understand what broke, update your change to fix it, and upload again. 589 Maintainers will trigger a new CI run to see if the problem was fixed. 590 591 592 ### Reviews 593 594 The CUE community values very thorough reviews. Think of each review comment 595 like a ticket: you are expected to somehow "close" it by acting on it, either by 596 implementing the suggestion or convincing the reviewer otherwise. 597 598 599 After you update the change, go through the review comments and make sure to 600 reply to every one. In GerritHub you can click the "Done" button to reply 601 indicating that you've implemented the reviewer's suggestion and in GitHub you 602 can mark a comment as resolved; otherwise, click on "Reply" and explain why you 603 have not, or what you have done instead. 604 605 606 It is perfectly normal for changes to go through several round of reviews, with 607 one or more reviewers making new comments every time and then waiting for an 608 updated change before reviewing again. This cycle happens even for experienced 609 contributors, so don't be discouraged by it. 610 611 612 ### Voting conventions in GerritHub 613 614 As they near a decision, reviewers will make a "vote" on your change. 615 The Gerrit voting system involves an integer in the range -2 to +2: 616 617 618 - **+2** The change is approved for being merged. Only CUE maintainers can cast 619 a +2 vote. 620 - **+1** The change looks good, but either the reviewer is requesting minor 621 changes before approving it, or they are not a maintainer and cannot approve 622 it, but would like to encourage an approval. 623 - **-1** The change is not good the way it is but might be fixable. A -1 vote 624 will always have a comment explaining why the change is unacceptable. 625 - **-2** The change is blocked by a maintainer and cannot be approved. Again, 626 there will be a comment explaining the decision. 627 628 ### Reviewed changed in GitHub 629 630 When reviewing a PR, a reviewer will indicate the nature of their response: 631 632 * **Comments** - general feedback without explicit approval. 633 * **Approve** - feedback and approval for this PR to accepted and submitted in 634 GerritHub. 635 * **Request changes** - feedback that must be addressed before this PR can 636 proceed. 637 638 639 640 ### Submitting an approved change 641 642 After the code has been `+2`'ed in GerritHub or "Approved" in GitHub, an 643 approver will apply it to the `master` branch using the Gerrit user interface. 644 This is called "submitting the change". 645 646 647 The two steps (approving and submitting) are separate because in some cases 648 maintainers may want to approve it but not to submit it right away (for 649 instance, the tree could be temporarily frozen). 650 651 652 Submitting a change checks it into the repository. The change description will 653 include a link to the code review, which will be updated with a link to the 654 change in the repository. Since the method used to integrate the changes is 655 Git's "Cherry Pick", the commit hashes in the repository will be changed by the 656 submit operation. 657 658 659 If your change has been approved for a few days without being submitted, feel 660 free to write a comment in GerritHub or GitHub requesting submission. 661 662 663 ## Miscellaneous topics 664 665 This section collects a number of other comments that are outside the 666 issue/edit/code review/submit process itself. 667 668 669 670 ### Copyright headers 671 672 Files in the CUE repository don't list author names, both to avoid clutter and 673 to avoid having to keep the lists up to date. Instead, your name will appear in 674 the [git change log](https://review.gerrithub.io/plugins/gitiles/cue-lang/cue/+log) 675 and in [GitHub's contributor stats](https://github.com/cue-lang/cue/graphs/contributors) 676 when using an email address linked to a GitHub account. 677 678 New files that you contribute should use the standard copyright header 679 with the current year reflecting when they were added. 680 Do not update the copyright year for existing files that you change. 681 682 683 ``` 684 // Copyright 2018 The CUE Authors 685 // 686 // Licensed under the Apache License, Version 2.0 (the "License"); 687 // you may not use this file except in compliance with the License. 688 // You may obtain a copy of the License at 689 // 690 // http://www.apache.org/licenses/LICENSE-2.0 691 // 692 // Unless required by applicable law or agreed to in writing, software 693 // distributed under the License is distributed on an "AS IS" BASIS, 694 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 695 // See the License for the specific language governing permissions and 696 // limitations under the License. 697 ``` 698 699 ### Troubleshooting GerritHub mail errors 700 701 The most common way that the `git codereview mail` command fails is because 702 the e-mail address in the commit does not match the one that you used during the 703 registration process. 704 705 If you see something like... 706 707 708 ``` 709 remote: Processing changes: refs: 1, done 710 remote: 711 remote: ERROR: In commit ab13517fa29487dcf8b0d48916c51639426c5ee9 712 remote: ERROR: author email address your.email@domain.com 713 remote: ERROR: does not match your user account. 714 ``` 715 716 you need to configure Git for this repository to use the e-mail address that you 717 registered with. To change the e-mail address to ensure this doesn't happen 718 again, run: 719 720 721 ```console 722 $ git config user.email email@address.com 723 ``` 724 725 Then change the commit to use this alternative e-mail address with this command: 726 727 728 ```console 729 $ git commit --amend --author="Author Name <email@address.com>" 730 ``` 731 732 Then retry by running: 733 734 735 ```console 736 $ git codereview mail 737 ``` 738 739 740 ### Quickly testing your changes 741 742 Running `go test ./...` for every single change to the code tree is burdensome. 743 Even though it is strongly suggested to run it before sending a change, during 744 the normal development cycle you may want to compile and test only the package 745 you are developing. 746 747 748 In this section, we'll call the directory into which you cloned the CUE 749 repository `$CUEDIR`. As CUE uses Go modules, The `cue` tool built by `go 750 install` will be installed in the `bin/go` in your home directory by default. 751 752 If you're changing the CUE APIs or code, you can test the results in just 753 this package directory. 754 755 ```console 756 $ cd $CUEDIR/cue 757 $ [make changes...] 758 $ go test 759 ``` 760 761 You don't need to build a new cue tool to test it. 762 Instead you can run the tests from the root. 763 764 ```console 765 $ cd $CUEDIR 766 $ go test ./... 767 ``` 768 769 To use the new tool you would still need to build and install it. 770 771 772 ### Specifying a reviewer / CCing others in GerritHub 773 774 You can specify a reviewer or CC interested parties using the `-r` or `-cc` 775 options. Both accept a comma-separated list of e-mail addresses: 776 777 778 ```console 779 $ git codereview mail -r joe@cuelang.org -cc mabel@example.com,math-nuts@swtch.com 780 ``` 781 782 783 ### Synchronize your client with GerritHub 784 785 While you were working, others might have submitted changes to the repository. 786 To update your local branch, run 787 788 789 ```console 790 $ git codereview sync 791 ``` 792 793 (Under the covers this runs 794 `git pull -r`.) 795 796 797 798 ### Reviewing code by others 799 800 As part of the review process reviewers can propose changes directly (in the 801 GitHub workflow this would be someone else attaching commits to a pull request). 802 803 You can import these changes proposed by someone else into your local Git 804 repository. On the Gerrit review page, click the "Download ▼" link in the upper 805 right corner, copy the "Checkout" command and run it from your local Git repo. 806 It will look something like this: 807 808 809 ```console 810 $ git fetch https://review.gerrithub.io/a/cue-lang/cue refs/changes/67/519567/1 && git checkout FETCH_HEAD 811 ``` 812 813 To revert, change back to the branch you were working in. 814 815 816 ### Set up git aliases 817 818 The `git-codereview` command can be run directly from the shell 819 by typing, for instance, 820 821 822 ```console 823 $ git codereview sync 824 ``` 825 826 but it is more convenient to set up aliases for `git-codereview`'s own 827 subcommands, so that the above becomes, 828 829 830 ```console 831 $ git sync 832 ``` 833 834 The `git-codereview` subcommands have been chosen to be distinct from Git's own, 835 so it's safe to define these aliases. To install them, copy this text into your 836 Git configuration file (usually `.gitconfig` in your home directory): 837 838 839 ``` 840 [alias] 841 change = codereview change 842 gofmt = codereview gofmt 843 mail = codereview mail 844 pending = codereview pending 845 submit = codereview submit 846 sync = codereview sync 847 ``` 848 849 850 ### Sending multiple dependent changes 851 852 Advanced users may want to stack up related commits in a single branch. Gerrit 853 allows for changes to be dependent on each other, forming such a dependency 854 chain. Each change will need to be approved and submitted separately but the 855 dependency will be visible to reviewers. 856 857 858 To send out a group of dependent changes, keep each change as a different commit 859 under the same branch, and then run: 860 861 862 ```console 863 $ git codereview mail HEAD 864 ``` 865 866 Make sure to explicitly specify `HEAD`, which is usually not required when 867 sending single changes. 868 869 This is covered in more detail in [the Gerrit 870 documentation](https://gerrit-review.googlesource.com/Documentation/concept-changes.html). 871 872 ### Do I really have to add the `-s` flag to each commit? 873 874 Earlier in this guide we explained the role the [Developer Certificate of 875 Origin](https://developercertificate.org/) plays in contributions to the CUE 876 project. we also explained how `git commit -s` can be used to sign-off each 877 commit. But: 878 879 * it's easy to forget the `-s` flag; 880 * it's not always possible/easy to fix up other tools that wrap the `git commit` 881 step. 882 883 You can automate the sign-off step using a [`git` 884 hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). Run the 885 following commands in the root of a `git` repository where you want to 886 automatically sign-off each commit: 887 888 ``` 889 cat <<'EOD' > .git/hooks/prepare-commit-msg 890 #!/bin/sh 891 892 NAME=$(git config user.name) 893 EMAIL=$(git config user.email) 894 895 if [ -z "$NAME" ]; then 896 echo "empty git config user.name" 897 exit 1 898 fi 899 900 if [ -z "$EMAIL" ]; then 901 echo "empty git config user.email" 902 exit 1 903 fi 904 905 git interpret-trailers --if-exists doNothing --trailer \ 906 "Signed-off-by: $NAME <$EMAIL>" \ 907 --in-place "$1" 908 EOD 909 chmod +x .git/hooks/prepare-commit-msg 910 ``` 911 912 If you already have a `prepare-commit-msg` hook, adapt it accordingly. The `-s` 913 flag will now be implied every time a commit is created. 914 915 916 ## Code of Conduct 917 918 Guidelines for participating in CUE community spaces and a reporting process for 919 handling issues can be found in the [Code of 920 Conduct](https://cuelang.org/docs/contribution_guidelines/conduct).