summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWayne Davison <wayne@opencoder.net>2021-12-30 12:00:14 -0800
committerDan Davison <dandavison7@gmail.com>2022-01-01 08:29:25 +0000
commit50ece4b0cc8dab57a69511fd62013feb892c9c20 (patch)
tree9aa1192cb95a2e2ccbfe66bc9448c603af3911fb
parent13f60da9ffe713aa68c3464c2451f5e072678921 (diff)
Put file-modified label in front of mode changes.
When using `--navigate` with files that get their mode modified, the file-modified label was not being prefixed, so these changes were not being marked as skip destinations. This is particularly bad if a file has line changes along with the mode change AND the user has an empty hunk label (since that would make the entire file's changes get skipped with an "n"). I added a test of a mode-change with a line-change, and a test for a mode change where the old & new mode values are not one of the two expected value-pairs. I also used format_file() on the mode filenames since the other format() calls were using it.
-rw-r--r--src/handlers/diff_header.rs20
-rw-r--r--src/tests/test_example_diffs.rs53
2 files changed, 69 insertions, 4 deletions
diff --git a/src/handlers/diff_header.rs b/src/handlers/diff_header.rs
index 1a703393..f90c6538 100644
--- a/src/handlers/diff_header.rs
+++ b/src/handlers/diff_header.rs
@@ -334,11 +334,23 @@ pub fn get_file_change_description_from_file_paths(
) if minus_file == plus_file => match (old_mode.as_str(), new_mode.as_str()) {
// 100755 for executable and 100644 for non-executable are the only file modes Git records.
// https://medium.com/@tahteche/how-git-treats-changes-in-file-permissions-f71874ca239d
- ("100644", "100755") => format!("{}: mode +x", plus_file),
- ("100755", "100644") => format!("{}: mode -x", plus_file),
+ ("100644", "100755") => format!(
+ "{}{}: mode +x",
+ format_label(&config.file_modified_label),
+ format_file(plus_file)
+ ),
+ ("100755", "100644") => format!(
+ "{}{}: mode -x",
+ format_label(&config.file_modified_label),
+ format_file(plus_file)
+ ),
_ => format!(
- "{}: {} {} {}",
- plus_file, old_mode, config.right_arrow, new_mode
+ "{}{}: {} {} {}",
+ format_label(&config.file_modified_label),
+ format_file(plus_file),
+ old_mode,
+ config.right_arrow,
+ new_mode
),
},
(minus_file, plus_file, _, _) if minus_file == plus_file => format!(
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index ce917c36..a135a9b2 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -8,6 +8,7 @@ mod tests {
use crate::tests::ansi_test_utils::ansi_test_utils;
use crate::tests::integration_test_utils;
use crate::tests::test_utils;
+ use regex::Regex;
#[test]
fn test_added_file() {
@@ -1607,6 +1608,40 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
}
#[test]
+ fn test_file_mode_change_unexpected_bits() {
+ let config =
+ integration_test_utils::make_config_from_args(&["--navigate", "--right-arrow=->"]);
+ let output =
+ integration_test_utils::run_delta(GIT_DIFF_FILE_MODE_CHANGE_UNEXPECTED_BITS, &config);
+ let output = strip_ansi_codes(&output);
+ assert!(output.contains(r"Δ src/delta.rs: 100700 -> 100644"));
+ }
+
+ #[test]
+ fn test_file_mode_change_with_diff() {
+ let config = integration_test_utils::make_config_from_args(&[
+ "--navigate",
+ "--keep-plus-minus-markers",
+ ]);
+ let output =
+ integration_test_utils::run_delta(GIT_DIFF_FILE_MODE_CHANGE_WITH_DIFF, &config);
+ let output = strip_ansi_codes(&output);
+ let re = Regex::new(r"\n─+\n").unwrap();
+ let output = re.replace(&output, "\n-----\n");
+ assert!(output.contains(
+ "Δ src/script: mode +x
+-----
+
+─────┐
+• 1: │
+─────┘
+-#!/bin/sh
++#!/bin/bash
+"
+ ));
+ }
+
+ #[test]
fn test_hyperlinks_commit_link_format() {
let config = integration_test_utils::make_config_from_args(&[
// If commit-style is not set then the commit line is handled in raw
@@ -2318,6 +2353,24 @@ old mode 100755
new mode 100644
";
+ const GIT_DIFF_FILE_MODE_CHANGE_UNEXPECTED_BITS: &str = "
+diff --git a/src/delta.rs b/src/delta.rs
+old mode 100700
+new mode 100644
+";
+
+ const GIT_DIFF_FILE_MODE_CHANGE_WITH_DIFF: &str = "
+diff --git a/src/script b/src/script
+old mode 100644
+new mode 100755
+index d00491f..0cfbf08 100644
+--- a/src/script
++++ b/src/script
+@@ -1 +1 @@
+-#!/bin/sh
++#!/bin/bash
+";
+
const GIT_DIFF_NO_INDEX_FILENAMES_WITH_SPACES: &str = "
diff --git a/a b b/c d
index d00491f..0cfbf08 100644