Skip to main content

A pre-commit integration for jj

Project description

jj-pre-push

PyPI

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:

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:

  1. Determines which bookmarks the corresponding jj git push will update on the remote, and how they would change.
  2. For each of these bookmarks in turn:
    • Checks out the bookmark to the working copy
    • 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 of new that 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.
  3. If all hooks succeeded on all branches, executes jj git push with the arguments provided; otherwise nothing is pushed.
  4. 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 prek

You can use jj-pre-push with any checker that has a CLI compatible with pre-commit, for example prek: specify the name of the checker program on the command-line as jj-pre-push --checker prek ..., or set the environment variable JJ_PRE_PUSH_CHECKER=prek.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jj_pre_push-0.3.5.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jj_pre_push-0.3.5-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file jj_pre_push-0.3.5.tar.gz.

File metadata

  • Download URL: jj_pre_push-0.3.5.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for jj_pre_push-0.3.5.tar.gz
Algorithm Hash digest
SHA256 f39f4f1677ca1508ca463aeea48c4748b801a47e2bc7afec6aae79d79a653c99
MD5 b7e8911b1167f31d13fde137c4f8de98
BLAKE2b-256 10d667f24a7f824e41dda33942213ec969c34bb489134e4b30697b686bac000a

See more details on using hashes here.

File details

Details for the file jj_pre_push-0.3.5-py3-none-any.whl.

File metadata

File hashes

Hashes for jj_pre_push-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c8e63a2b0f82818f723fea8f1da2cbbf5553350a036358e608984083f0a6182f
MD5 76ace135b980e30045febfdd276158c0
BLAKE2b-256 f063d265d628cb68c10eb19069bb756b92e2018988ca5bddeee31d2323c2eb19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page