-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,16 @@ pub(crate) struct CommitArgs { | |
/// Put these paths in the first commit | ||
#[arg(value_hint = clap::ValueHint::AnyPath)] | ||
paths: Vec<String>, | ||
/// Reset the author to the configured user | ||
/// | ||
/// This resets the author name, email, and timestamp. | ||
/// | ||
/// You can use it in combination with the JJ_USER and JJ_EMAIL | ||
/// environment variables to set a different author: | ||
/// | ||
/// $ JJ_USER='Foo Bar' [email protected] jj commit --reset-author | ||
#[arg(long)] | ||
reset_author: bool, | ||
} | ||
|
||
#[instrument(skip_all)] | ||
|
@@ -102,12 +112,16 @@ new working-copy commit. | |
edit_description(tx.base_repo(), &template, command.settings())? | ||
}; | ||
|
||
let new_commit = tx | ||
let mut commit_builder = tx | ||
.mut_repo() | ||
.rewrite_commit(command.settings(), &commit) | ||
.set_tree_id(tree_id) | ||
.set_description(description) | ||
.write()?; | ||
.set_description(description); | ||
if args.reset_author { | ||
let new_author = commit_builder.committer().clone(); | ||
commit_builder = commit_builder.set_author(new_author); | ||
} | ||
let new_commit = commit_builder.write()?; | ||
let workspace_ids = tx | ||
.mut_repo() | ||
.view() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -437,6 +437,13 @@ Update the description and create a new change on top | |
* `-i`, `--interactive` — Interactively choose which changes to include in the first commit | ||
* `--tool <NAME>` — Specify diff editor to be used (implies --interactive) | ||
* `-m`, `--message <MESSAGE>` — The change description to use (don't open editor) | ||
* `--reset-author` — Reset the author to the configured user | ||
This resets the author name, email, and timestamp. | ||
You can use it in combination with the JJ_USER and JJ_EMAIL environment variables to set a different author: | ||
$ JJ_USER='Foo Bar' [email protected] jj commit --reset-author | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,6 +217,52 @@ fn test_commit_paths_warning() { | |
"###); | ||
} | ||
|
||
#[test] | ||
fn test_commit_reset_author() { | ||
let test_env = TestEnvironment::default(); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
test_env.add_config( | ||
r#"[template-aliases] | ||
'format_signature(signature)' = 'signature.name() ++ " " ++ signature.email() ++ " " ++ signature.timestamp()'"#, | ||
); | ||
let get_signatures = || { | ||
test_env.jj_cmd_success( | ||
&repo_path, | ||
&[ | ||
"log", | ||
"-r@", | ||
"-T", | ||
r#"format_signature(author) ++ "\n" ++ format_signature(committer)"#, | ||
], | ||
) | ||
}; | ||
insta::assert_snapshot!(get_signatures(), @r###" | ||
@ Test User [email protected] 2001-02-03 04:05:07.000 +07:00 | ||
│ Test User [email protected] 2001-02-03 04:05:07.000 +07:00 | ||
~ | ||
"###); | ||
|
||
// Reset the author (the committer is always reset) | ||
test_env.jj_cmd_ok( | ||
&repo_path, | ||
&[ | ||
"commit", | ||
"--config-toml", | ||
r#"user.name = "Ove Ridder" | ||
user.email = "[email protected]""#, | ||
"--reset-author", | ||
"-m1", | ||
], | ||
); | ||
insta::assert_snapshot!(get_signatures(), @r###" | ||
@ Ove Ridder [email protected] 2001-02-03 04:05:09.000 +07:00 | ||
│ Ove Ridder [email protected] 2001-02-03 04:05:09.000 +07:00 | ||
~ | ||
"###); | ||
} | ||
|
||
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String { | ||
let template = r#"commit_id.short() ++ " " ++ description"#; | ||
test_env.jj_cmd_success(cwd, &["log", "-T", template]) | ||
|