Skip to content

Commit 29e5573

Browse files
Oblomovspearce
authored andcommitted
git-gui: handle bare repos correctly
Refactor checking for a bare repository into its own proc, that relies on git rev-parse --is-bare-repository if possible. For older versions of git we fall back to a logic such that the repository is considered bare if: * either the core.bare setting is true * or the worktree is not set and the directory name ends with .git The error message for the case of an unhandled bare repository is also updated to reflect the fact that the problem is not the funny name but the bareness. The new refactored proc is also used to disable the menu entry to explore the working copy, and to skip changing to the worktree before the gitk invocation. Signed-off-by: Giuseppe Bilotta <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 21985a1 commit 29e5573

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

git-gui.sh

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ unset oguimsg
122122
set _appname {Git Gui}
123123
set _gitdir {}
124124
set _gitworktree {}
125+
set _isbare {}
125126
set _gitexec {}
126127
set _githtmldir {}
127128
set _reponame {}
@@ -277,6 +278,32 @@ proc get_config {name} {
277278
}
278279
}
279280

281+
proc is_bare {} {
282+
global _isbare
283+
global _gitdir
284+
global _gitworktree
285+
286+
if {$_isbare eq {}} {
287+
if {[catch {
288+
set _bare [git rev-parse --is-bare-repository]
289+
switch -- $_bare {
290+
true { set _isbare 1 }
291+
false { set _isbare 0}
292+
default { throw }
293+
}
294+
}]} {
295+
if {[is_config_true core.bare]
296+
|| ($_gitworktree eq {}
297+
&& [lindex [file split $_gitdir] end] ne {.git})} {
298+
set _isbare 1
299+
} else {
300+
set _isbare 0
301+
}
302+
}
303+
}
304+
return $_isbare
305+
}
306+
280307
######################################################################
281308
##
282309
## handy utils
@@ -1122,9 +1149,9 @@ if {$_prefix ne {}} {
11221149
set _gitworktree [pwd]
11231150
unset cdup
11241151
} elseif {![is_enabled bare]} {
1125-
if {[lindex [file split $_gitdir] end] ne {.git}} {
1152+
if {[is_bare]} {
11261153
catch {wm withdraw .}
1127-
error_popup [strcat [mc "Cannot use funny .git directory:"] "\n\n$_gitdir"]
1154+
error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
11281155
exit 1
11291156
}
11301157
if {$_gitworktree eq {}} {
@@ -1973,7 +2000,7 @@ proc do_gitk {revs {is_submodule false}} {
19732000
set pwd [pwd]
19742001
19752002
if {!$is_submodule} {
1976-
if {$_gitworktree ne {}} {
2003+
if {![is_bare]} {
19772004
cd $_gitworktree
19782005
}
19792006
set env(GIT_DIR) [file normalize [gitdir]]
@@ -2457,10 +2484,12 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {
24572484
#
24582485
menu .mbar.repository
24592486
2460-
.mbar.repository add command \
2461-
-label [mc "Explore Working Copy"] \
2462-
-command {do_explore}
2463-
.mbar.repository add separator
2487+
if {![is_bare]} {
2488+
.mbar.repository add command \
2489+
-label [mc "Explore Working Copy"] \
2490+
-command {do_explore}
2491+
.mbar.repository add separator
2492+
}
24642493
24652494
.mbar.repository add command \
24662495
-label [mc "Browse Current Branch's Files"] \

0 commit comments

Comments
 (0)