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

Fix the empty result issue in add -p #664

Merged
merged 3 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ impl<'a> StateMachine<'a> {
.to_string()
};
self.line = ansi::strip_ansi_codes(&self.raw_line);

// Strip the neglected CR.
// (CR-LF is unfortunately split by git because it adds ansi escapes between them.
// Thus byte_lines library can't remove the CR properly.)
if let Some(c) = self.line.bytes().nth_back(0) {
if c == b'\r' {
self.line.truncate(self.line.len() - 1);
}
}
dandavison marked this conversation as resolved.
Show resolved Hide resolved
}

/// Should a handle_* function be called on this element?
Expand Down
24 changes: 24 additions & 0 deletions src/tests/test_example_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e
);
}

#[test]
fn test_orphan_carriage_return_is_stripped() {
let config = integration_test_utils::make_config_from_args(&[]);
let output = integration_test_utils::run_delta(
GIT_DIFF_SINGLE_HUNK_WITH_SEQUENCE_OF_CR_ESCAPE_SEQUENCES_LF,
&config,
);
assert!(output.bytes().all(|b: u8| b != b'\r'));
}

#[test]
fn test_commit_decoration_style_omit() {
_do_test_commit_style_no_decoration(&[
Expand Down Expand Up @@ -1708,6 +1718,20 @@ Date: Thu May 14 11:13:17 2020 -0400
#[allow(dead_code)]
";

const GIT_DIFF_SINGLE_HUNK_WITH_SEQUENCE_OF_CR_ESCAPE_SEQUENCES_LF: &str = "\
diff --git a/src/main.rs b/src/main.rs
index f346a8c..e443b63 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,4 @@
-deleted line\r
-\r
fn main() {\r
println!(\"existing line\");\r
+ println!(\"added line\");\r
}\r
";

Copy link
Owner

Choose a reason for hiding this comment

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

Awesome, thank you!

const DIFF_IN_DIFF: &str = "\
diff --git a/0001-Init.patch b/0001-Init.patch
deleted file mode 100644
Expand Down