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