forked from mirrors/jj
commit: add --reset-author
option
This commit is contained in:
parent
b06b65b355
commit
e54ecefbd4
4 changed files with 72 additions and 3 deletions
|
@ -79,6 +79,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
commits with no description) if authored by the current user.
|
||||
[#2000](https://github.com/martinvonz/jj/issues/2000)
|
||||
|
||||
* `jj commit` now accepts `--reset-author` option to match `jj describe`.
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
* `jj git push` now ignores immutable commits when checking whether a
|
||||
|
|
|
@ -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' JJ_EMAIL=foo@bar.com 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()
|
||||
|
|
|
@ -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' JJ_EMAIL=foo@bar.com jj commit --reset-author
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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 test.user@example.com 2001-02-03 04:05:07.000 +07:00
|
||||
│ Test User test.user@example.com 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 = "ove.ridder@example.com""#,
|
||||
"--reset-author",
|
||||
"-m1",
|
||||
],
|
||||
);
|
||||
insta::assert_snapshot!(get_signatures(), @r###"
|
||||
@ Ove Ridder ove.ridder@example.com 2001-02-03 04:05:09.000 +07:00
|
||||
│ Ove Ridder ove.ridder@example.com 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])
|
||||
|
|
Loading…
Reference in a new issue