summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2025-08-01 11:02:55 +0200
committerThomas Otto <th1000s@posteo.net>2025-08-01 11:09:18 +0200
commit59a907117bb9aeb467b392c4fdc36f2f931330c0 (patch)
treec1cf0c644732f5b2d516de27246d6d7d8d9cf9e8 /src
parentcd4a9f4e74d243d44bdaebde5d4188cdc100951a (diff)
Fix diff output when a diff ends with a mode change
Output can be generated directly via Painter::write, or Painter::output_buffer. The latter must be emit()'ed before the former method can be used again, otherwise the order is incorrect. Tests added. Fixes #1504
Diffstat (limited to 'src')
-rw-r--r--src/handlers/diff_header.rs68
-rw-r--r--src/handlers/diff_header_diff.rs1
2 files changed, 69 insertions, 0 deletions
diff --git a/src/handlers/diff_header.rs b/src/handlers/diff_header.rs
index 78157cb..b5fe114 100644
--- a/src/handlers/diff_header.rs
+++ b/src/handlers/diff_header.rs
@@ -646,6 +646,74 @@ mod tests {
);
}
+ #[test]
+ fn test_diff_header_with_mode_change_in_last_hunk() {
+ let input = "\
+diff --git a/a.txt b/a.txt
+index 44371ed..e69de29 100644
+--- a/a.txt
++++ b/a.txt
+@@ -1 +0,0 @@
+-A-content
+diff --git a/b.txt b/b.txt
+old mode 100644
+new mode 100755
+";
+
+ let result = DeltaTest::with_args(&[]).with_input(input);
+
+ assert_snapshot!(result.output, @r"
+ a.txt
+ ───────────────────────────────────────────
+
+ ───┐
+ 0: │
+ ───┘
+ A-content
+
+ b.txt (mode +x)
+ ───────────────────────────────────────────
+ ");
+ }
+
+ #[test]
+ fn test_diff_header_with_2x_mode_change() {
+ let input = "\
+diff --git a/a.txt b/a.txt
+index 44371ed..e69de29 100644
+--- a/a.txt
++++ b/a.txt
+@@ -1 +0,0 @@
+-A-content
+diff --git a/b.txt b/b.txt
+old mode 100644
+new mode 100755
+--- a/b.txt
++++ b/b.txt
+diff --git a/c.txt b/c.txt
+old mode 100644
+new mode 100755
+";
+
+ let result = DeltaTest::with_args(&[]).with_input(input);
+
+ assert_snapshot!(result.output, @r"
+ a.txt
+ ───────────────────────────────────────────
+
+ ───┐
+ 0: │
+ ───┘
+ A-content
+
+ b.txt (mode +x)
+ ───────────────────────────────────────────
+
+ c.txt (mode +x)
+ ───────────────────────────────────────────
+ ");
+ }
+
pub const BIN_AND_TXT_FILE_ADDED: &str = "\
diff --git a/BIN b/BIN
new file mode 100644
diff --git a/src/handlers/diff_header_diff.rs b/src/handlers/diff_header_diff.rs
index e88f89d..70aca72 100644
--- a/src/handlers/diff_header_diff.rs
+++ b/src/handlers/diff_header_diff.rs
@@ -13,6 +13,7 @@ impl StateMachine<'_> {
return Ok(false);
}
self.painter.paint_buffered_minus_and_plus_lines();
+ self.painter.emit()?;
self.state =
if self.line.starts_with("diff --cc ") || self.line.starts_with("diff --combined ") {
// We will determine the number of parents when we see the hunk header.