Skip to content

Commit 9342158

Browse files
docs: add working with gerrit section
Currently there are instructions on how to setup jj to work with GitHub, but not Gerrit, which seems to be very popular with the jj community. Add a gerrit.md file to help users discover the jj gerrit subcommand.
1 parent 83b9b3a commit 9342158

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

docs/gerrit.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Using Jujutsu with Gerrit Code Review
2+
3+
JJ and Gerrit share the same mental model, which makes Gerrit feel like a
4+
natural collaboration tool for JJ. JJ tracks a "change identity" across
5+
rewrites, and Gerrit’s `Change-Id` tracks the same logical change across patch
6+
sets. JJ and Gerrit's `Change-Id`s aren’t natively compatible yet, but they’re
7+
philosophically aligned. `jj gerrit upload` bridges the gap today by adding a
8+
Gerrit-style `Change-Id` while JJ keeps its own notion of change identity on the
9+
client. In practice, that means small, clean commits that evolve over
10+
time—exactly how Gerrit wants you to work.
11+
12+
This guide assumes a basic understanding of Git, Gerrit, and Jujutsu.
13+
14+
## Set up a Gerrit remote
15+
16+
Jujutsu communicates with Gerrit by pushing commits to a Git remote. If you're
17+
starting from an existing Git repository with Gerrit remotes already configured,
18+
you can use `jj git init --colocate` to start using JJ in that repo. Otherwise,
19+
set up your Gerrit remote.
20+
21+
```shell
22+
# Option 1: Start JJ in an existing Git repo with Gerrit remotes
23+
$ jj git init --colocate
24+
25+
# Option 2: Add a Gerrit remote to a JJ repo
26+
$ jj git remote add gerrit ssh://gerrit.example.com:29418/your/project
27+
```
28+
29+
You can configure default values in your repository config by appending the
30+
below to `.jj/repo/config.toml`, like so:
31+
32+
```toml
33+
[gerrit]
34+
default_remote = "gerrit" # name of the Git remote to push to
35+
default_for = "main" # target branch in Gerrit
36+
```
37+
38+
## Basic workflow
39+
40+
`jj gerrit upload` takes one or more revsets, ensures each selected commit has a
41+
Gerrit-compatible `Change-Id:` footer (adding one if missing), and pushes the
42+
resulting heads to `refs/for/<branch>` on your Gerrit remote.
43+
44+
> Note
45+
> Gerrit identifies and updates changes by `Change-Id`. When you reupload a
46+
> commit with the same `Change-Id`, Gerrit creates a new patch set.
47+
48+
### upload a single change
49+
50+
```shell
51+
# upload the last real commit (@-) for review to main
52+
$ jj gerrit upload -r @-
53+
```
54+
55+
## Selecting revisions (revsets)
56+
57+
`jj gerrit upload` accepts one or more `-r/--revisions` arguments. Each argument
58+
may expand to multiple commits. Common patterns:
59+
60+
- `-r @-`: the last non-empty commit
61+
- `-r 'trunk()..@-'`: everything on top of trunk
62+
- `-r 'A..B'`: commits reachable from `B` but not `A`
63+
64+
See the [revsets](./revsets.md) guide for more.
65+
66+
> Warning
67+
> The working-copy commit `@` is empty and is rejected. Use `@-` or another
68+
> concrete commit.
69+
70+
### Preview without pushing
71+
72+
Use `--dry-run` to see which commits would be modified and pushed, and where,
73+
without changing anything or contacting the remote.
74+
75+
```shell
76+
$ jj gerrit upload -r 'trunk()..@-' --for main --dry-run
77+
```
78+
79+
## Target branch and remote selection
80+
81+
You must specify the target branch for review with `--for <branch>` or by
82+
configuring `[gerrit].default_for`.
83+
84+
The remote used to push is determined as follows:
85+
86+
1. `--remote <name>` if provided
87+
2. `[gerrit].default_remote` if configured
88+
3. The sole configured Git remote, if exactly one exists
89+
4. A Git remote named `gerrit`, if present
90+
5. Otherwise, the command errors
91+
92+
## Updating changes after review
93+
94+
To address review feedback, amend or rewrite your commits, then run `jj gerrit
95+
upload` again with the same revsets. Because the `Change-Id` footer is preserved,
96+
Gerrit will add new patch sets to the existing changes instead of creating new
97+
ones.
98+
99+
Examples:
100+
101+
```shell
102+
# Edit and squash into an earlier commit in the stack
103+
$ jj edit xcv # position on the stack to edit
104+
--- Apply needed edits ---
105+
$ jj gerrit upload -r 'xcv'
106+
```
107+
108+
## Future: native Jujutsu metadata in Gerrit
109+
110+
The Gerrit project is exploring support for native Jujutsu metadata ("jj
111+
headers") so Gerrit could understand Jujutsu change identity without requiring
112+
`Change-Id` footers. Until then, `jj gerrit upload` will add a Gerrit-compatible
113+
`Change-Id` when needed and push to `refs/for/<branch>`.
114+
115+

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ You may want to jump to:
2323
- [Installation and Setup](install-and-setup.md)
2424
- [Tutorial and Birds-Eye View](tutorial.md)
2525
- [Working with GitHub](github.md)
26+
- [Working with Gerrit](gerrit.md)
2627
- [Development Roadmap](roadmap.md)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ nav:
9292
- 'Installation and Setup': 'install-and-setup.md'
9393
- 'Tutorial and Birds-Eye View': 'tutorial.md'
9494
- 'Working with GitHub': 'github.md'
95+
- 'Working with Gerrit': 'gerrit.md'
9596
- 'Working on Windows': 'windows.md'
9697

9798
- FAQ: 'FAQ.md'

0 commit comments

Comments
 (0)