Re: [PATCH] git-gui: handle bare repo or missing worktree
- From
- Shroom Moo <egg_mushroomcow@foxmail.com>
- Date
- Apr 29, 2026, 18:28 UTC
- Message-ID
- <tencent_38DC315B635248A3A19F1A426A95A3E19208@qq.com>
- In-Reply-To
- <308229f2-0d20-4f3b-8e6a-c962bd9c3a6e@kdbg.org>
Hi Hannes,
Thanks for taking a close look at the patch. You're right that the minimal crashfix is just protecting the `rev-parse --show-toplevel` call. The existing error paths after that line already handle bare repos and missing worktrees, showing an error dialog before exiting. That alone would prevent the fatal Tcl error –the original crash is fixed.
The extra logic is not about incomplete error diagnosis (the other checks cover that). It's about improving the user experience in the specific case that prompted this report: a colleague double-clicked git-gui.exe inside the Git installation directory, where a third-party program had accidentally left a HEAD file. That caused git to treat the directory as a bare repository, even though it has no . git folder. In that context, showing a "Cannot use bare repository" and quitting was confusing – the user simply started the program without choosing that path.
So the additional detection and the `choose_repository::pick` call are a UX improvement, not a correctness requirement. When the program detects that the current directory is an unusable repository, falling back to the repository-selection dialog (as we do when no repository is found) is better than failing with an error. The user can pick a valid repository and continue without restarting the GUI.
Since a minimal patch is preferred, I have prepared v2 which only protects `--show-toplevel`. The dialog fallback could be revisited as a separate enhancement if desired. I've already sent the v2 patch to the list.
-- Shroom