1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-23 22:24:51 +02:00

Fix fixup's false filename detection in hunks containing dashed lines (#5004)

### PR Description

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 repository https://github.com/abobov/lazygit-fixup-issue
demonstrates the issue:

- clone repository
- run `git reset --soft HEAD~`
- try `<c-f>` Find base commit for fixup 
- `fatal: no such path ...` error
This commit is contained in:
Stefan Haller
2025-11-01 09:42:45 +01:00
committed by GitHub
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: `