diff options
author | Wayne Davison <wayne@opencoder.net> | 2021-11-16 18:57:44 -0800 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2021-11-17 13:42:20 -0500 |
commit | d4e3c288ae8bdfe2bf93c9c23c88860a3987973c (patch) | |
tree | c5e694f4b20afa26a5f7542ade66820eaf5f2ca0 | |
parent | d46a1741f7e000da7d6d5280c17e4923db2adb32 (diff) |
Use file-modified-label consistently.
When filtering a diff and when directly diffing files/dirs, use the
modified label that is output when interpreting git diffs. This gets
rid of the "comparing:" prefix (which was otherwise missing from the
--navigate regex) and ensures that a direct diff has a label to stop at
when --navigate is enabled. One of the unified-diff tests now uses
--file-modified-label=comparing: to generate the same output as before,
while the other now uses --navigate to get a delta char label.
-rw-r--r-- | src/handlers/file_meta.rs | 23 | ||||
-rw-r--r-- | src/tests/test_example_diffs.rs | 13 |
2 files changed, 20 insertions, 16 deletions
diff --git a/src/handlers/file_meta.rs b/src/handlers/file_meta.rs index 82109a91..d58eb9dd 100644 --- a/src/handlers/file_meta.rs +++ b/src/handlers/file_meta.rs @@ -304,16 +304,21 @@ pub fn get_file_change_description_from_file_paths( plus_file_event: &FileEvent, config: &Config, ) -> String { + let format_label = |label: &str| { + if !label.is_empty() { + format!("{} ", label) + } else { + "".to_string() + } + }; if comparing { - format!("comparing: {} ⟶ {}", minus_file, plus_file) + format!( + "{}{} ⟶ {}", + format_label(&config.file_modified_label), + minus_file, + plus_file + ) } else { - let format_label = |label: &str| { - if !label.is_empty() { - format!("{} ", label) - } else { - "".to_string() - } - }; let format_file = |file| { if config.hyperlinks { features::hyperlinks::format_osc8_file_hyperlink(file, None, file, config) @@ -356,7 +361,7 @@ pub fn get_file_change_description_from_file_paths( format_label(match file_event { FileEvent::Rename => &config.file_renamed_label, FileEvent::Copy => &config.file_copied_label, - _ => "", + _ => &config.file_modified_label, }), format_file(minus_file), format_file(plus_file) diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs index dda5bcf6..a6d5f497 100644 --- a/src/tests/test_example_diffs.rs +++ b/src/tests/test_example_diffs.rs @@ -110,7 +110,8 @@ mod tests { #[test] fn test_diff_unified_two_files() { - let config = integration_test_utils::make_config_from_args(&[]); + let config = + integration_test_utils::make_config_from_args(&["--file-modified-label", "comparing:"]); let output = integration_test_utils::run_delta(DIFF_UNIFIED_TWO_FILES, &config); let output = strip_ansi_codes(&output); let mut lines = output.lines(); @@ -125,16 +126,14 @@ mod tests { #[test] fn test_diff_unified_two_directories() { - let config = integration_test_utils::make_config_from_args(&["--width", "80"]); + let config = + integration_test_utils::make_config_from_args(&["--width", "80", "--navigate"]); let output = integration_test_utils::run_delta(DIFF_UNIFIED_TWO_DIRECTORIES, &config); let output = strip_ansi_codes(&output); let mut lines = output.lines(); // Header - assert_eq!( - lines.nth(1).unwrap(), - "comparing: a/different ⟶ b/different" - ); + assert_eq!(lines.nth(1).unwrap(), "Δ a/different ⟶ b/different"); // Change assert_eq!(lines.nth(7).unwrap(), "This is different from b"); // File uniqueness @@ -144,7 +143,7 @@ mod tests { // Next hunk assert_eq!( lines.nth(4).unwrap(), - "comparing: a/more_difference ⟶ b/more_difference" + "Δ a/more_difference ⟶ b/more_difference" ); } |