cli: respect ui.default-description in split as well

#2062 missed this. Partially addresses #1354.
This commit is contained in:
Vamsi Avula 2023-08-15 09:36:10 +05:30
parent dc6e1d7dee
commit 088cc787b8
2 changed files with 98 additions and 2 deletions

View file

@ -3004,6 +3004,7 @@ fn description_template_for_commit(
fn description_template_for_cmd_split(
ui: &Ui,
command: &CommandHelper,
workspace_command: &WorkspaceCommandHelper,
intro: &str,
overall_commit_description: &str,
@ -3020,8 +3021,16 @@ fn description_template_for_cmd_split(
&EverythingMatcher,
&[DiffFormat::Summary],
)?;
Ok(format!("JJ: {intro}\n{overall_commit_description}\n")
+ &diff_summary_to_description(&diff_summary_bytes))
let description = if overall_commit_description.is_empty() {
command
.settings()
.config()
.get_string("ui.default-description")
.unwrap_or("".to_owned())
} else {
overall_commit_description.to_owned()
};
Ok(format!("JJ: {intro}\n{description}\n") + &diff_summary_to_description(&diff_summary_bytes))
}
fn diff_summary_to_description(bytes: &[u8]) -> String {
@ -3078,6 +3087,7 @@ don't make any changes, then the operation will be aborted.
let first_template = description_template_for_cmd_split(
ui,
command,
tx.base_workspace_helper(),
"Enter commit description for the first part (parent).",
commit.description(),
@ -3093,6 +3103,7 @@ don't make any changes, then the operation will be aborted.
.write()?;
let second_template = description_template_for_cmd_split(
ui,
command,
tx.base_workspace_helper(),
"Enter commit description for the second part (child).",
commit.description(),

View file

@ -135,6 +135,91 @@ fn test_split_by_paths() {
"###);
}
#[test]
fn test_split_with_non_empty_description() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.add_config(r#"ui.default-description = "\n\nTESTED=TODO""#);
let workspace_path = test_env.env_root().join("repo");
std::fs::write(workspace_path.join("file1"), "foo\n").unwrap();
std::fs::write(workspace_path.join("file2"), "bar\n").unwrap();
test_env.jj_cmd_success(&workspace_path, &["describe", "-m", "test"]);
let edit_script = test_env.set_up_fake_editor();
std::fs::write(
edit_script,
["dump editor1", "next invocation\n", "dump editor2"].join("\0"),
)
.unwrap();
test_env.jj_cmd_success(&workspace_path, &["split", "file1"]);
assert_eq!(
std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(),
r#"JJ: Enter commit description for the first part (parent).
test
JJ: This commit contains the following changes:
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).
test
JJ: This commit contains the following changes:
JJ: A file2
JJ: Lines starting with "JJ: " (like this one) will be removed.
"#
);
}
#[test]
fn test_split_with_default_description() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
test_env.add_config(r#"ui.default-description = "\n\nTESTED=TODO""#);
let workspace_path = test_env.env_root().join("repo");
std::fs::write(workspace_path.join("file1"), "foo\n").unwrap();
std::fs::write(workspace_path.join("file2"), "bar\n").unwrap();
let edit_script = test_env.set_up_fake_editor();
std::fs::write(
edit_script,
["dump editor1", "next invocation\n", "dump editor2"].join("\0"),
)
.unwrap();
test_env.jj_cmd_success(&workspace_path, &["split", "file1"]);
assert_eq!(
std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(),
r#"JJ: Enter commit description for the first part (parent).
TESTED=TODO
JJ: This commit contains the following changes:
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.
"#
);
}
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
let template = r#"change_id.short() ++ " " ++ empty"#;
test_env.jj_cmd_success(cwd, &["log", "-T", template])