-
Notifications
You must be signed in to change notification settings - Fork 750
hooks: Add support for running jj fix
as a pre-upload hook.
#7801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
2d9fb18
to
5e574e4
Compare
We will support arbitrary hooks in the future, but for a few reasons we will special-case `jj fix`: * Performance (jj fix is hyper-optimized for running on stacks of commits at the same time) * Common (This will probably be the most common requested pre-upload check) * Simplicity (this was much easier to implement, so is a good first hook) Bug: jj-vcs#3577
5e574e4
to
38f4ab3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor stuff, I also don't really agree with how the code currently was rewritten but I'm unable to point at it.
cc @hooper
* Added the first hook to jj - a pre-upload hook that runs `jj fix` before | ||
uploading. Toggled via the config flag `hooks.pre-upload-fix`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is missing that it only runs for gerrit upload
which isn't such a common workflow for most people.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: In the commit description you could mention that "you" (i.e the chromium project) scripted around that which is imo a good motivation.
/// Currently, this triggers on `jj gerrit upload`. Other forges which | ||
/// implement custom upload scripts should also call this. | ||
/// | ||
/// This should ideally work for `jj git push` too, but doing so has | ||
/// consequences. `git push` can be used to upload to code review, but it can | ||
/// do many other things as well. We need to ensure the UX works well before | ||
/// adding it to `git push`. |
There was a problem hiding this comment.
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 advertise this as "general hook" support. Since it is the only support we'll ever have
Pre-upload hooks are triggered when you upload your code for code review. | ||
|
||
The special config flag `hooks.pre-upload-fix = true` flag can be set to run | ||
`jj fix` before uploading your code. | ||
|
||
Support for more generic hooks will be added in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is also missing the major caveat of it being gerrit upload
only
We already have some "on push" behavior, namely signing. I had an old diff I never upstreamed that added a new flag called diff --git a/cli/src/commands/git/push.rs b/cli/src/commands/git/push.rs
index 88403257ea..fee554e83b 100644
--- a/cli/src/commands/git/push.rs
+++ b/cli/src/commands/git/push.rs
@@ -393,7 +393,7 @@
return Ok(());
}
- let sign_behavior = if tx.settings().get_bool("git.sign-on-push")? {
+ let sign_behavior = if should_sign_on_push(tx.settings())? {
Some(SignBehavior::Own)
} else {
None
@@ -1016,3 +1016,15 @@
.collect_vec();
Ok(bookmarks_targeted)
}
+
+fn should_sign_on_push(settings: &UserSettings) -> Result<bool, CommandError> {
+ // First check the new on-push-behavior configuration
+ if let Ok(behaviors) = settings.get::<Vec<String>>("git.on-push-behavior") {
+ return Ok(behaviors.contains(&"sign".to_string()));
+ } else if let Some(behavior) = settings.get_string("git.on-push-behavior").optional()? {
+ return Ok(behavior == "sign");
+ }
+
+ // Fall back to the old sign-on-push configuration for backward compatibility
+ settings.get_bool("git.sign-on-push").map_err(Into::into)
+}
diff --git a/cli/src/config-schema.json b/cli/src/config-schema.json
index e4ed1a4c81..da11add710 100644
--- a/cli/src/config-schema.json
+++ b/cli/src/config-schema.json
@@ -468,6 +468,22 @@
"description": "Whether jj should sign commits before pushing",
"default": false
},
+ "on-push-behavior": {
+ "description": "List of behaviors to execute before pushing",
+ "oneOf": [
+ {
+ "type": "string",
+ "enum": ["sign"]
+ },
+ {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "enum": ["sign"]
+ }
+ }
+ ]
+ },
"track-default-bookmark-on-clone": {
"type": "boolean",
"description": "Whether `jj git clone` creates a local bookmark tracking the default remote bookmark", I had then wanted to extend FWIW, I'm not so sure about special casing it only on |
I agree but ideally we really shouldn't run untrusted programs but should use user-aliases instead. This will let users plug a bunch of with the model. And matching on bookmark patterns also makes sense. |
|
||
pub fn commits(&self, commits: Vec<CommitId>) -> Result<Vec<Commit>, CommandError> { | ||
Ok(self | ||
.attach_revset_evaluator(RevsetExpression::commits(commits)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's necessary to use a revset for this. Maybe a better way would be to use self.repo().store().get_commit(commit_id)
directly? That's what evaluate_to_commits()
uses internally anyway.
We will support arbitrary hooks in the future, but for a few reasons we will special-case
jj fix
:Bug: #3577
Checklist
If applicable:
CHANGELOG.md
README.md
,docs/
,demos/
)cli/src/config-schema.json
)