ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: when splitting change without description, skip it on second part

One use case for `jj split` is when creating a new commit from some of
the changes in the working copy. If there's no description on the
working-copy commit in that case, it seems better to not ask the user
to provide one when they're splitting the commit either.
This commit is contained in:
Martin von Zweigbergk 2023-08-15 09:35:45 -07:00 committed by Martin von Zweigbergk
parent 2685d4a64a
commit 873634a80e
3 changed files with 45 additions and 36 deletions

View file

@ -69,6 +69,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`ui.default-description` option, to use when describing changes with an empty
description.
* `jj split` will now leave the description empty on the second part if the
description was empty on the input commit.
### Fixed bugs
* `jj config set --user` and `jj config edit --user` can now be used outside of any repository.

View file

@ -793,7 +793,12 @@ struct DiffeditArgs {
/// Edit the right side of the diff until it has the content you want in the
/// first revision. Once you close the editor, your edited content will replace
/// the previous revision. The remaining changes will be put in a new revision
/// on top. You will be asked to enter a change description for each.
/// on top.
///
/// If the change you split had a description, you will be asked to enter a
/// change description for each commit. If the change did not have a
/// description, the second part will not get a description, and you will be
/// asked for a description only for the first part.
#[derive(clap::Args, Clone, Debug)]
struct SplitArgs {
/// The revision to split
@ -3095,17 +3100,21 @@ don't make any changes, then the operation will be aborted.
.set_tree(tree_id)
.set_description(first_description)
.write()?;
let second_template = description_template_for_cmd_split(
ui,
command.settings(),
tx.base_workspace_helper(),
"Enter commit description for the second part (child).",
commit.description(),
&middle_tree,
&commit.tree(),
)?;
let second_description =
edit_description(tx.base_repo(), &second_template, command.settings())?;
let second_description = if commit.description().is_empty() {
// If there was no description before, don't ask for one for the second commit.
"".to_string()
} else {
let second_template = description_template_for_cmd_split(
ui,
command.settings(),
tx.base_workspace_helper(),
"Enter commit description for the second part (child).",
commit.description(),
&middle_tree,
&commit.tree(),
)?;
edit_description(tx.base_repo(), &second_template, command.settings())?
};
let second_commit = tx
.mut_repo()
.rewrite_commit(command.settings(), &commit)

View file

@ -55,16 +55,7 @@ fn test_split_by_paths() {
JJ: Lines starting with "JJ: " (like this one) will be removed.
"###);
insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(), @r###"
JJ: Enter commit description for the second part (child).
JJ: This commit contains the following changes:
JJ: A file1
JJ: A file3
JJ: Lines starting with "JJ: " (like this one) will be removed.
"###);
assert!(!test_env.env_root().join("editor1").exists());
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ kkmpptxzrspx false
@ -148,7 +139,14 @@ fn test_split_with_non_empty_description() {
let edit_script = test_env.set_up_fake_editor();
std::fs::write(
edit_script,
["dump editor1", "next invocation\n", "dump editor2"].join("\0"),
[
"dump editor1",
"write\npart 1",
"next invocation\n",
"dump editor2",
"write\npart 2",
]
.join("\0"),
)
.unwrap();
test_env.jj_cmd_success(&workspace_path, &["split", "file1"]);
@ -175,6 +173,11 @@ JJ: A file2
JJ: Lines starting with "JJ: " (like this one) will be removed.
"#
);
insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
@ kkmpptxzrspx false part 2
qpvuntsmwlqt false part 1
zzzzzzzzzzzz true
"###);
}
#[test]
@ -206,21 +209,15 @@ JJ: A file1
JJ: Lines starting with "JJ: " (like this one) will be removed.
"#
);
assert_eq!(
std::fs::read_to_string(test_env.env_root().join("editor2")).unwrap(),
r#"JJ: Enter commit description for the second part (child).
TESTED=TODO
JJ: This commit contains the following changes:
JJ: A file2
JJ: Lines starting with "JJ: " (like this one) will be removed.
"#
);
assert!(!test_env.env_root().join("editor2").exists());
insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
@ rlvkpnrzqnoo false
qpvuntsmwlqt false TESTED=TODO
zzzzzzzzzzzz true
"###);
}
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
let template = r#"change_id.short() ++ " " ++ empty"#;
let template = r#"separate(" ", change_id.short(), empty, description)"#;
test_env.jj_cmd_success(cwd, &["log", "-T", template])
}