A pre-commit integration for jj
Project description
jj-pre-push
A very limited integration between jj and pre-commit allowing you to run your pre-push hooks in a colocated jj/git repository.
I don't expect this to last forever, it's just a stopgap until some jj-native mechanism arrives that can take over.
Prior art:
- https://www.aazuspan.dev/blog/automating-pre-push-checks-with-jujutsu/
- Various comments on https://github.com/jj-vcs/jj/issues/405
Usage
Use jj-pre-push push (or an alias - personally I use jj push) as a replacement for
jj git push. It takes all the same arguments, and does the following:
-
Determines which bookmarks the corresponding
jj git pushwill update on the remote, and how they would change. -
For each of these bookmarks in turn:
- Checks out the bookmark to the working copy (or uses the existing working commit if it is empty and based on the bookmark).
- Runs the pre-push hooks defined in your .pre-commit-config.yaml on the same set of
files pre-commit would when pushing the same change. (For existing branches that's
the files touched in the range
old...new; for new branches it's the files touched in all ancestors ofnewthat aren't present on the remote.) - Reports any failures; and if any files were modified reports the change ID(s) in which these modifications can be found.
[!NOTE] If your current working commit is empty and is a direct child of the bookmark being checked,
jj-pre-pushwill run the checks directly in that working commit instead of creating a new one. Any modifications made by the hooks will be preserved in your working commit, ready to be diffed or squashed. -
If all hooks succeeded on all branches, executes
jj git pushwith the arguments provided; otherwise nothing is pushed. -
Returns the working copy to its original change.
If there is no .pre-commit-config.yaml in your workspace root, jj-pre-push push
immediately delegates to jj git push.
By default jj-pre-push produces no console output of its own unless hooks fail. If
you'd like to see more details about what's happening, you can use jj-pre-push --log-level=INFO push.
Installation
If you have uv installed and you're planning to use an
alias anyway, you can avoid explicitly installing at all with uvx, e.g. with this jj
configuration for jj push:
[aliases]
push = ["util", "exec", "--", "uvx", "jj-pre-push", "push"]
Otherwise, install the PyPI package jj-pre-push in whichever way you prefer; e.g. uv tool install jj-pre-push or pip install jj-pre-push, and use jj-pre-push push as
described earlier.
Usage with jjui
If you're a jjui fan (I think maybe you should be!),
here's an example jjui/config.toml snippet showing how you can define custom actions
to invoke jj-pre-push: one to perform the default jj push, and one to push the
bookmarks attached to the change you have currently selected in the UI. I've also added
some examples of key sequence bindings to perform these actions.
[[actions]]
name = "jj-push"
lua = '''
jj_async("push")
revisions.refresh()
'''
[[actions]]
name = "jj-push-selected"
lua = '''
jj_async("push", "-r", context.commit_id())
revisions.refresh()
'''
[[bindings]]
action = "jj-push"
seq = ["x", "p"]
scope = "revisions"
desc = "jj push"
[[bindings]]
action = "jj-push-selected"
seq = ["x", "P"]
scope = "revisions"
desc = "jj push selected bookmark(s)"
Note that these depend upon the jj push alias defined in the previous section.
Usage with other checkers/hook managers
jj-pre-push has rudimentary support for checkers other than pre-commit - to use a
different checker, specify its name on the command line with jj-pre-push --checker CHECKER ... or set the environment variable JJ_PRE_PUSH_CHECKER. Supported checkers:
pre-commitprek, or any other checker with a pre-commit-compatible CLIhk
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jj_pre_push-0.5.0.tar.gz.
File metadata
- Download URL: jj_pre_push-0.5.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f2d1ce38f2a8c7fe0e7036af8c89e162df9aac9e6ab84796661a346cf068829
|
|
| MD5 |
d4c8fdb5a89bee85fa68ec7e37d36327
|
|
| BLAKE2b-256 |
ab03e43f5de5829a6efad0f87e85cf105485b44294f914da8685eb44c6c9297a
|
File details
Details for the file jj_pre_push-0.5.0-py3-none-any.whl.
File metadata
- Download URL: jj_pre_push-0.5.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dd592c4d1d1e47f727f26184624c6633ad866d843b24ccfd7676f69ede5d459
|
|
| MD5 |
b94faaaabbf0dfccf6ad9b87ced9e646
|
|
| BLAKE2b-256 |
47a494528a9bfeff5a54c1d01e987e1f30bac0adbe1cf2c624411b9925c0879e
|