1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-22 04:42:37 +03:00

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.
This commit is contained in:
Anton Bobov
2025-10-31 21:53:57 +05:00
committed by Stefan Haller
parent f4920e8efa
commit 4c4929acad
2 changed files with 21 additions and 1 deletions

View File

@@ -194,7 +194,7 @@ func parseDiff(diff string) ([]*hunk, []*hunk) {
if strings.HasPrefix(line, "diff --git") { if strings.HasPrefix(line, "diff --git") {
finishHunk() finishHunk()
currentHunk = nil currentHunk = nil
} else if strings.HasPrefix(line, "--- ") { } else if currentHunk == nil && strings.HasPrefix(line, "--- ") {
// For some reason, the line ends with a tab character if the file // For some reason, the line ends with a tab character if the file
// name contains spaces // name contains spaces
filename = strings.TrimRight(line[6:], "\t") filename = strings.TrimRight(line[6:], "\t")

View File

@@ -78,6 +78,26 @@ index 9ce8efb33..fb5e469e7 100644
}, },
}, },
}, },
{
name: "hunk with dashed lines",
diff: `
diff --git a/file1.txt b/file1.txt
index 9ce8efb33..fb5e469e7 100644
--- a/file1.txt
+++ b/file1.txt
@@ -3,1 +3,1 @@
--- xxx
+-- yyy
`,
expectedDeletedLineHunks: []*hunk{
{
filename: "file1.txt",
startLineIdx: 3,
numLines: 1,
},
},
expectedAddedLineHunks: []*hunk{},
},
{ {
name: "several hunks in different files", name: "several hunks in different files",
diff: ` diff: `