From 4c4929acadbd935a1207c8cb0e36b9602d2fce01 Mon Sep 17 00:00:00 2001 From: Anton Bobov Date: Fri, 31 Oct 2025 21:53:57 +0500 Subject: [PATCH] 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. --- pkg/gui/controllers/helpers/fixup_helper.go | 2 +- .../controllers/helpers/fixup_helper_test.go | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index f44c23da8b4..a435d188dbb 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -194,7 +194,7 @@ func parseDiff(diff string) ([]*hunk, []*hunk) { if strings.HasPrefix(line, "diff --git") { finishHunk() 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 // name contains spaces filename = strings.TrimRight(line[6:], "\t") diff --git a/pkg/gui/controllers/helpers/fixup_helper_test.go b/pkg/gui/controllers/helpers/fixup_helper_test.go index 954161cd16a..e50a4249f70 100644 --- a/pkg/gui/controllers/helpers/fixup_helper_test.go +++ b/pkg/gui/controllers/helpers/fixup_helper_test.go @@ -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", diff: `