Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve "Binary files" line in color_only mode #1649

Merged
merged 1 commit into from
Mar 12, 2024
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
3 changes: 2 additions & 1 deletion src/handlers/diff_header_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ impl<'a> StateMachine<'a> {
return Ok(false);
}

if self.test_diff_is_binary() {
// Preserve the "Binary files" line when diff lines should be kept unchanged.
if !self.config.color_only && self.test_diff_is_binary() {
// Print the "Binary files" line verbatim, if there was no "diff" line, or it
// listed different files but was not followed by header minus and plus lines.
// This can happen in output of standalone diff or git diff --no-index.
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ impl<'a> StateMachine<'a> {
// 2. Git diff emits lines describing submodule state such as "Submodule x/y/z contains
// untracked content"
//
// 3. When comparing binary files, diff can emit "Binary files ... differ" line.
//
// See https://github.com/dandavison/delta/issues/60#issuecomment-557485242 for a
// proposal for more robust parsing logic.

Expand Down
29 changes: 29 additions & 0 deletions src/tests/test_example_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,15 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
assert_eq!(output, input);
}

#[test]
fn test_git_diff_binary_is_unchanged_under_color_only() {
let config = integration_test_utils::make_config_from_args(&["--color-only"]);
let input = BINARY_FILES_DIFFER_BETWEEN_OTHER;
let output = integration_test_utils::run_delta(input, &config);
let output = strip_ansi_codes(&output);
assert_eq!(output, input);
}

// See https://github.com/dandavison/delta/issues/371#issuecomment-720173435
#[test]
fn test_keep_plus_minus_markers_under_inspect_raw_lines() {
Expand Down Expand Up @@ -2354,6 +2363,26 @@ rename to bar
diff --git a/qux b/qux
index 00de669..d47cd84 100644
Binary files a/qux and b/qux differ
";

const BINARY_FILES_DIFFER_BETWEEN_OTHER: &str = "\
diff --git a/foo b/foo
index 7b57bd29ea8a..4d3b8c11a4a2 100644
--- a/foo
+++ b/foo
@@ -1 +1 @@
-abc
+def
diff --git a/qux b/qux
index 00de669..d47cd84 100644
Binary files a/qux and b/qux differ
diff --git a/bar b/bar
index 7b57bd29ea8a..4d3b8c11a4a2 100644
--- a/bar
+++ b/bar
@@ -1 +1 @@
-123
+456
";

const DIFF_NO_INDEX_BINARY_FILES_DIFFER: &str = "\
Expand Down
Loading