From c76a26bd2d5d9d37fa62725bb3fa7fd179c0fbc8 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Wed, 5 Jan 2022 13:54:18 -0800 Subject: Handle a mode change on a renamed file. (#875) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Handle a mode change on a renamed file. I changed the diff parsing to cache the mode info from the old/new mode lines until the parsing bumps into the start of the actual related diff, finds the diff line for an unrelated diff, or runs out of input. This allows the mode info to be output in conjunction with a file event instead of as a separate heading (that used to have an empty name when the mode change was for a rename). The mode info is passed down into the draw routines as a separate "addendum" string that the draw code can use as it likes. Currently that means that it appends the addendum string to the non-raw string in parens. I imagine that future draw routines could decide to put it in a separate box or some other per-routine method. There is currently a single function in src/handlers/draw.rs that joins the strings in the same way for everyone. A couple examples of how the new code looks: Δ foo.rs (mode +x) ─────────────────────────────────────────────────── renamed: old-longer-name → shorter-name (mode +x) ─────────────────────────────────────────────────── Would it look better on its own line? Δ foo.rs • mode +x ─────────────────────────────────────────────────── renamed: old-longer-name → shorter-name • mode +x ─────────────────────────────────────────────────── Would it look better appended after a "•" character? Δ foo.rs • mode +x ─────────────────────────────────────────────────── renamed: old-longer-name → shorter-name • mode +x ─────────────────────────────────────────────────── Should it be a user option? If so, we can do that later. --- src/tests/test_example_diffs.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/tests/test_example_diffs.rs') diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs index 6e0c542..3ef649b 100644 --- a/src/tests/test_example_diffs.rs +++ b/src/tests/test_example_diffs.rs @@ -1571,32 +1571,41 @@ src/align.rs:71: impl<'a> Alignment<'a> { │ )); } + #[test] + fn test_file_mode_change_with_rename() { + let config = integration_test_utils::make_config_from_args(&["--right-arrow=->"]); + let output = + integration_test_utils::run_delta(GIT_DIFF_FILE_MODE_CHANGE_WITH_RENAME, &config); + let output = strip_ansi_codes(&output); + assert!(output.contains("renamed: old-longer-name -> shorter-name (mode +x)")); + } + #[test] fn test_file_mode_change_gain_executable_bit() { DeltaTest::with_args(&[]) .with_input(GIT_DIFF_FILE_MODE_CHANGE_GAIN_EXECUTABLE_BIT) - .expect_contains(r"src/delta.rs: mode +x"); + .expect_contains("src/delta.rs (mode +x)"); } #[test] fn test_file_mode_change_lose_executable_bit() { DeltaTest::with_args(&[]) .with_input(GIT_DIFF_FILE_MODE_CHANGE_LOSE_EXECUTABLE_BIT) - .expect_contains(r"src/delta.rs: mode -x"); + .expect_contains("src/delta.rs (mode -x)"); } #[test] fn test_file_mode_change_unexpected_bits() { DeltaTest::with_args(&["--navigate", "--right-arrow=->"]) .with_input(GIT_DIFF_FILE_MODE_CHANGE_UNEXPECTED_BITS) - .expect_contains(r"Δ src/delta.rs: 100700 -> 100644"); + .expect_contains("Δ src/delta.rs (mode 100700 -> 100644)"); } #[test] fn test_file_mode_change_with_diff() { DeltaTest::with_args(&["--navigate", "--keep-plus-minus-markers"]) .with_input(GIT_DIFF_FILE_MODE_CHANGE_WITH_DIFF) - .expect_contains("Δ src/script: mode +x") + .expect_contains("Δ src/script (mode +x)") .expect_after_skip( 5, " @@ -2308,6 +2317,15 @@ Date: Sun Nov 1 15:28:53 2020 -0500 +] "#; + const GIT_DIFF_FILE_MODE_CHANGE_WITH_RENAME: &str = " +diff --git a/old-longer-name b/shorter-name +old mode 100644 +new mode 100755 +similarity index 100% +rename from old-longer-name +rename to shorter-name +"; + const GIT_DIFF_FILE_MODE_CHANGE_GAIN_EXECUTABLE_BIT: &str = " diff --git a/src/delta.rs b/src/delta.rs old mode 100644 -- cgit v1.2.3