[PATCH v6 2/3] git-gui: disable gitk visualization when no worktree available
- From
- Shroom Moo <egg_mushroomcow@foxmail.com>
- Date
- May 6, 2026, 20:27 UTC
- Message-ID
- <tencent_02420881568A85BB718B6E7949E18FDE7D0A@qq.com>
- In-Reply-To
- <20260506202751.3294-1-egg_mushroomcow@foxmail.com>
When git-gui is started in a bare repository with the 'bare' option enabled (e.g., for blame/browser), there is no working tree. The "Visualize Current Branch's History" and "Visualize All Branch History" menu items remain enabled, but clicking them triggers a Tcl error because do_gitk tries to change directory to an empty _gitworktree.
Fix this by disabling the two visualization menu items when the repository is bare and the 'bare' option is active. Also update current_branch_write to keep the state consistent when the branch changes, and add a defensive check in do_gitk to avoid the error should the menu state somehow become out of sync.
This complements the startup sequence improvements in the previous commit, which already correctly identifies bare repositories and leaves _gitworktree empty in such cases.
Helped-by: Mark Levedahl <mlevedahl@gmail.com> Helped-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Shroom Moo <egg_mushroomcow@foxmail.com> --- git-gui/git-gui.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh index fbdc0b2a41..1191e6654c 100755 --- a/git-gui/git-gui.sh +++ b/git-gui/git-gui.sh @@ -2034,6 +2034,10 @@ proc do_gitk {revs {is_submodule false}} { # set exe [_which gitk -script] set cmd [list [info nameofexecutable] $exe] + if {$_gitworktree eq {}} { + error_popup [mc "Cannot visualize history: no working tree"] + return + } if {$exe eq {}} { error_popup [mc "Couldn't find gitk in PATH"] } else { @@ -2657,6 +2661,13 @@ set ui_visualize_current [.mbar.repository index last] .mbar.repository add command \ -label [mc "Visualize All Branch History"] \ -command {do_gitk --all} +set ui_visualize_all [.mbar.repository index last] + +# Cannot work without a working tree +if {[is_bare] && [is_enabled bare]} { + .mbar.repository entryconf $ui_visualize_current -state disabled + .mbar.repository entryconf $ui_visualize_all -state disabled +} .mbar.repository add separator proc current_branch_write {args} { @@ -2665,6 +2676,13 @@ proc current_branch_write {args} { -label [mc "Browse %s's Files" $current_branch] .mbar.repository entryconf $::ui_visualize_current \ -label [mc "Visualize %s's History" $current_branch] + if {[is_bare] && [is_enabled bare]} { + .mbar.repository entryconf $::ui_visualize_current -state disabled + .mbar.repository entryconf $::ui_visualize_all -state disabled + } else { + .mbar.repository entryconf $::ui_visualize_current -state normal + .mbar.repository entryconf $::ui_visualize_all -state normal + } } trace add variable current_branch write current_branch_write
-- 2.52.0.windows.1