summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBjörn Steinbrink <bsteinbr@gmail.com>2022-06-21 20:03:49 +0200
committerDan Davison <dandavison7@gmail.com>2022-06-22 08:49:42 -0400
commitbd54a51205beb2aa71f8d4efb9b0749f425fb1da (patch)
tree493fd6e213c60ea9c92d99078c15bb093c231988 /src
parente28e97de7aa02969bcf939f20269ea5c0ff5269b (diff)
Fix whole-file changes being attributed to the wrong commit in "git log" output
The pending buffer for whole-file changes is currently only flushed when encountering a new diff header. This leads to it being carried over across commit boundaries in cases where multiple commits are shown. To fix this, we simply need to flush the buffered data on a commit boundary as well. Fixes #1089
Diffstat (limited to 'src')
-rw-r--r--src/handlers/commit_meta.rs1
-rw-r--r--src/tests/test_example_diffs.rs29
2 files changed, 30 insertions, 0 deletions
diff --git a/src/handlers/commit_meta.rs b/src/handlers/commit_meta.rs
index 98bdfad7..f60ba370 100644
--- a/src/handlers/commit_meta.rs
+++ b/src/handlers/commit_meta.rs
@@ -16,6 +16,7 @@ impl<'a> StateMachine<'a> {
}
let mut handled_line = false;
self.painter.paint_buffered_minus_and_plus_lines();
+ self.handle_pending_line_with_diff_name()?;
self.state = State::CommitMeta;
if self.should_handle() {
self.painter.emit()?;
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index 325f2e9a..d3800a62 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -1626,6 +1626,13 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
.expect_contains("a b ⟶ c d\n");
}
+ #[test]
+ fn test_file_removal_in_log_output() {
+ DeltaTest::with_args(&[])
+ .with_input(GIT_LOG_FILE_REMOVAL_IN_FIRST_COMMIT)
+ .expect_after_header("#partial\n\nremoved: a");
+ }
+
const GIT_DIFF_SINGLE_HUNK: &str = "\
commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e
Author: Dan Davison <dandavison7@gmail.com>
@@ -2386,4 +2393,26 @@ index d00491f..0cfbf08 100644
-1
+2
";
+
+ const GIT_LOG_FILE_REMOVAL_IN_FIRST_COMMIT: &str = "
+commit 4117f616160180c0c57ea64840eadd08b7fa32a4
+Author: Björn Steinbrink <bsteinbr@gmail.com>
+Date: Tue Jun 21 14:51:59 2022 +0200
+
+ remove file
+
+diff --git a a
+deleted file mode 100644
+index e69de29..0000000
+
+commit 190cce5dffeb9050fd6a27780f16d84b19c07dc0
+Author: Björn Steinbrink <bsteinbr@gmail.com>
+Date: Tue Jun 21 14:48:20 2022 +0200
+
+ add file
+
+diff --git a a
+new file mode 100644
+index 0000000..e69de29
+";
}