git-gui: fix exception when trying to stage with empty file list
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Tue, 9 Jan 2018 14:33:01 +0000 (15:33 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Jan 2018 19:02:40 +0000 (11:02 -0800)
If there is nothing to stage, there is nothing to stage. Let's not try
to, even if the file list contains nothing at all.

This fixes https://github.com/git-for-windows/git/issues/1075

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-gui.sh
index 3ce2e04bc58ee2c0f17cf86b4d72bab7549b3f78..b3c14acbdf740b2073954bdc8ef49496db228b65 100755 (executable)
@@ -2505,7 +2505,9 @@ proc toggle_or_diff {mode w args} {
                if {$last_clicked ne {}} {
                        set lno [lindex $last_clicked 1]
                } else {
-                       if {[llength $file_lists($w)] == 0} {
+                       if {![info exists file_lists]
+                               || ![info exists file_lists($w)]
+                               || [llength $file_lists($w)] == 0} {
                                set last_clicked {}
                                return
                        }
@@ -2519,7 +2521,13 @@ proc toggle_or_diff {mode w args} {
                }
        }
 
-       set path [lindex $file_lists($w) [expr {$lno - 1}]]
+       if {![info exists file_lists]
+               || ![info exists file_lists($w)]
+               || [llength $file_lists($w)] < $lno - 1} {
+               set path {}
+       } else {
+               set path [lindex $file_lists($w) [expr {$lno - 1}]]
+       }
        if {$path eq {}} {
                set last_clicked {}
                return