From 82cb8706bb9f4f43c72e0228ad33d91c29448f3f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 21 Jan 2007 11:54:16 -0500 Subject: [PATCH] git-gui: Remove combined diff showing behavior. The combined diff format can be very confusing, especially to new users who may not even be familiar with a standard two way diff format. So for files which are already staged for commit and which are modifed in the working directory we should show two different diffs, depending on which side the user clicked on. If the user clicks on the "Changes To Be Committed" side then we should show them the PARENT<->index difference. This is the set of changes they will actually commit. If the user clicks on the "Changed But Not Updated" side we should show them the index<->working directory difference. This is the set of changes which will not be committed, as they have not been staged into the index. This is especially useful when merging, as the "Changed But Not Updated" files are the ones that need merge conflict resolution, and the diff here is the conflict hunks and/or any evil merge created by the user. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 0bfd56051..64c2ae30e 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -556,13 +556,14 @@ proc clear_diff {} { } proc reshow_diff {} { - global current_diff_path ui_status_value file_states + global ui_status_value file_states + global current_diff_path current_diff_side if {$current_diff_path eq {} || [catch {set s $file_states($current_diff_path)}]} { clear_diff } else { - show_diff $current_diff_path + show_diff $current_diff_path $current_diff_side } } @@ -595,10 +596,11 @@ files list, to prevent possible confusion. display_file $path __ } -proc show_diff {path {w {}} {lno {}}} { +proc show_diff {path w {lno {}}} { global file_states file_lists global is_3way_diff diff_active repo_config - global ui_diff current_diff_path ui_status_value + global ui_diff ui_status_value ui_index ui_workdir + global current_diff_path current_diff_side if {$diff_active || ![lock_index read]} return @@ -621,20 +623,12 @@ proc show_diff {path {w {}} {lno {}}} { set is_3way_diff 0 set diff_active 1 set current_diff_path $path + set current_diff_side $w set ui_status_value "Loading diff of [escape_path $path]..." - set cmd [list | git diff-index] - lappend cmd --no-color - if {$repo_config(gui.diffcontext) > 0} { - lappend cmd "-U$repo_config(gui.diffcontext)" - } - lappend cmd -p - - switch $m { - MM { - lappend cmd -c - } - _O { + # - Git won't give us the diff, there's nothing to compare to! + # + if {$m eq {_O}} { if {[catch { set fd [open $path r] set content [read $fd] @@ -654,9 +648,23 @@ proc show_diff {path {w {}} {lno {}}} { set ui_status_value {Ready.} return } + + set cmd [list | git] + if {$w eq $ui_index} { + lappend cmd diff-index + lappend cmd --cached + } elseif {$w eq $ui_workdir} { + lappend cmd diff-files } - lappend cmd [PARENT] + lappend cmd -p + lappend cmd --no-color + if {$repo_config(gui.diffcontext) > 0} { + lappend cmd "-U$repo_config(gui.diffcontext)" + } + if {$w eq $ui_index} { + lappend cmd [PARENT] + } lappend cmd -- lappend cmd $path -- 2.30.2