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 `ui.default-description` option, to use when describing changes with an empty
description. description.
* `jj split` will now leave the description empty on the second part if the
description was empty on the input commit.
### Fixed bugs ### Fixed bugs
* `jj config set --user` and `jj config edit --user` can now be used outside of any repository. * `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 /// 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 /// 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 /// 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)] #[derive(clap::Args, Clone, Debug)]
struct SplitArgs { struct SplitArgs {
/// The revision to split /// The revision to split
@ -3095,17 +3100,21 @@ don't make any changes, then the operation will be aborted.
.set_tree(tree_id) .set_tree(tree_id)
.set_description(first_description) .set_description(first_description)
.write()?; .write()?;
let second_template = description_template_for_cmd_split( let second_description = if commit.description().is_empty() {
ui, // If there was no description before, don't ask for one for the second commit.
command.settings(), "".to_string()
tx.base_workspace_helper(), } else {
"Enter commit description for the second part (child).", let second_template = description_template_for_cmd_split(
commit.description(), ui,
&middle_tree, command.settings(),
&commit.tree(), tx.base_workspace_helper(),
)?; "Enter commit description for the second part (child).",
let second_description = commit.description(),
edit_description(tx.base_repo(), &second_template, command.settings())?; &middle_tree,
&commit.tree(),
)?;
edit_description(tx.base_repo(), &second_template, command.settings())?
};
let second_commit = tx let second_commit = tx
.mut_repo() .mut_repo()
.rewrite_commit(command.settings(), &commit) .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. JJ: Lines starting with "JJ: " (like this one) will be removed.
"###); "###);
insta::assert_snapshot!( assert!(!test_env.env_root().join("editor1").exists());
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.
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ kkmpptxzrspx false @ kkmpptxzrspx false
@ -148,7 +139,14 @@ fn test_split_with_non_empty_description() {
let edit_script = test_env.set_up_fake_editor(); let edit_script = test_env.set_up_fake_editor();
std::fs::write( std::fs::write(
edit_script, 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(); .unwrap();
test_env.jj_cmd_success(&workspace_path, &["split", "file1"]); 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. 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] #[test]
@ -206,21 +209,15 @@ JJ: A file1
JJ: Lines starting with "JJ: " (like this one) will be removed. JJ: Lines starting with "JJ: " (like this one) will be removed.
"# "#
); );
assert_eq!( assert!(!test_env.env_root().join("editor2").exists());
std::fs::read_to_string(test_env.env_root().join("editor2")).unwrap(), insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
r#"JJ: Enter commit description for the second part (child). @ rlvkpnrzqnoo false
qpvuntsmwlqt false TESTED=TODO
zzzzzzzzzzzz true
TESTED=TODO "###);
JJ: This commit contains the following changes:
JJ: A file2
JJ: Lines starting with "JJ: " (like this one) will be removed.
"#
);
} }
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String { 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]) test_env.jj_cmd_success(cwd, &["log", "-T", template])
} }