[PATCH v2 1/1] git-gui: protect rev-parse --show-toplevel call
- From
- Shroom Moo <egg_mushroomcow@foxmail.com>
- Date
- Apr 29, 2026, 17:32 UTC
- Message-ID
- <tencent_AEE968E8E785907BA55A383977C8968ED406@qq.com>
- In-Reply-To
- <308229f2-0d20-4f3b-8e6a-c962bd9c3a6e@kdbg.org>
When starting git-gui from a directory that is a bare repository or where the working tree is missing, git-gui previously executed 'rev-parse --show-toplevel' without error handling. This caused a fatal Tcl error ("this operation must be run in a work tree").
Wrap the call in a catch to prevent the fatal error. The existing error paths after this call already handle bare repos and missing worktrees appropriately.
Signed-off-by: Shroom Moo <egg_mushroomcow@foxmail.com> --- git-gui/git-gui.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh index 23fe76e498..aee37685e1 100755 --- a/git-gui/git-gui.sh +++ b/git-gui/git-gui.sh @@ -1169,7 +1169,9 @@ if {![file isdirectory $_gitdir]} { load_config 0 apply_config -set _gitworktree [git rev-parse --show-toplevel] +if {[catch {set _gitworktree [git rev-parse --show-toplevel]}]} { + set _gitworktree {} +} if {$_prefix ne {}} { if {$_gitworktree eq {}} {
-- 2.52.0.windows.1