diff options
author | Pat Thoyts <patthoyts@users.sourceforge.net> | 2010-10-20 14:29:56 +0100 |
---|---|---|
committer | Pat Thoyts <patthoyts@users.sourceforge.net> | 2010-10-20 14:29:56 +0100 |
commit | 38ec8d3e265220fb091b8c5ad6233b502242f866 (patch) | |
tree | d1573048e28d3bfc76cd209be7e19f469b338037 | |
parent | git-gui: use full dialog width for old name when renaming branch (diff) | |
download | tgif-38ec8d3e265220fb091b8c5ad6233b502242f866.tar.xz |
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 <patthoyts@users.sourceforge.net>
-rwxr-xr-x | git-gui.sh | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/git-gui.sh b/git-gui.sh index 25229a4073..5e8378fc3e 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1194,13 +1194,22 @@ if {![file isdirectory $_gitdir]} { # _gitdir exists, so try loading the config load_config 0 apply_config -# try to set work tree from environment, falling back to core.worktree -if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} { - set _gitworktree [get_config core.worktree] - if {$_gitworktree eq ""} { - set _gitworktree [file dirname [file normalize $_gitdir]] + +# v1.7.0 introduced --show-toplevel to return the canonical work-tree +if {[package vsatisfies $_git_version 1.7.0]} { + set _gitworktree [git rev-parse --show-toplevel] +} else { + # try to set work tree from environment, core.worktree or use + # 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) }]} { + set _gitworktree [get_config core.worktree] + if {$_gitworktree eq ""} { + set _gitworktree [file normalize ./[git rev-parse --show-cdup]] + } } } + if {$_prefix ne {}} { if {$_gitworktree eq {}} { regsub -all {[^/]+/} $_prefix ../ cdup |