Skip to content

Commit 9426110

Browse files
totphth1000s
authored andcommitted
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 dandavison#1504
1 parent cd4a9f4 commit 9426110

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/handlers/diff_header.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,74 @@ mod tests {
646646
);
647647
}
648648

649+
#[test]
650+
fn test_diff_header_with_mode_change_in_last_hunk() {
651+
let input = "\
652+
diff --git a/a.txt b/a.txt
653+
index 44371ed..e69de29 100644
654+
--- a/a.txt
655+
+++ b/a.txt
656+
@@ -1 +0,0 @@
657+
-A-content
658+
diff --git a/b.txt b/b.txt
659+
old mode 100644
660+
new mode 100755
661+
";
662+
663+
let result = DeltaTest::with_args(&[]).with_input(input);
664+
665+
assert_snapshot!(result.output, @r"
666+
a.txt
667+
───────────────────────────────────────────
668+
669+
───┐
670+
0: │
671+
───┘
672+
A-content
673+
674+
b.txt (mode +x)
675+
───────────────────────────────────────────
676+
");
677+
}
678+
679+
#[test]
680+
fn test_diff_header_with_2x_mode_change() {
681+
let input = "\
682+
diff --git a/a.txt b/a.txt
683+
index 44371ed..e69de29 100644
684+
--- a/a.txt
685+
+++ b/a.txt
686+
@@ -1 +0,0 @@
687+
-A-content
688+
diff --git a/b.txt b/b.txt
689+
old mode 100644
690+
new mode 100755
691+
--- a/b.txt
692+
+++ b/b.txt
693+
diff --git a/c.txt b/c.txt
694+
old mode 100644
695+
new mode 100755
696+
";
697+
698+
let result = DeltaTest::with_args(&[]).with_input(input);
699+
700+
assert_snapshot!(result.output, @r"
701+
a.txt
702+
───────────────────────────────────────────
703+
704+
───┐
705+
0: │
706+
───┘
707+
A-content
708+
709+
b.txt (mode +x)
710+
───────────────────────────────────────────
711+
712+
c.txt (mode +x)
713+
───────────────────────────────────────────
714+
");
715+
}
716+
649717
pub const BIN_AND_TXT_FILE_ADDED: &str = "\
650718
diff --git a/BIN b/BIN
651719
new file mode 100644

src/handlers/diff_header_diff.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ impl StateMachine<'_> {
1313
return Ok(false);
1414
}
1515
self.painter.paint_buffered_minus_and_plus_lines();
16+
self.painter.emit()?;
1617
self.state =
1718
if self.line.starts_with("diff --cc ") || self.line.starts_with("diff --combined ") {
1819
// We will determine the number of parents when we see the hunk header.

0 commit comments

Comments
 (0)