On Thu, Jan 23, 2020 at 11:20:36AM -0800, Junio C Hamano wrote: > Use the gitworktree helper introduced in 65bb0bda ("gitk: Fix the > display of files when filtered by path", 2011-12-13), which is > prepared to see failures from "rev-parse --show-toplevel" and other > means it tries to find the top-level of the working tree instead to > work around this issue. The resulting value in $worktree global, > when run in a bare repository, is bogus, but the code is not > prepared to run external diff correctly without a working tree > anyway ;-) > > Helped-by: Eric Sunshine <sunshine@xxxxxxxxxxxxxx> > Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> > --- > diff --git a/gitk b/gitk > @@ -12599,7 +12599,7 @@ set cdup {} > if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} { > set cdup [exec git rev-parse --show-cdup] > } > -set worktree [exec git rev-parse --show-toplevel] > +set worktree [gitworktree] This helps but doesn't quite make it functional due to a bug in gitworktree() which results in: Error in startup script: can't read "_gitworktree": no such variable while executing "if {$_gitworktree eq ""} { So, to make this work, it also needs: --- >8 --- diff --git a/gitk-git/gitk b/gitk-git/gitk index abe4805ade..8cbca113e3 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -34,8 +34,7 @@ proc gitworktree {} { # cdup to obtain a relative path to the top of the worktree. If # run from the top, the ./ prefix ensures normalize expands pwd. if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} { - catch {set _gitworktree [exec git config --get core.worktree]} - if {$_gitworktree eq ""} { + if {[catch {set _gitworktree [exec git config --get core.worktree]}]} { set _gitworktree [file normalize ./[exec git rev-parse --show-cdup]] } } --- >8 ---