Skip to content

Commit e272a77

Browse files
gitsterpaulusmack
authored andcommitted
gitk: be prepared to be run in a bare repository
784b7e2 ("gitk: Fix "External diff" with separate work tree", 2011-04-04) added an unconditional call to "git rev-parse --show-toplevel" to set up a global variable quite early in the course of the program, so that the location of the working tree can later be known if/when the user chooses to run the external diff via the external_diff_get_one_file proc. Before that change, the external diff code used to assume that the parent directory of ".git" directory is the top-level of the working tree. Recent versions of git however notices that "rev-parse --show-toplevel" executed in a bare repository is an error, which makes gitk stop, even before the user could attempt to run external diff. Use the gitworktree helper introduced in 65bb0bd ("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 ;-) [[email protected] - folded in fix from Eric Sunshine] Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent c1a6345 commit e272a77

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

gitk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ proc gitworktree {} {
3434
# cdup to obtain a relative path to the top of the worktree. If
3535
# run from the top, the ./ prefix ensures normalize expands pwd.
3636
if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
37-
catch {set _gitworktree [exec git config --get core.worktree]}
38-
if {$_gitworktree eq ""} {
37+
if {[catch {set _gitworktree [exec git config --get core.worktree]}]} {
3938
set _gitworktree [file normalize ./[exec git rev-parse --show-cdup]]
4039
}
4140
}
@@ -12603,7 +12602,7 @@ set cdup {}
1260312602
if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
1260412603
set cdup [exec git rev-parse --show-cdup]
1260512604
}
12606-
set worktree [exec git rev-parse --show-toplevel]
12605+
set worktree [gitworktree]
1260712606
setcoords
1260812607
makewindow
1260912608
catch {

0 commit comments

Comments
 (0)