diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 5d350d0fa0..3cc7e91eba 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -1746,6 +1746,11 @@ impl WorkspaceCommandTransaction<'_> { ) -> Result { let base_ignores = self.helper.base_ignores()?; let settings = &self.helper.settings; + let instructions = if settings.diff_instructions() { + instructions + } else { + None + }; Ok(crate::merge_tools::edit_diff( ui, left_tree, diff --git a/cli/src/merge_tools/external.rs b/cli/src/merge_tools/external.rs index 15c58d5797..ddf65ab57e 100644 --- a/cli/src/merge_tools/external.rs +++ b/cli/src/merge_tools/external.rs @@ -17,7 +17,6 @@ use jj_lib::matchers::Matcher; use jj_lib::merge::{Merge, MergedTreeValue}; use jj_lib::merged_tree::{MergedTree, MergedTreeBuilder}; use jj_lib::repo_path::{RepoPath, RepoPathBuf}; -use jj_lib::settings::UserSettings; use jj_lib::store::Store; use jj_lib::working_copy::{CheckoutError, SnapshotOptions}; use pollster::FutureExt; @@ -429,7 +428,6 @@ pub fn edit_diff_external( matcher: &dyn Matcher, instructions: Option<&str>, base_ignores: Arc, - settings: &UserSettings, ) -> Result { let got_output_field = find_all_variables(&editor.edit_args).contains(&"output"); let store = left_tree.store(); @@ -452,8 +450,7 @@ pub fn edit_diff_external( let instructions_path_to_cleanup = output_wc_path.join("JJ-INSTRUCTIONS"); // In the unlikely event that the file already exists, then the user will simply // not get any instructions. - let add_instructions = if settings.diff_instructions() && !instructions_path_to_cleanup.exists() - { + let add_instructions = if !instructions_path_to_cleanup.exists() { instructions } else { None diff --git a/cli/src/merge_tools/mod.rs b/cli/src/merge_tools/mod.rs index f686b9859c..98c4278200 100644 --- a/cli/src/merge_tools/mod.rs +++ b/cli/src/merge_tools/mod.rs @@ -150,7 +150,6 @@ pub fn edit_diff( matcher, instructions, base_ignores, - settings, ), } } diff --git a/cli/tests/test_diffedit_command.rs b/cli/tests/test_diffedit_command.rs index 383f7a82f9..69619b49f7 100644 --- a/cli/tests/test_diffedit_command.rs +++ b/cli/tests/test_diffedit_command.rs @@ -47,6 +47,22 @@ fn test_diffedit() { M file2 "###); + // Try again with ui.diff-instructions=false + std::fs::write(&edit_script, "files-before file1 file2\0files-after file2").unwrap(); + let (stdout, stderr) = test_env.jj_cmd_ok( + &repo_path, + &["diffedit", "--config-toml=ui.diff-instructions=false"], + ); + insta::assert_snapshot!(stdout, @""); + insta::assert_snapshot!(stderr, @r###" + Nothing changed. + "###); + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]); + insta::assert_snapshot!(stdout, @r###" + D file1 + M file2 + "###); + // Nothing happens if the diff-editor exits with an error std::fs::write(&edit_script, "rm file2\0fail").unwrap(); insta::assert_snapshot!(&test_env.jj_cmd_failure(&repo_path, &["diffedit"]), @r###" @@ -64,8 +80,8 @@ fn test_diffedit() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" - Created kkmpptxz 1930da4a (no description set) - Working copy now at: kkmpptxz 1930da4a (no description set) + Created kkmpptxz ae84b067 (no description set) + Working copy now at: kkmpptxz ae84b067 (no description set) Parent commit : rlvkpnrz 613028a4 (no description set) Added 0 files, modified 1 files, removed 0 files "###); @@ -80,10 +96,10 @@ fn test_diffedit() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit", "-r", "@-"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" - Created rlvkpnrz c03ae967 (no description set) + Created rlvkpnrz 51a4f74c (no description set) Rebased 1 descendant commits - Working copy now at: kkmpptxz 2a4dc204 (no description set) - Parent commit : rlvkpnrz c03ae967 (no description set) + Working copy now at: kkmpptxz 574af856 (no description set) + Parent commit : rlvkpnrz 51a4f74c (no description set) Added 0 files, modified 1 files, removed 0 files "###); let contents = String::from_utf8(std::fs::read(repo_path.join("file3")).unwrap()).unwrap(); @@ -101,8 +117,8 @@ fn test_diffedit() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["diffedit", "--from", "@--"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" - Created kkmpptxz 15f2c966 (no description set) - Working copy now at: kkmpptxz 15f2c966 (no description set) + Created kkmpptxz cd638328 (no description set) + Working copy now at: kkmpptxz cd638328 (no description set) Parent commit : rlvkpnrz 613028a4 (no description set) Added 0 files, modified 0 files, removed 1 files "###);