Skip to content

Commit 246295b

Browse files
jlehmannspearce
authored andcommitted
git-gui: display summary when showing diff of a submodule
As it is hard to say what changed in a submodule by looking at the hashes, let's show the colored submodule summary instead. Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent a91be3f commit 246295b

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

git-gui.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3212,7 +3212,7 @@ proc popup_diff_menu {ctxm ctxmmg x y X Y} {
32123212
set l [mc "Stage Hunk For Commit"]
32133213
set t [mc "Stage Line For Commit"]
32143214
}
3215-
if {$::is_3way_diff
3215+
if {$::is_3way_diff || $::is_submodule_diff
32163216
|| $current_diff_path eq {}
32173217
|| {__} eq $state
32183218
|| {_O} eq $state

lib/diff.tcl

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ proc show_other_diff {path w m cont_info} {
255255

256256
proc start_show_diff {cont_info {add_opts {}}} {
257257
global file_states file_lists
258-
global is_3way_diff diff_active repo_config
258+
global is_3way_diff is_submodule_diff diff_active repo_config
259259
global ui_diff ui_index ui_workdir
260260
global current_diff_path current_diff_side current_diff_header
261261

@@ -265,6 +265,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
265265
set s $file_states($path)
266266
set m [lindex $s 0]
267267
set is_3way_diff 0
268+
set is_submodule_diff 0
268269
set diff_active 1
269270
set current_diff_header {}
270271

@@ -295,6 +296,11 @@ proc start_show_diff {cont_info {add_opts {}}} {
295296
lappend cmd $path
296297
}
297298

299+
if {[string match {160000 *} [lindex $s 2]]
300+
|| [string match {160000 *} [lindex $s 3]]} {
301+
set cmd {submodule summary -- $current_diff_path}
302+
}
303+
298304
if {[catch {set fd [eval git_read --nice $cmd]} err]} {
299305
set diff_active 0
300306
unlock_index
@@ -312,7 +318,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
312318
}
313319

314320
proc read_diff {fd cont_info} {
315-
global ui_diff diff_active
321+
global ui_diff diff_active is_submodule_diff
316322
global is_3way_diff is_conflict_diff current_diff_header
317323
global current_diff_queue
318324
global diff_empty_count
@@ -337,6 +343,9 @@ proc read_diff {fd cont_info} {
337343
}
338344
set ::current_diff_inheader 0
339345

346+
if {[regexp {^\* } $line]} {
347+
set is_submodule_diff 1
348+
}
340349
# -- Automatically detect if this is a 3 way diff.
341350
#
342351
if {[string match {@@@ *} $line]} {set is_3way_diff 1}
@@ -374,6 +383,23 @@ proc read_diff {fd cont_info} {
374383
set tags {}
375384
}
376385
}
386+
} elseif {$is_submodule_diff} {
387+
if {$line == ""} continue
388+
if {[regexp {^\* } $line]} {
389+
set line [string replace $line 0 1 {Submodule }]
390+
set tags d_@
391+
} else {
392+
set op [string range $line 0 2]
393+
switch -- $op {
394+
{ <} {set tags d_-}
395+
{ >} {set tags d_+}
396+
{ W} {set tags {}}
397+
default {
398+
puts "error: Unhandled submodule diff marker: {$op}"
399+
set tags {}
400+
}
401+
}
402+
}
377403
} else {
378404
set op [string index $line 0]
379405
switch -- $op {

0 commit comments

Comments
 (0)