@matheusbsbs / matheus-bagliano / commits / 38ec8d3e26
Fork 0

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>

Pat Thoyts committed Oct 20, 2010 at 14:29 UTC 38ec8d3e265220fb091b8c5ad6233b502242f866
1 file changed +14 -5
git-gui.sh
+14 -5
@@ -1194,13 +1194,22 @@ if {![file isdirectory $_gitdir]} {
1194 # _gitdir exists, so try loading the config
1195 load_config 0
1196 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 + }
1210 }
1211 }
1212 +
1213 if {$_prefix ne {}} {
1214 if {$_gitworktree eq {}} {
1215 regsub -all {[^/]+/} $_prefix ../ cdup