Code

gitk: Avoid Tcl error when switching views
[git.git] / gitk
diff --git a/gitk b/gitk
index 5a78a916e48fff5bd43b5bf32d8a25f7c87022ff..84ab02e15f6bdecdd04e8835e3aefd0875efea44 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -403,6 +403,9 @@ proc readcommit {id} {
 proc updatecommits {} {
     global viewdata curview phase displayorder ordertok idpending
     global children commitrow selectedline thickerline showneartags
+    global isworktree
+
+    set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
 
     if {$phase ne {}} {
        stop_rev_list
@@ -2099,8 +2102,6 @@ proc showview {n} {
        set ybot [expr {[lindex $span 1] * $ymax}]
        if {$ytop < $y && $y < $ybot} {
            set yscreen [expr {$y - $ytop}]
-       } else {
-           set yscreen [expr {($ybot - $ytop) / 2}]
        }
     } elseif {[info exists pending_select]} {
        set selid $pending_select
@@ -2161,7 +2162,7 @@ proc showview {n} {
     set yf 0
     set row {}
     set selectfirst 0
-    if {$selid ne {} && [info exists commitrow($n,$selid)]} {
+    if {[info exists yscreen] && [info exists commitrow($n,$selid)]} {
        set row $commitrow($n,$selid)
        # try to get the selected row in the same position on the screen
        set ymax [lindex [$canv cget -scrollregion] 3]
@@ -2885,8 +2886,9 @@ proc dohidelocalchanges {} {
 # spawn off a process to do git diff-index --cached HEAD
 proc dodiffindex {} {
     global localirow localfrow lserial showlocalchanges
+    global isworktree
 
-    if {!$showlocalchanges} return
+    if {!$showlocalchanges || !$isworktree} return
     incr lserial
     set localfrow -1
     set localirow -1
@@ -8698,6 +8700,7 @@ set patchnum 0
 set localirow -1
 set localfrow -1
 set lserial 0
+set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
 setcoords
 makewindow
 # wait for the window to become visible