[PATCH v1 09/11] git-gui: support using repository parent dir as a worktree
- From
Mark Levedahl <mlevedahl@gmail.com>
- Date
- May 14, 2026, 14:33 UTC
- Message-ID
- <20260514143322.865587-10-mlevedahl@gmail.com>
- In-Reply-To
- <20260514143322.865587-1-mlevedahl@gmail.com>
git-gui, since 87cd09f43e ("git-gui: work from the .git dir", 2010-01-23), has had the intent to allow starting from inside a repository, then switching to the parent directory if that is a valid worktree.
This certainly hasn't worked since 2d92ab32fd ("rev-parse: make --show-toplevel without a worktree an error", 2019-11-19) in git, but breaking this git-gui feature was unintentional.
Add a proc to test if the parent of the git repository is a valid worktree, and set that directory as the worktree if so. Use invocations of git rev-parse to assure all validity and safety checks included in git-core are executed. --- git-gui.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/git-gui.sh b/git-gui.sh index a03eaa7..e326401 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1100,6 +1100,23 @@ unset argv0dir ## ## repository setup +proc is_parent_worktree {} { + # Directory 'parent' of a repository named 'parent/.git' might be the worktree + set ok 0 + if {[file tail $::_gitdir] eq {.git}} { + set gitdir_parent [file join $::_gitdir {..}] + set expected_worktree [file normalize $gitdir_parent] + catch {set git_worktree [git -C $gitdir_parent rev-parse --show-toplevel]} + if {[string compare $expected_worktree $git_worktree] == 0} { + set ::_prefix {} + set ::_gitworktree $git_worktree + cd $git_worktree + set ok 1 + } + } + return $ok +} + proc is_gitvars_error {err} { set havevars 0 set GIT_DIR {}
-- 2.54.0.99.14