Skip to content

Commit fa6b5b3

Browse files
Johannes Sixtspearce
authored andcommitted
git-gui: Fix "Stage/Unstage Line" with one line of context.
To "Stage/Unstage Line" we construct a patch that contains exactly one change (either addition or removal); the hunk header was forged by counting the old side and adjusting the count by +/-1 for the new side. But when we counted the context we never counted the changed line itself. If the hunk had only one removal line and one line of context, like this: @@ -1,3 +1,2 @@ context 1 -removal context 2 We had constructed this patch: @@ -1,2 +1,1 @@ context 1 -removal context 2 which does not apply because git apply deduces that it must apply at the end of the file. ("context 2" is considered garbage and ignored.) The fix is that removal lines must be counted towards the context of the old side. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent 7838d3f commit fa6b5b3

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

lib/diff.tcl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ proc apply_line {x y} {
423423
# the line to stage/unstage
424424
set ln [$ui_diff get $i_l $next_l]
425425
set patch "$patch$ln"
426+
if {$c1 eq {-}} {
427+
set n [expr $n+1]
428+
}
426429
} elseif {$c1 ne {-} && $c1 ne {+}} {
427430
# context line
428431
set ln [$ui_diff get $i_l $next_l]

0 commit comments

Comments
 (0)