Skip to content

Commit 186d5f0

Browse files
committed
Fix fixup's false filename detection in hunks containing dashed lines
The existing diff parser incorrectly treated subsequent lines beginning with "---" as filename headers while processing hunks. This caused corruption when dashed lines appeared within diffs themselves. Restrict filename detection to only occur between hunks.
1 parent 6f0f1e7 commit 186d5f0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pkg/gui/controllers/helpers/fixup_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func parseDiff(diff string) ([]*hunk, []*hunk) {
194194
if strings.HasPrefix(line, "diff --git") {
195195
finishHunk()
196196
currentHunk = nil
197-
} else if strings.HasPrefix(line, "--- ") {
197+
} else if currentHunk == nil && strings.HasPrefix(line, "--- ") {
198198
// For some reason, the line ends with a tab character if the file
199199
// name contains spaces
200200
filename = strings.TrimRight(line[6:], "\t")

pkg/gui/controllers/helpers/fixup_helper_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ index 9ce8efb33..fb5e469e7 100644
7878
},
7979
},
8080
},
81+
{
82+
name: "hunk with dashed lines",
83+
diff: `
84+
diff --git a/file1.txt b/file1.txt
85+
index 9ce8efb33..fb5e469e7 100644
86+
--- a/file1.txt
87+
+++ b/file1.txt
88+
@@ -3,1 +3,1 @@
89+
--- xxx
90+
+-- yyy
91+
`,
92+
expectedDeletedLineHunks: []*hunk{
93+
{
94+
filename: "file1.txt",
95+
startLineIdx: 3,
96+
numLines: 1,
97+
},
98+
},
99+
expectedAddedLineHunks: []*hunk{},
100+
},
81101
{
82102
name: "several hunks in different files",
83103
diff: `

0 commit comments

Comments
 (0)