diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-08-09 17:28:43 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2023-08-10 07:22:42 +0200 |
commit | 73b68927af5b64b675109fd7f5fc9e14daf857cc (patch) | |
tree | 1f737e55fc8181af12e754db18164664db252583 /pkg/commands | |
parent | bf699d3a79dbe160830d56cb8d13574b8efd766c (diff) |
Fix bug in LineNumberOfLine
This fixes a regression that was introduced in 73c7dc9c5d00.
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/patch/patch.go | 4 | ||||
-rw-r--r-- | pkg/commands/patch/patch_test.go | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/pkg/commands/patch/patch.go b/pkg/commands/patch/patch.go index 5275fb613..55dd8f80d 100644 --- a/pkg/commands/patch/patch.go +++ b/pkg/commands/patch/patch.go @@ -97,12 +97,12 @@ func (self *Patch) LineNumberOfLine(idx int) int { idxInHunk := idx - hunkStartIdx if idxInHunk == 0 { - return hunk.oldStart + return hunk.newStart } lines := hunk.bodyLines[:idxInHunk-1] offset := nLinesWithKind(lines, []PatchLineKind{ADDITION, CONTEXT}) - return hunk.oldStart + offset + return hunk.newStart + offset } // Returns hunk index containing the line at the given patch line index diff --git a/pkg/commands/patch/patch_test.go b/pkg/commands/patch/patch_test.go index 57d17e7c9..e86c5f07a 100644 --- a/pkg/commands/patch/patch_test.go +++ b/pkg/commands/patch/patch_test.go @@ -599,7 +599,7 @@ func TestLineNumberOfLine(t *testing.T) { testName: "twoHunksWithMoreAdditionsThanRemovals", patchStr: twoHunksWithMoreAdditionsThanRemovals, indexes: []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 1000}, - expecteds: []int{1, 1, 1, 1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16}, + expecteds: []int{1, 1, 1, 1, 1, 1, 2, 2, 3, 4, 5, 6, 9, 9, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16}, }, } |