{"thread":{"id":"21876","subject":"[PATCHv3 (resend) 0/3] git-gui: more robust handling of fancy repos","startedAt":"2009-12-06T08:06:38Z","lastAt":"2009-12-06T08:06:41Z","messageCount":4,"participants":["Giuseppe Bilotta"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"129317","messageId":"1260086801-4331-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"21876","inReplyTo":null,"subject":"[PATCHv3 (resend) 0/3] git-gui: more robust handling of fancy repos","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-12-06T08:06:38Z","receivedAt":"2009-12-06T08:06:38Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"This is a resend with the patches rebased on current 'next'.\n\nThe first patch allows git gui to work with respotiories for which\nthe worktree is not the parent of the gitdir.\n\nThe second patch refactors bare repository detection, improves the error\nmessage if the bare support feature is disabled, and disabled\ninapplicable menu entries.\n\nThe third patch allows git-gui to work properly when launched from the\n.git directory itself, solving the issue Markus Heidelberg was having in\nhttp://thread.gmane.org/gmane.comp.version-control.git/115044\n\nGiuseppe Bilotta (3):\n  git-gui: handle non-standard worktree locations\n  git-gui: handle bare repos correctly\n  git-gui: work from the .git dir\n\n git-gui/git-gui.sh |   88 +++++++++++++++++++++++++++++++++++++++++++---------\n 1 files changed, 73 insertions(+), 15 deletions(-)\n"},{"id":"129320","messageId":"1260086801-4331-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"21876","inReplyTo":"1260086801-4331-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 (resend) 1/3] git-gui: handle non-standard worktree locations","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-12-06T08:06:39Z","receivedAt":"2009-12-06T08:06:39Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Don't rely on the git worktree being the updir of the gitdir, since it\nmight not be. Instead, define (and use) a new _gitworktree global\nvariable, setting it to $GIT_WORK_TREE if present, falling back to\ncore.worktree if defined, and finally to whatever we guess the correct\nworktree is. Getting core.worktree requires the config from the alleged\ngit dir _gitdir to be loaded early.\n\nSupporting non-standard worktree locations also breaks the git-gui\nassumption (made when calling gitk) that the worktree was the dirname of\n$_gitdir and that, by consequence, the git dir could be set to the tail\nof $_gitdir once we changed to the worktree root directory. Therefore,\nwe need to export a GIT_DIR environment variable set to the full,\nnormalized path of $_gitdir instead. We also skip changing to the worktree\ndirectory if it's empty (i.e. if we're working on a bare repository).\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-gui/git-gui.sh |   37 ++++++++++++++++++++++++++++---------\n 1 files changed, 28 insertions(+), 9 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 037a1f2..fc766ca 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -121,6 +121,7 @@ unset oguimsg\n \n set _appname {Git Gui}\n set _gitdir {}\n+set _gitworktree {}\n set _gitexec {}\n set _githtmldir {}\n set _reponame {}\n@@ -1090,13 +1091,25 @@ if {![file isdirectory $_gitdir]} {\n \terror_popup [strcat [mc \"Git directory not found:\"] \"\\n\\n$_gitdir\"]\n \texit 1\n }\n+# _gitdir exists, so try loading the config\n+load_config 0\n+apply_config\n+# try to set work tree from environment, falling back to core.worktree\n+if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {\n+\tset _gitworktree [get_config core.worktree]\n+}\n if {$_prefix ne {}} {\n-\tregsub -all {[^/]+/} $_prefix ../ cdup\n+\tif {$_gitworktree eq {}} {\n+\t\tregsub -all {[^/]+/} $_prefix ../ cdup\n+\t} else {\n+\t\tset cdup $_gitworktree\n+\t}\n \tif {[catch {cd $cdup} err]} {\n \t\tcatch {wm withdraw .}\n \t\terror_popup [strcat [mc \"Cannot move to top of working directory:\"] \"\\n\\n$err\"]\n \t\texit 1\n \t}\n+\tset _gitworktree [pwd]\n \tunset cdup\n } elseif {![is_enabled bare]} {\n \tif {[lindex [file split $_gitdir] end] ne {.git}} {\n@@ -1104,11 +1117,15 @@ if {$_prefix ne {}} {\n \t\terror_popup [strcat [mc \"Cannot use funny .git directory:\"] \"\\n\\n$_gitdir\"]\n \t\texit 1\n \t}\n-\tif {[catch {cd [file dirname $_gitdir]} err]} {\n+\tif {$_gitworktree eq {}} {\n+\t\tset _gitworktree [file dirname $_gitdir]\n+\t}\n+\tif {[catch {cd $_gitworktree} err]} {\n \t\tcatch {wm withdraw .}\n-\t\terror_popup [strcat [mc \"No working directory\"] \" [file dirname $_gitdir]:\\n\\n$err\"]\n+\t\terror_popup [strcat [mc \"No working directory\"] \" $_gitworktree:\\n\\n$err\"]\n \t\texit 1\n \t}\n+\tset _gitworktree [pwd]\n }\n set _reponame [file split [file normalize $_gitdir]]\n if {[lindex $_reponame end] eq {.git}} {\n@@ -1921,6 +1938,7 @@ proc incr_font_size {font {amt 1}} {\n set starting_gitk_msg [mc \"Starting gitk... please wait...\"]\n \n proc do_gitk {revs} {\n+\tglobal _gitworktree\n \t# -- Always start gitk through whatever we were loaded with.  This\n \t#    lets us bypass using shell process on Windows systems.\n \t#\n@@ -1938,8 +1956,10 @@ proc do_gitk {revs} {\n \t\t}\n \n \t\tset pwd [pwd]\n-\t\tcd [file dirname [gitdir]]\n-\t\tset env(GIT_DIR) [file tail [gitdir]]\n+\t\tif { $_gitworktree ne {} } {\n+\t\t\tcd $_gitworktree\n+\t\t}\n+\t\tset env(GIT_DIR) [file normalize [gitdir]]\n \n \t\teval exec $cmd $revs &\n \n@@ -1958,6 +1978,7 @@ proc do_gitk {revs} {\n }\n \n proc do_explore {} {\n+\tglobal _gitworktree\n \tset explorer {}\n \tif {[is_Cygwin] || [is_Windows]} {\n \t\tset explorer \"explorer.exe\"\n@@ -1967,7 +1988,7 @@ proc do_explore {} {\n \t\t# freedesktop.org-conforming system is our best shot\n \t\tset explorer \"xdg-open\"\n \t}\n-\teval exec $explorer [list [file nativename [file dirname [gitdir]]]] &\n+\teval exec $explorer $_gitworktree &\n }\n \n set is_quitting 0\n@@ -2326,8 +2347,6 @@ proc show_less_context {} {\n ##\n ## ui construction\n \n-load_config 0\n-apply_config\n set ui_comm {}\n \n # -- Menu Bar\n@@ -3365,7 +3384,7 @@ unset i\n set file_lists($ui_index) [list]\n set file_lists($ui_workdir) [list]\n \n-wm title . \"[appname] ([reponame]) [file normalize [file dirname [gitdir]]]\"\n+wm title . \"[appname] ([reponame]) [file normalize $_gitworktree]\"\n focus -force $ui_comm\n \n # -- Warn the user about environmental problems.  Cygwin's Tcl\n-- \n1.6.5.4\n"},{"id":"129319","messageId":"1260086801-4331-3-git-send-email-giuseppe.bilotta@gmail.com","threadId":"21876","inReplyTo":"1260086801-4331-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 (resend) 2/3] git-gui: handle bare repos correctly","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-12-06T08:06:40Z","receivedAt":"2009-12-06T08:06:40Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Refactor checking for a bare repository into its own proc, that relies\non git rev-parse --is-bare-repository if possible. For older versions of\ngit we fall back to a logic such that the repository is considered bare\nif:\n * either the core.bare setting is true\n * or the worktree is not set and the directory name ends with .git\nThe error message for the case of an unhandled bare repository is also\nupdated to reflect the fact that the problem is not the funny name but\nthe bareness.\n\nThe new refactored proc is also used to disable the menu entry to\nexplore the working copy, and to skip changing to the worktree before\nthe gitk invocation.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-gui/git-gui.sh |   43 ++++++++++++++++++++++++++++++++++++-------\n 1 files changed, 36 insertions(+), 7 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex fc766ca..99ca4c0 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -122,6 +122,7 @@ unset oguimsg\n set _appname {Git Gui}\n set _gitdir {}\n set _gitworktree {}\n+set _isbare {}\n set _gitexec {}\n set _githtmldir {}\n set _reponame {}\n@@ -277,6 +278,32 @@ proc get_config {name} {\n \t}\n }\n \n+proc is_bare {} {\n+\tglobal _isbare\n+\tglobal _gitdir\n+\tglobal _gitworktree\n+\n+\tif {$_isbare eq {}} {\n+\t\tif {[catch {\n+\t\t\tset _bare [git rev-parse --is-bare-repository]\n+\t\t\tswitch  -- $_bare {\n+\t\t\ttrue { set _isbare 1 }\n+\t\t\tfalse { set _isbare 0}\n+\t\t\tdefault { throw }\n+\t\t\t}\n+\t\t}]} {\n+\t\t\tif {[is_config_true core.bare]\n+\t\t\t\t|| ($_gitworktree eq {}\n+\t\t\t\t\t&& [lindex [file split $_gitdir] end] ne {.git})} {\n+\t\t\t\tset _isbare 1\n+\t\t\t} else {\n+\t\t\t\tset _isbare 0\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn $_isbare\n+}\n+\n ######################################################################\n ##\n ## handy utils\n@@ -1112,9 +1139,9 @@ if {$_prefix ne {}} {\n \tset _gitworktree [pwd]\n \tunset cdup\n } elseif {![is_enabled bare]} {\n-\tif {[lindex [file split $_gitdir] end] ne {.git}} {\n+\tif {[is_bare]} {\n \t\tcatch {wm withdraw .}\n-\t\terror_popup [strcat [mc \"Cannot use funny .git directory:\"] \"\\n\\n$_gitdir\"]\n+\t\terror_popup [strcat [mc \"Cannot use bare repository:\"] \"\\n\\n$_gitdir\"]\n \t\texit 1\n \t}\n \tif {$_gitworktree eq {}} {\n@@ -1956,7 +1983,7 @@ proc do_gitk {revs} {\n \t\t}\n \n \t\tset pwd [pwd]\n-\t\tif { $_gitworktree ne {} } {\n+\t\tif { ![is_bare] } {\n \t\t\tcd $_gitworktree\n \t\t}\n \t\tset env(GIT_DIR) [file normalize [gitdir]]\n@@ -2378,10 +2405,12 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {\n #\n menu .mbar.repository\n \n-.mbar.repository add command \\\n-\t-label [mc \"Explore Working Copy\"] \\\n-\t-command {do_explore}\n-.mbar.repository add separator\n+if {![is_bare]} {\n+\t.mbar.repository add command \\\n+\t\t-label [mc \"Explore Working Copy\"] \\\n+\t\t-command {do_explore}\n+\t.mbar.repository add separator\n+}\n \n .mbar.repository add command \\\n \t-label [mc \"Browse Current Branch's Files\"] \\\n-- \n1.6.5.4\n"},{"id":"129318","messageId":"1260086801-4331-4-git-send-email-giuseppe.bilotta@gmail.com","threadId":"21876","inReplyTo":"1260086801-4331-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 (resend) 3/3] git-gui: work from the .git dir","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-12-06T08:06:41Z","receivedAt":"2009-12-06T08:06:41Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"When git-gui is run from a .git dir, _gitdir would be set to \".\" by\nrev-parse, something that confuses the worktree detection.\n\nFix by expanding the value of _gitdir to pwd in this special case.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-gui/git-gui.sh |   10 ++++++++++\n 1 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 99ca4c0..0497e38 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -1102,6 +1102,8 @@ if {[catch {\n \t\tset _prefix {}\n \t\t}]\n \t&& [catch {\n+\t\t# beware that from the .git dir this sets _gitdir to .\n+\t\t# and _prefix to the empty string\n \t\tset _gitdir [git rev-parse --git-dir]\n \t\tset _prefix [git rev-parse --show-prefix]\n \t} err]} {\n@@ -1110,6 +1112,14 @@ if {[catch {\n \tchoose_repository::pick\n \tset picked 1\n }\n+\n+# we expand the _gitdir when it's just a single dot (i.e. when we're being\n+# run from the .git dir itself) lest the routines to find the worktree\n+# get confused\n+if {$_gitdir eq \".\"} {\n+\tset _gitdir [pwd]\n+}\n+\n if {![file isdirectory $_gitdir] && [is_Cygwin]} {\n \tcatch {set _gitdir [exec cygpath --windows $_gitdir]}\n }\n-- \n1.6.5.4\n"}]}