git-gui: Fix applying a line when all following lines are deletions
[gitweb.git] / lib / diff.tcl
index ae1ea3a615f8bc4c809341ae6c6dd3fcf8a54269..066755b864b587e073a820aa2eb729a6c930d7b0 100644 (file)
@@ -298,7 +298,12 @@ proc start_show_diff {cont_info {add_opts {}}} {
 
        if {[string match {160000 *} [lindex $s 2]]
         || [string match {160000 *} [lindex $s 3]]} {
-               set cmd {submodule summary -- $current_diff_path}
+               set is_submodule_diff 1
+               if {$w eq $ui_index} {
+                       set cmd [list submodule summary --cached -- $path]
+               } else {
+                       set cmd [list submodule summary --files -- $path]
+               }
        }
 
        if {[catch {set fd [eval git_read --nice $cmd]} err]} {
@@ -343,9 +348,6 @@ proc read_diff {fd cont_info} {
                }
                set ::current_diff_inheader 0
 
-               if {[regexp {^\* } $line]} {
-                       set is_submodule_diff 1
-               }
                # -- Automatically detect if this is a 3 way diff.
                #
                if {[string match {@@@ *} $line]} {set is_3way_diff 1}
@@ -662,6 +664,7 @@ proc apply_line {x y} {
                }
                set i_l $next_l
        }
+       set patch "$patch$pre_context"
        set patch "@@ -$hln,$n +$hln,[eval expr $n $sign 1] @@\n$patch"
 
        if {[catch {