|
2 | 2 |
|
3 | 3 | The Gerrit-based workflow prefers small commits that get reviewed individually, |
4 | 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. |
| 5 | +can be a single CL which you can update over time. Each new update to a change |
| 6 | +is tracked as a new patchset, this will allow you to see how a |
| 7 | +change evolved over time directly in the UI. |
6 | 8 |
|
7 | 9 | ## Change IDs |
8 | 10 |
|
9 | 11 | 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 | | -
|
| 12 | +using a `Change-Id` footer in the commits. When using the `jj gerrit upload` |
| 13 | +command, the footer is added automatically to all commits in the revset that |
| 14 | +don't already have one. |
23 | 15 |
|
24 | 16 | ## Push workflow |
25 | 17 |
|
26 | 18 | In a traditional Gerrit workflow, you push commits to the review server using |
27 | 19 | `git push origin <rev>:refs/for/main`. |
28 | 20 |
|
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 | | -
|
| 21 | +JJ support this workflow natively thanks to the `jj gerrit upload` command. |
| 22 | +With this command you can upload revsets to Gerrit directly, if a JJ change is |
| 23 | +missing the change-id footer, the command will add it automatically. You can |
| 24 | +also modify the footer manually if you wish to associate a specific JJ change |
| 25 | +with an already existing Gerrit change. |
43 | 26 |
|
44 | | -The following alias makes uploading to Gerrit with `jj` convenient: |
| 27 | +If you want to triple check which commits will be modified and pushed with this |
| 28 | +command you can run `jj gerrit upload -r <revset> --remote-branch <branch-name> --dry-run` |
45 | 29 |
|
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 | | -``` |
| 30 | +### Remote branch selection |
57 | 31 |
|
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. |
| 32 | +When using `jj gerrit upload` you can either have a default remote branch |
| 33 | +selected or overwrite it with each upload. |
60 | 34 |
|
61 | | -Its output will look something like this: |
| 35 | +To configure a default remote branch please run: |
| 36 | +`jj config set --user gerrit.default-remote-branch <branch name>` |
62 | 37 |
|
63 | | -```console |
64 | | -$ jj |
65 | | -@ wtzvnrmz [email protected] 2025-06-18 18:29:08 f694f9f1 |
66 | | -│ (empty) (no description set) |
67 | | -○ zqlxpsus [email protected] 2025-06-18 18:29:08 git_head() 556b213a |
68 | | -│ [temporal] Add Add/Subtract to all Temporal types |
69 | | -│ ○ rnnrzqpt [email protected] 2025-06-18 18:29:08 8d16e5e5 |
70 | | -├─╯ [temporal] Add remaining .with() methods |
71 | | -○ slwvqnrr [email protected] 2025-06-18 18:28:52 e68229d4 |
72 | | -│ [temporal] Add `wrapped_rust()` helper for writing generic code |
73 | | -│ ○ vtszmlsx [email protected] 2025-06-18 18:25:38 c14b9e56 |
74 | | -├─╯ [temporal] Add PlainTime.{compare, with} |
75 | | -○ xrvwxply [email protected] 2025-06-18 18:24:28 f4ac4ff7 |
76 | | -│ [temporal] Add IsPartialTemporalObject |
77 | | -│ ○ tlmqwnpn [email protected] 2025-06-18 17:02:40 df3c2fa5 |
78 | | -├─╯ Fix comment about enable_rust |
79 | | -◆ ytnpqlum [email protected] 2025-06-18 16:38:37 main@origin 1f5d17d2 |
80 | | -│ [temporal] Add GetTemporalRelativeToOption, use it |
81 | | -~ |
| 38 | +while if you want to change it for a specific push you can do: |
| 39 | +`jj gerrit upload -r <revset> --remote-branch <branch-name>` |
82 | 40 |
|
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 | 41 |
|
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 | 42 |
|
0 commit comments