]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: simplify [is_bare] to report if a worktree is known
authorMark Levedahl <mlevedahl@gmail.com>
Sun, 31 May 2026 23:02:21 +0000 (19:02 -0400)
committerJohannes Sixt <j6t@kdbg.org>
Tue, 2 Jun 2026 17:13:13 +0000 (19:13 +0200)
git-gui includes proc is_bare, used in several places to make decisions
on whether a worktree exists, but also in discovery to tell if a
worktree can be supported.

But, is_bare is out of date with regard to multiple worktrees, safe
repository guards, and possibly other relevant features known to git
rev-parse. Also, is_bare caches its result on the first call, so is not
useful if a later step in the discovery process finds a worktree.

So, simplify is_bare to report whether git-gui has a worktree or is
working only from a repository.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
git-gui.sh

index 66379f290f99d869006595314dc50d6c880199fb..44dcb5ffaf34fbf0073e3bc629fab15496f535f8 100755 (executable)
@@ -372,7 +372,6 @@ if {[tk windowingsystem] eq "aqua"} {
 set _appname {Git Gui}
 set _gitdir {}
 set _gitworktree {}
-set _isbare {}
 set _githtmldir {}
 set _prefix {}
 set _reponame {}
@@ -524,29 +523,7 @@ proc get_config {name} {
 }
 
 proc is_bare {} {
-       global _isbare
-       global _gitdir
-       global _gitworktree
-
-       if {$_isbare eq {}} {
-               if {[catch {
-                       set _bare [git rev-parse --is-bare-repository]
-                       switch  -- $_bare {
-                       true { set _isbare 1 }
-                       false { set _isbare 0}
-                       default { throw }
-                       }
-               }]} {
-                       if {[is_config_true core.bare]
-                               || ($_gitworktree eq {}
-                                       && [lindex [file split $_gitdir] end] ne {.git})} {
-                               set _isbare 1
-                       } else {
-                               set _isbare 0
-                       }
-               }
-       }
-       return $_isbare
+       return [expr {$::_gitworktree eq {}}]
 }
 
 ######################################################################