Skip to content

Commit

Permalink
Fix whole-file changes being attributed to the wrong commit in "git l…
Browse files Browse the repository at this point in the history
…og" 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
  • Loading branch information
dotdash authored and dandavison committed Jun 22, 2022
1 parent e28e97d commit bd54a51
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/handlers/commit_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
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 @@ -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>
Expand Down Expand Up @@ -2385,5 +2392,27 @@ index d00491f..0cfbf08 100644
@@ -1 +1 @@
-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
";
}

0 comments on commit bd54a51

Please sign in to comment.