Skip to content

Commit

Permalink
git-gui: Fix "Stage/Unstage Line" with one line of context.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Sixt authored and Shawn O. Pearce committed Jul 26, 2008
1 parent 7838d3f commit fa6b5b3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/diff.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ proc apply_line {x y} {
# the line to stage/unstage
set ln [$ui_diff get $i_l $next_l]
set patch "$patch$ln"
if {$c1 eq {-}} {
set n [expr $n+1]
}
} elseif {$c1 ne {-} && $c1 ne {+}} {
# context line
set ln [$ui_diff get $i_l $next_l]
Expand Down

0 comments on commit fa6b5b3

Please sign in to comment.