@matheusbsbs / matheus-bagliano / commits / 29e5573d1e
Fork 0

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 <giuseppe.bilotta@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Giuseppe Bilotta committed Jan 23, 2010 at 11:03 UTC 29e5573d1ef67c92314c39e55d26504fee119c04
1 file changed +36 -7
git-gui.sh
+36 -7
@@ -122,6 +122,7 @@ unset oguimsg
122 set _appname {Git Gui}
123 set _gitdir {}
124 set _gitworktree {}
125 +set _isbare {}
126 set _gitexec {}
127 set _githtmldir {}
128 set _reponame {}
@@ -277,6 +278,32 @@ proc get_config {name} {
278 }
279 }
280
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 +
307 ######################################################################
308 ##
309 ## handy utils
@@ -1122,9 +1149,9 @@ if {$_prefix ne {}} {
1149 set _gitworktree [pwd]
1150 unset cdup
1151 } elseif {![is_enabled bare]} {
1125 - if {[lindex [file split $_gitdir] end] ne {.git}} {
1152 + if {[is_bare]} {
1153 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"]
1155 exit 1
1156 }
1157 if {$_gitworktree eq {}} {
@@ -1973,7 +2000,7 @@ proc do_gitk {revs {is_submodule false}} {
2000 set pwd [pwd]
2001
2002 if {!$is_submodule} {
1976 - if {$_gitworktree ne {}} {
2003 + if {![is_bare]} {
2004 cd $_gitworktree
2005 }
2006 set env(GIT_DIR) [file normalize [gitdir]]
@@ -2457,10 +2484,12 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2484 #
2485 menu .mbar.repository
2486
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 +}
2493
2494 .mbar.repository add command \
2495 -label [mc "Browse Current Branch's Files"] \