Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub struct StateMachine<'a> {
pub source: Source,
pub minus_file: String,
pub plus_file: String,
pub binary_files: bool,
pub minus_file_event: handlers::diff_header::FileEvent,
pub plus_file_event: handlers::diff_header::FileEvent,
pub diff_line: String,
Expand Down Expand Up @@ -130,6 +131,7 @@ impl<'a> StateMachine<'a> {
source: Source::Unknown,
minus_file: "".to_string(),
plus_file: "".to_string(),
binary_files: false,
minus_file_event: handlers::diff_header::FileEvent::NoEvent,
plus_file_event: handlers::diff_header::FileEvent::NoEvent,
diff_line: "".to_string(),
Expand Down
10 changes: 9 additions & 1 deletion src/handlers/diff_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl StateMachine<'_> {
let line = get_file_change_description_from_file_paths(
&self.minus_file,
&self.plus_file,
self.binary_files,
comparing,
&self.minus_file_event,
&self.plus_file_event,
Expand Down Expand Up @@ -398,6 +399,7 @@ fn _parse_file_path(path: &str, git_diff_name: bool) -> String {
pub fn get_file_change_description_from_file_paths(
minus_file: &str,
plus_file: &str,
binary_files: bool,
comparing: bool,
minus_file_event: &FileEvent,
plus_file_event: &FileEvent,
Expand Down Expand Up @@ -435,7 +437,8 @@ pub fn get_file_change_description_from_file_paths(
_ => formatted_file,
}
};
match (minus_file, plus_file, minus_file_event, plus_file_event) {

let mut description = match (minus_file, plus_file, minus_file_event, plus_file_event) {
(minus_file, plus_file, _, _) if minus_file == plus_file => format!(
"{}{}",
format_label(&config.file_modified_label),
Expand Down Expand Up @@ -463,7 +466,12 @@ pub fn get_file_change_description_from_file_paths(
config.right_arrow,
format_file(plus_file)
),
};

if binary_files {
description.push_str(" (binary file)");
}
description
}
}

Expand Down
1 change: 1 addition & 0 deletions src/handlers/diff_header_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl StateMachine<'_> {
let name = get_repeated_file_path_from_diff_line(&self.line).unwrap_or_default();
self.minus_file.clone_from(&name);
self.plus_file.clone_from(&name);
self.binary_files = false;
self.minus_file_event = FileEvent::Change;
self.plus_file_event = FileEvent::Change;
self.current_file_pair = Some((self.minus_file.clone(), self.plus_file.clone()));
Expand Down
3 changes: 1 addition & 2 deletions src/handlers/diff_header_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ impl StateMachine<'_> {
return Ok(true);
}

self.binary_files = true;
if self.minus_file != "/dev/null" {
relativize_path_maybe(&mut self.minus_file, self.config);
self.minus_file.push_str(" (binary file)");
}
if self.plus_file != "/dev/null" {
relativize_path_maybe(&mut self.plus_file, self.config);
self.plus_file.push_str(" (binary file)");
}
return Ok(true);
}
Expand Down
7 changes: 7 additions & 0 deletions src/tests/test_example_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,13 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
);
}

#[test]
fn test_hyperlinks_binary_files() {
DeltaTest::with_args(&["--hyperlinks"])
.with_input(BINARY_FILES_DIFFER)
.expect_raw_contains("]8;;\u{1b}\\ (binary file)");
}

#[test]
fn test_filenames_with_spaces() {
DeltaTest::with_args(&[])
Expand Down