git-gui: use --absolute-git-dir

git-gui uses git rev-parse --git-dir to get the pathname of the discovered git repository. The returned value can be relative, and is '.' if the current directory is the top of the repository directory itself. git-gui has code to change '.' to [pwd] in this case so that subsequent logic runs. But, git rev-parse supports --absolute-git-dir from fac60b8925 ("rev-parse: add option for absolute or relative path formatting", 2020-12-13), and included in git 2.31. git-gui requires git >= 2.36, so this more useful form is always available. Use --absolute-git-dir to always get an absolute path, avoiding the need for other checks, and delete the now unneeded code to fix a relative _gitdir. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com> Signed-off-by: Johannes Sixt <j6t@kdbg.org>

Mark Levedahl committed May 31, 2026 at 19:02 UTC 9902c4cc9c466fa96f55865a21ca2f6867d723c0
1 file changed +3 -11
git-gui.sh
+3 -11
@@ -1145,16 +1145,15 @@ if {[catch {
1145 set _prefix {}
1146 }]
1147 && [catch {
1148 - # beware that from the .git dir this sets _gitdir to .
1149 - # and _prefix to the empty string
1150 - set _gitdir [git rev-parse --git-dir]
1148 + # beware that from the .git dir this sets _prefix to the empty string
1149 + set _gitdir [git rev-parse --absolute-git-dir]
1150 set _prefix [git rev-parse --show-prefix]
1151 } err]} {
1152 load_config 1
1153 apply_config
1154 choose_repository::pick
1155 if {[catch {
1157 - set _gitdir [git rev-parse --git-dir]
1156 + set _gitdir [git rev-parse --absolute-git-dir]
1157 } err]} {
1158 catch {wm withdraw .}
1159 error_popup [strcat [mc "Unusable repo/worktree:"] " [pwd] \n\n$err"]
@@ -1175,13 +1174,6 @@ if {$hashalgorithm eq "sha1"} {
1174 exit 1
1175 }
1176
1178 -# we expand the _gitdir when it's just a single dot (i.e. when we're being
1179 -# run from the .git dir itself) lest the routines to find the worktree
1180 -# get confused
1181 -if {$_gitdir eq "."} {
1182 - set _gitdir [pwd]
1183 -}
1184 -
1177 if {![file isdirectory $_gitdir]} {
1178 catch {wm withdraw .}
1179 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]