Skip to content

Conversation

DanieleSassoli
Copy link

@DanieleSassoli DanieleSassoli commented Sep 1, 2025

This PR depends on @matts1 change that addst the Gerrit upload
command.

I should add, I'm very new to JJ and this is my first contribution.
Please let me know if I did anything wrong.

Checklist

If applicable:

  • [N/A] I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • [N/A] I have updated the config schema (cli/src/config-schema.json)
  • [N/A] I have added/updated tests to cover my changes

@DanieleSassoli DanieleSassoli requested a review from a team as a code owner September 1, 2025 09:58
@DanieleSassoli DanieleSassoli changed the base branch from main to aseipp/push-uytvkxyqyspn September 1, 2025 09:58
@DanieleSassoli DanieleSassoli changed the title Add gerrit docs Add Working with Gerrit docs Sep 1, 2025
@DanieleSassoli DanieleSassoli changed the title Add Working with Gerrit docs docs: add working with gerrit section Sep 1, 2025
@PhilipMetzger
Copy link
Contributor

PhilipMetzger commented Sep 1, 2025

This in general looks good to me, but your patch is failing the CI because the commit title not the PR title should be docs: <your-title> so to fix it copy the current PR title to the commit description and re-push it again.

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.
Copy link
Contributor

@matts1 matts1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks pretty good, but 3 main focus areas:

  • User guides should focus on how a user interacts with something, rather than the technical details of how it works under the hood
  • You make a lot of assumptions about the user's workflow, in particular @- vs @. JJ does not distinguish these. You're welcome to use @- in your examples, but we should avoid making assumptions and saying things like "@- is the last non-empty commit"
  • One thing it appears you've missed in how the command works is that when you push to gerrit, you are pushing not just a single commit, but a stack of changes. So your usage of trunk()..@- are equivalent to @-


```shell
# Option 1: Start JJ in an existing Git repo with Gerrit remotes
$ jj git init --colocate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be an option 3: jj git clone

```

You can configure default values in your repository config by appending the
below to `.jj/repo/config.toml`, like so:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a note that this is generally only useful for option 2

## Basic workflow

`jj gerrit upload` takes one or more revsets, ensures each selected commit has a
Gerrit-compatible `Change-Id:` footer (adding one if missing), and pushes the
Copy link
Contributor

@matts1 matts1 Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is phrased from a technical perspective of how it works, rather than from the perspective of a user. I suggest:
jj gerrit upload takes one or more revsets, and uploads the stack of commits ending in them to gerrit. Each JJ change will map to a single gerrit change based on the JJ change id. This should be what you want most of the time, but if you want to associate a JJ change with a specific change already uploaded to gerrit, you can copy the Change-Id footer from gerrit to the bottom of the commit description in JJ.

### upload a single change

```shell
# upload the last real commit (@-) for review to main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should call this the "last real commit". @ is a real commit too (in the sense that it has a commit object associated with it). Your interpretation of "last real commit" also assumes the squash workflow, rather than the edit workflow, both of which work just fine with jj gerrit upload.

See the [revsets](./revsets.md) guide for more.

> Warning
> The working-copy commit `@` is empty and is rejected. Use `@-` or another
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is making another assumption about workflows that isn't necessarily true for everyone. Empty commits are rejected. I usually upload @, and my @ is non-empty.


## Updating changes after review

To address review feedback, amend or rewrite your commits, then run `jj gerrit
Copy link
Contributor

@matts1 matts1 Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/amend or rewrite your commits/update your revisions.

Amend is a bit of an overloaded term, and we work with revisions / changes in jj, not commits

## Updating changes after review

To address review feedback, amend or rewrite your commits, then run `jj gerrit
upload` again with the same revsets. Because the `Change-Id` footer is preserved,
Copy link
Contributor

@matts1 matts1 Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this is a user guide, can we remove the "Because the change-ID footer is preserved". This is another one of those things that the user doesn't need to know. All they need to know is "I say upload, and it updates an existing gerrit change because I already uploaded it"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change-Id is a trailer. I believe gerrit used to use the term footer, but it seems now git officially supports them, they're trailers, and JJ also uses the term trailer.

Since we've already mentioned the trailer earlier (well, see my previous comment) we could probably omit repeating it here?

## Target branch and remote selection

You must specify the target branch for review with `--for <branch>` or by
configuring `[gerrit].default_for`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the technical details. From a user's perspective, they simply need to know:

  • Please run jj config set --user gerrit.default_for <branch name> to set your default branch across all repos
  • Please run jj config set --repo gerrit.default_for <branch name> to set your default branch for this specific repo.
  • Use --for <branch name> to override this for one specific occasion.

You must specify the target branch for review with `--for <branch>` or by
configuring `[gerrit].default_for`.

The remote used to push is determined as follows:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, more technical details. What the user needs to know

  • If your upload isn't going to gerrit, run jj config set --repo gerrit.default_remote <gerrit remote name>
  • To upload to a specific remote as a one-off thing, use --remote <remote name>

without changing anything or contacting the remote.

```shell
$ jj gerrit upload -r 'trunk()..@-' --for main --dry-run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned before, trunk()..@- isn't required

@matts1
Copy link
Contributor

matts1 commented Sep 2, 2025

I've updated the docstrings for the commands in the original pr, since the behaviour around stacked commits was very non-obvious.

resulting heads to `refs/for/<branch>` on your Gerrit remote.

> Note
> Gerrit identifies and updates changes by `Change-Id`. When you reupload a
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth being explicit and mentioning that Change-Id is a commit trailer?

Copy link
Contributor

@PhilipMetzger PhilipMetzger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just minor stuff

- `-r 'trunk()..@-'`: everything on top of trunk
- `-r 'A..B'`: commits reachable from `B` but not `A`

See the [revsets](./revsets.md) guide for more.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove ./ as we generally use relative links

$ jj gerrit upload -r 'xcv'
```

## Future: native Jujutsu metadata in Gerrit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Matt since we already have a familiar wording in the FAQ. The thing Daniel could do is link out to Gerrits design doc though.

Comment on lines +9 to +10
client. In practice, that means small, clean commits that evolve over
time—exactly how Gerrit wants you to work.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
client. In practice, that means small, clean commits that evolve over
time—exactly how Gerrit wants you to work.
client. In practice, that means small, clean commits that evolve over time,
exactly how Gerrit wants you to work.

$ jj git init --colocate

# Option 2: Add a Gerrit remote to a JJ repo
$ jj git remote add gerrit ssh://gerrit.example.com:29418/your/project

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$ jj git remote add gerrit ssh://gerrit.example.com:29418/your/project
$ jj git remote add gerrit https://review.gerrithub.io/yourname/yourproject

If you use Git/HTTPS is going to be more similar to a real production use; also using GerritHub.io could help people experimenting it without having to setup Gerrit at all.

4. A Git remote named `gerrit`, if present
5. Otherwise, the command errors

## Updating changes after review

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Updating changes after review
## Uploading a new patch-set to an existing Change


## Updating changes after review

To address review feedback, amend or rewrite your commits, then run `jj gerrit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To address review feedback, amend or rewrite your commits, then run `jj gerrit
To rework an existing Change, amending the content or rewrite the commit comments, then run `jj gerrit

Comment on lines +110 to +113
The Gerrit project is exploring support for native Jujutsu metadata ("jj
headers") so Gerrit could understand Jujutsu change identity without requiring
`Change-Id` footers. Until then, `jj gerrit upload` will add a Gerrit-compatible
`Change-Id` when needed and push to `refs/for/<branch>`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this is pretty much up in the air and subject to change; I'd just remove it for now.

Comment on lines +114 to +115


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: empty lines

@@ -23,4 +23,5 @@ You may want to jump to:
- [Installation and Setup](install-and-setup.md)
- [Tutorial and Birds-Eye View](tutorial.md)
- [Working with GitHub](github.md)
- [Working with Gerrit](gerrit.md)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just sort them alphabetically to avoid being biased on the order.

@@ -92,6 +92,7 @@ nav:
- 'Installation and Setup': 'install-and-setup.md'
- 'Tutorial and Birds-Eye View': 'tutorial.md'
- 'Working with GitHub': 'github.md'
- 'Working with Gerrit': 'gerrit.md'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: let's sort them alphabetically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants