|
| 1 | +# Working with Gerrit |
| 2 | + |
| 3 | +The Gerrit-based workflow prefers small commits that get reviewed individually, |
| 4 | +as "changelists" (CLs). `jj` is well suited for this workflow: each `jj` change |
| 5 | +can be a single CL which you can update over time. |
| 6 | + |
| 7 | +## Change IDs |
| 8 | + |
| 9 | +Similar to `jj`'s change IDs, Gerrit associates commits with a common "change" |
| 10 | +using a `Change-Id` header in the commits. Gerrit repositories typically use a |
| 11 | +Git commit hook to add change IDs to commits, you can configure `jj` to do the |
| 12 | +same with this configuration: |
| 13 | + |
| 14 | +```toml |
| 15 | +[templates] |
| 16 | +commit_trailers = ''' |
| 17 | +if(self.author().email() == "YOUR_EMAIL_HERE" && |
| 18 | + !trailers.contains_key("Change-Id"), |
| 19 | + format_gerrit_change_id_trailer(self) |
| 20 | +) |
| 21 | +``` |
| 22 | +
|
| 23 | +
|
| 24 | +## Push workflow |
| 25 | +
|
| 26 | +In a traditional Gerrit workflow, you push commits to the review server using |
| 27 | +`git push origin <rev>:refs/for/main`. |
| 28 | +
|
| 29 | +Repositories using `depot_tools` will likely teach you about the `git cl upload` |
| 30 | +workflow instead: which by default will only push from a named, checked-out |
| 31 | +branch, and will squash all commits into a single change upstream |
| 32 | +(overrideable with `--no-squash`). |
| 33 | +
|
| 34 | +
|
| 35 | +If working with `jj`, it is convenient for a single `jj` change to be a single |
| 36 | +Gerrit change. `jj` also likes to keep the repository in "detached HEAD" mode, |
| 37 | +so `git cl upload` needs a `git checkout <branchname>` first to work. As such, |
| 38 | +`git cl upload` is not the best way to interact with a `jj` repository. |
| 39 | +
|
| 40 | +Regardless of whether or not you are using `depot_tools`, `jj` works best with |
| 41 | +Gerrit when you build on top of the `refs/for/main` primitive. |
| 42 | +
|
| 43 | +
|
| 44 | +The following alias makes uploading to Gerrit with `jj` convenient: |
| 45 | +
|
| 46 | +```toml |
| 47 | +[aliases] |
| 48 | +cl-up = ["util", "exec", "--", "bash", "-c", """ |
| 49 | +set -euo pipefail |
| 50 | +INPUT=${1:-"@-"} |
| 51 | +HASH=$(jj log -r "${INPUT}" -T commit_id --no-graph) |
| 52 | +HASHINFO=$(git log -n 1 ${HASH} --oneline --color=always) |
| 53 | +echo "Pushing from commit ${HASHINFO}" |
| 54 | +git push origin "${HASH}":refs/for/main |
| 55 | +""", ""] |
| 56 | +``` |
| 57 | +
|
| 58 | +`jj cl-up <rev>` will push `<rev>` (`@-` if not specified) and its ancestors to |
| 59 | +`origin`, creating new CLs if necessary, updating existing ones otherwise. |
| 60 | +
|
| 61 | +Its output will look something like this: |
| 62 | +
|
| 63 | +```console |
| 64 | +$ jj |
| 65 | +@ wtzvnrmz manishearth@google.com 2025-06-18 18:29:08 f694f9f1 |
| 66 | +│ (empty) (no description set) |
| 67 | +○ zqlxpsus manishearth@google.com 2025-06-18 18:29:08 git_head() 556b213a |
| 68 | +│ [temporal] Add Add/Subtract to all Temporal types |
| 69 | +│ ○ rnnrzqpt manishearth@google.com 2025-06-18 18:29:08 8d16e5e5 |
| 70 | +├─╯ [temporal] Add remaining .with() methods |
| 71 | +○ slwvqnrr manishearth@google.com 2025-06-18 18:28:52 e68229d4 |
| 72 | +│ [temporal] Add `wrapped_rust()` helper for writing generic code |
| 73 | +│ ○ vtszmlsx manishearth@google.com 2025-06-18 18:25:38 c14b9e56 |
| 74 | +├─╯ [temporal] Add PlainTime.{compare, with} |
| 75 | +○ xrvwxply manishearth@google.com 2025-06-18 18:24:28 f4ac4ff7 |
| 76 | +│ [temporal] Add IsPartialTemporalObject |
| 77 | +│ ○ tlmqwnpn manishearth@google.com 2025-06-18 17:02:40 df3c2fa5 |
| 78 | +├─╯ Fix comment about enable_rust |
| 79 | +◆ ytnpqlum manishearth@google.com 2025-06-18 16:38:37 main@origin 1f5d17d2 |
| 80 | +│ [temporal] Add GetTemporalRelativeToOption, use it |
| 81 | +~ |
| 82 | +
|
| 83 | +$ jj cl-up |
| 84 | +Pushing from commit 556b213a122 [temporal] Add Add/Subtract to all Temporal types |
| 85 | +Enumerating objects: 16, done. |
| 86 | +Counting objects: 100% (16/16), done. |
| 87 | +Delta compression using up to 14 threads |
| 88 | +Compressing objects: 100% (11/11), done. |
| 89 | +Writing objects: 100% (11/11), 2.77 KiB | 61.00 KiB/s, done. |
| 90 | +Total 11 (delta 9), reused 0 (delta 0), pack-reused 0 (from 0) |
| 91 | +remote: Resolving deltas: 100% (9/9) |
| 92 | +remote: Waiting for private key checker: 3/3 objects left |
| 93 | +remote: Processing changes: refs: 1, new: 1, updated: 1, done |
| 94 | +remote: |
| 95 | +remote: SUCCESS |
| 96 | +remote: |
| 97 | +remote: https://chromium-review.googlesource.com/c/v8/v8/+/6654560 [temporal] Add `wrapped_rust()` helper for writing generic code [NEW] |
| 98 | +remote: https://chromium-review.googlesource.com/c/v8/v8/+/6653151 [temporal] Add Add/Subtract to all Temporal types |
| 99 | +remote: |
| 100 | +To sso://chromium/v8/v8.git |
| 101 | + * [new reference] 556b213a122d5a0dad5bdd5dd0a1485a303e9ea1 -> refs/for/main |
| 102 | +``` |
| 103 | +
|
| 104 | +Here, it pushed commits `zqlxpsus` and `slwvqnrr`, creating/updating changes for |
| 105 | +them. Change `xrvwxply` was also in the history but not pushed since it was |
| 106 | +already up to date upstream. Other changes were not pushed since they were not ancestors of `@`. |
| 107 | +
|
0 commit comments