Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/handlers/diff_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
53 changes: 53 additions & 0 deletions src/tests/test_example_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -1606,6 +1607,40 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
assert!(output.contains(r"src/delta.rs: mode -x"));
}

#[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"));
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incidentally, there's a utility to make writing these tests easier now. It doesn't yet have an expect_contains() method but I'll add that, at which point this test will be able to be written as

    fn test_file_mode_change_unexpected_bits() {
        DeltaTest::with(&["--navigate", "--right-arrow=->"])
            .with_input(GIT_DIFF_FILE_MODE_CHANGE_UNEXPECTED_BITS)
            .expect_contains(r"Δ src/delta.rs: 100700 -> 100644");
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out. I've created a pull request that implements this (along with some other changes).


#[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(&[
Expand Down Expand Up @@ -2316,6 +2351,24 @@ new mode 100755
diff --git a/src/delta.rs b/src/delta.rs
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 = "
Expand Down