-
Notifications
You must be signed in to change notification settings - Fork 751
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | |
to fetch during clone. If present, the first matching branch is used as the | ||
working-copy parent. | ||
|
||
* 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`. | ||
Comment on lines
+73
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this is missing that it only runs for |
||
|
||
### Fixed bugs | ||
|
||
* `jj metaedit --author-timestamp` twice with the same value no longer | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1652,6 +1652,13 @@ to the current parents may contain changes from multiple commits. | |
) | ||
} | ||
|
||
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 commentThe 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 |
||
.evaluate_to_commits()? | ||
.try_collect()?) | ||
} | ||
|
||
pub fn id_prefix_context(&self) -> &IdPrefixContext { | ||
self.user_repo | ||
.id_prefix_context | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2025 The Jujutsu Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::collections::HashMap; | ||
|
||
use jj_lib::backend::CommitId; | ||
use jj_lib::fileset::FilesetExpression; | ||
|
||
use crate::cli_util::CommandHelper; | ||
use crate::command_error::CommandError; | ||
use crate::commands::fix::fix_revisions; | ||
use crate::ui::Ui; | ||
|
||
/// Triggered every time a user runs something that semantically approximates | ||
/// an "upload". | ||
/// | ||
/// 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`. | ||
Comment on lines
+28
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
/// | ||
/// This function may create transactions that rewrite commits, so is not | ||
/// allowed to be called while a transaction is ongoing. | ||
/// It returns a mapping of rewrites, and users are expected to update any | ||
/// references to point at the new revision. | ||
pub(crate) fn run_pre_upload_hooks( | ||
ui: &mut Ui, | ||
command: &CommandHelper, | ||
workspace_command: &mut crate::cli_util::WorkspaceCommandHelper, | ||
root_commits: &[CommitId], | ||
) -> Result<HashMap<CommitId, CommitId>, CommandError> { | ||
Ok(if command.settings().get_bool("hooks.pre-upload-fix")? { | ||
fix_revisions( | ||
ui, | ||
workspace_command, | ||
root_commits, | ||
&FilesetExpression::all().to_matcher(), | ||
false, | ||
)? | ||
} else { | ||
Default::default() | ||
}) | ||
} | ||
|
||
pub(crate) fn apply_rewrites( | ||
rewrites: &HashMap<CommitId, CommitId>, | ||
commits: Vec<CommitId>, | ||
) -> Vec<CommitId> { | ||
commits | ||
.into_iter() | ||
.map(|c| rewrites.get(&c).cloned().unwrap_or(c)) | ||
.collect() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1746,6 +1746,16 @@ eol-conversion = "input-output" | |
[`gitoxide`][gitoxide-is-binary] or [`git`][git-is-binary]. Jujutsu | ||
doesn't plan to align the binary detection logic with git. | ||
|
||
## Hook settings | ||
|
||
### Pre-upload hooks | ||
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. | ||
Comment on lines
+1752
to
+1757
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this is also missing the major caveat of it being |
||
|
||
## Ways to specify `jj` config: details | ||
|
||
### User config files | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,6 @@ name = "" | |
|
||
[working-copy] | ||
eol-conversion = "none" | ||
|
||
[hooks] | ||
pre-upload-fix = false |
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.