Skip to content

Commit 38ec8d3

Browse files
committed
git-gui: correct assignment of work-tree
git-gui currently uses its own logic to determine the work-tree setting but 'git rev-parse --toplevel' directly returns git's work-tree value by calling get_git_work_tree() and is therefore always correct. This fixes an inability to handle some repository configurations. In particular where .git is a file containing a path to the real directory (a cross-platform symbolic link). To continue to support older versions than 1.7.0, setting the work-tree by normalizing the --show-cdup value is more reliable as git-dir might be outside the work-tree entirely. Signed-off-by: Pat Thoyts <[email protected]>
1 parent 4c56d1d commit 38ec8d3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

git-gui.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,13 +1194,22 @@ if {![file isdirectory $_gitdir]} {
11941194
# _gitdir exists, so try loading the config
11951195
load_config 0
11961196
apply_config
1197-
# try to set work tree from environment, falling back to core.worktree
1198-
if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1199-
set _gitworktree [get_config core.worktree]
1200-
if {$_gitworktree eq ""} {
1201-
set _gitworktree [file dirname [file normalize $_gitdir]]
1197+
1198+
# v1.7.0 introduced --show-toplevel to return the canonical work-tree
1199+
if {[package vsatisfies $_git_version 1.7.0]} {
1200+
set _gitworktree [git rev-parse --show-toplevel]
1201+
} else {
1202+
# try to set work tree from environment, core.worktree or use
1203+
# cdup to obtain a relative path to the top of the worktree. If
1204+
# run from the top, the ./ prefix ensures normalize expands pwd.
1205+
if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1206+
set _gitworktree [get_config core.worktree]
1207+
if {$_gitworktree eq ""} {
1208+
set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1209+
}
12021210
}
12031211
}
1212+
12041213
if {$_prefix ne {}} {
12051214
if {$_gitworktree eq {}} {
12061215
regsub -all {[^/]+/} $_prefix ../ cdup

0 commit comments

Comments
 (0)