From 088cc787b8dfcb79e75d48343eb1f5da0fadfd49 Mon Sep 17 00:00:00 2001 From: Vamsi Avula Date: Tue, 15 Aug 2023 09:36:10 +0530 Subject: [PATCH] cli: respect `ui.default-description` in split as well #2062 missed this. Partially addresses #1354. --- cli/src/commands/mod.rs | 15 +++++- cli/tests/test_split_command.rs | 85 +++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 4a5db0da3..1fc1aaf6b 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -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(), diff --git a/cli/tests/test_split_command.rs b/cli/tests/test_split_command.rs index 92e689ad9..363e6a754 100644 --- a/cli/tests/test_split_command.rs +++ b/cli/tests/test_split_command.rs @@ -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])