{"thread":{"id":"22355","subject":"[PATCHv4 1/5] git-gui: handle non-standard worktree locations","startedAt":"2010-01-23T10:03:33Z","lastAt":"2010-01-24T00:03:05Z","messageCount":9,"participants":["Giuseppe Bilotta","Shawn O. Pearce"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"132469","messageId":"1264241018-6616-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22355","inReplyTo":null,"subject":"[PATCHv4 0/5] git-gui: more robust handling of fancy repos","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-01-23T10:03:33Z","receivedAt":"2010-01-23T10:03:33Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"A re-issue of the patchest to make git-gui more robust towards\nnon-standard repository setup, with two additional fixes.\n\nThe first three patches are unchanged from the previous iteration (still\nwaiting for review, actually).\n\nThe 4th sets GIT_DIR and GIT_WORK_TREE in git-gui to ensure that all\nexternal tool invocation work in the same setup.\n\nThe last one also updates the shortcut library to make use of\n_gitworktree instead of the old assumption that the worktree is the\nupdir of the git dir. I can't really test this patch though because\nI don't have Windows.\n\n\nGiuseppe Bilotta (5):\n  git-gui: handle non-standard worktree locations\n  git-gui: handle bare repos correctly\n  git-gui: work from the .git dir\n  git-gui: set GIT_DIR and GIT_WORK_TREE after setup\n  git-gui: update shortcut tools to use _gitworktree\n\n git-gui/git-gui.sh       |  101 ++++++++++++++++++++++++++++++++++------------\n git-gui/lib/shortcut.tcl |    7 ++-\n 2 files changed, 79 insertions(+), 29 deletions(-)\n"},{"id":"132468","messageId":"1264241018-6616-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22355","inReplyTo":"1264241018-6616-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv4 1/5] git-gui: handle non-standard worktree locations","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-01-23T10:03:34Z","receivedAt":"2010-01-23T10:03:34Z","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 718277a..7e633f4 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@@ -2331,8 +2352,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@@ -3370,7 +3389,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.6.rc1.295.g3a4e71\n"},{"id":"132473","messageId":"1264241018-6616-3-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22355","inReplyTo":"1264241018-6616-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv4 2/5] git-gui: handle bare repos correctly","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-01-23T10:03:35Z","receivedAt":"2010-01-23T10:03:35Z","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 7e633f4..d0dff40 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@@ -2383,10 +2410,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.6.rc1.295.g3a4e71\n"},{"id":"132471","messageId":"1264241018-6616-4-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22355","inReplyTo":"1264241018-6616-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv4 3/5] git-gui: work from the .git dir","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-01-23T10:03:36Z","receivedAt":"2010-01-23T10:03:36Z","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 d0dff40..c5c787d 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.6.rc1.295.g3a4e71\n"},{"id":"132470","messageId":"1264241018-6616-5-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22355","inReplyTo":"1264241018-6616-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv4 4/5] git-gui: set GIT_DIR and GIT_WORK_TREE after setup","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-01-23T10:03:37Z","receivedAt":"2010-01-23T10:03:37Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Rather than juggling $GIT_DIR around the invocation of gitk, set it\n(and $GIT_WORK_TREE) after finishing setup, ensuring that any external\ntool works with the setup we're running with.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-gui/git-gui.sh |   15 +++------------\n 1 files changed, 3 insertions(+), 12 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex c5c787d..aff0644 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -1171,6 +1171,9 @@ if {[lindex $_reponame end] eq {.git}} {\n \tset _reponame [lindex $_reponame end]\n }\n \n+set env(GIT_DIR) $_gitdir\n+set env(GIT_WORK_TREE) $_gitworktree\n+\n ######################################################################\n ##\n ## global init\n@@ -1986,25 +1989,13 @@ proc do_gitk {revs} {\n \t} else {\n \t\tglobal env\n \n-\t\tif {[info exists env(GIT_DIR)]} {\n-\t\t\tset old_GIT_DIR $env(GIT_DIR)\n-\t\t} else {\n-\t\t\tset old_GIT_DIR {}\n-\t\t}\n-\n \t\tset pwd [pwd]\n \t\tif { ![is_bare] } {\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-\t\tif {$old_GIT_DIR eq {}} {\n-\t\t\tunset env(GIT_DIR)\n-\t\t} else {\n-\t\t\tset env(GIT_DIR) $old_GIT_DIR\n-\t\t}\n \t\tcd $pwd\n \n \t\tui_status $::starting_gitk_msg\n-- \n1.6.6.rc1.295.g3a4e71\n"},{"id":"132472","messageId":"1264241018-6616-6-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22355","inReplyTo":"1264241018-6616-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv4 5/5] git-gui: update shortcut tools to use _gitworktree","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-01-23T10:03:38Z","receivedAt":"2010-01-23T10:03:38Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-gui/lib/shortcut.tcl |    7 ++++---\n 1 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/git-gui/lib/shortcut.tcl b/git-gui/lib/shortcut.tcl\nindex 2f20eb3..79c1888 100644\n--- a/git-gui/lib/shortcut.tcl\n+++ b/git-gui/lib/shortcut.tcl\n@@ -2,6 +2,7 @@\n # Copyright (C) 2006, 2007 Shawn Pearce\n \n proc do_windows_shortcut {} {\n+\tglobal _gitworktree\n \tset fn [tk_getSaveFile \\\n \t\t-parent . \\\n \t\t-title [append \"[appname] ([reponame]): \" [mc \"Create Desktop Icon\"]] \\\n@@ -15,7 +16,7 @@ proc do_windows_shortcut {} {\n \t\t\t\t\t[info nameofexecutable] \\\n \t\t\t\t\t[file normalize $::argv0] \\\n \t\t\t\t\t] \\\n-\t\t\t\t\t[file dirname [file normalize [gitdir]]]\n+\t\t\t\t\t[file normalize [$_gitworktree]]\n \t\t\t} err]} {\n \t\t\terror_popup [strcat [mc \"Cannot write shortcut:\"] \"\\n\\n$err\"]\n \t\t}\n@@ -23,7 +24,7 @@ proc do_windows_shortcut {} {\n }\n \n proc do_cygwin_shortcut {} {\n-\tglobal argv0\n+\tglobal argv0 _gitworktree\n \n \tif {[catch {\n \t\tset desktop [exec cygpath \\\n@@ -56,7 +57,7 @@ proc do_cygwin_shortcut {} {\n \t\t\t\t\t$sh -c \\\n \t\t\t\t\t\"CHERE_INVOKING=1 source /etc/profile;[sq $me] &\" \\\n \t\t\t\t\t] \\\n-\t\t\t\t\t[file dirname [file normalize [gitdir]]]\n+\t\t\t\t\t[file normalize [$_gitworktree]]\n \t\t\t} err]} {\n \t\t\terror_popup [strcat [mc \"Cannot write shortcut:\"] \"\\n\\n$err\"]\n \t\t}\n-- \n1.6.6.rc1.295.g3a4e71\n"},{"id":"132518","messageId":"20100123232215.GI12679@spearce.org","threadId":"22355","inReplyTo":"1264241018-6616-5-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCHv4 4/5] git-gui: set GIT_DIR and GIT_WORK_TREE after setup","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2010-01-23T23:22:15Z","receivedAt":"2010-01-23T23:22:15Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> wrote:\n> Rather than juggling $GIT_DIR around the invocation of gitk, set it\n> (and $GIT_WORK_TREE) after finishing setup, ensuring that any external\n> tool works with the setup we're running with.\n> \n> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n> ---\n>  git-gui/git-gui.sh |   15 +++------------\n>  1 files changed, 3 insertions(+), 12 deletions(-)\n\nThis patch has merge conflicts with changes from Jens Lehmann\nrelated to starting gitk inside of a submodule.  Since I merged\nhis menu code first, I would appreciate it if you could rebase this\none patch on top of my latest master:\n\n  git://git.spearce.org/git-gui.git master\n\n\nThe other 4 patches in this series are already applied, thanks.\n\n-- \nShawn.\n"},{"id":"132520","messageId":"1264291140-16595-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"22355","inReplyTo":"20100123232215.GI12679@spearce.org","subject":"[PATCH] git-gui: set GIT_DIR and GIT_WORK_TREE after setup","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2010-01-23T23:59:00Z","receivedAt":"2010-01-23T23:59:00Z","isPatch":true,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Rather than juggling with the env var GIT_DIR around the invocation of\ngitk, set it and GIT_WORK_TREE after finishing setup, ensuring that any\nexternal tool works with the setup we're running with.\n\nThis also allows us to remove a couple of conditionals when running gitk\nor git gui in a submodule, as we know that the variables are present and\nhave to be unset and reset before and after the invocation.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-gui.sh |   43 ++++++++++++++++++++-----------------------\n 1 files changed, 20 insertions(+), 23 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 5d39955..81143c7 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -1171,6 +1171,9 @@ if {[lindex $_reponame end] eq {.git}} {\n \tset _reponame [lindex $_reponame end]\n }\n \n+set env(GIT_DIR) $_gitdir\n+set env(GIT_WORK_TREE) $_gitworktree\n+\n ######################################################################\n ##\n ## global init\n@@ -1979,7 +1982,7 @@ set starting_gitk_msg [mc \"Starting gitk... please wait...\"]\n \n proc do_gitk {revs {is_submodule false}} {\n \tglobal current_diff_path file_states current_diff_side ui_index\n-\tglobal _gitworktree\n+\tglobal _gitdir _gitworktree\n \n \t# -- Always start gitk through whatever we were loaded with.  This\n \t#    lets us bypass using shell process on Windows systems.\n@@ -1991,19 +1994,12 @@ proc do_gitk {revs {is_submodule false}} {\n \t} else {\n \t\tglobal env\n \n-\t\tif {[info exists env(GIT_DIR)]} {\n-\t\t\tset old_GIT_DIR $env(GIT_DIR)\n-\t\t} else {\n-\t\t\tset old_GIT_DIR {}\n-\t\t}\n-\n \t\tset pwd [pwd]\n \n \t\tif {!$is_submodule} {\n \t\t\tif {![is_bare]} {\n \t\t\t\tcd $_gitworktree\n \t\t\t}\n-\t\t\tset env(GIT_DIR) [file normalize [gitdir]]\n \t\t} else {\n \t\t\tcd $current_diff_path\n \t\t\tif {$revs eq {--}} {\n@@ -2024,15 +2020,18 @@ proc do_gitk {revs {is_submodule false}} {\n \t\t\t\t}\n \t\t\t\tset revs $old_sha1...$new_sha1\n \t\t\t}\n-\t\t\tif {[info exists env(GIT_DIR)]} {\n-\t\t\t\tunset env(GIT_DIR)\n-\t\t\t}\n+\t\t\t# GIT_DIR and GIT_WORK_TREE for the submodule are not the ones\n+\t\t\t# we've been using for the main repository, so unset them.\n+\t\t\t# TODO we could make life easier (start up faster?) for gitk\n+\t\t\t# by setting these to the appropriate values to allow gitk\n+\t\t\t# to skip the heuristics to find their proper value\n+\t\t\tunset env(GIT_DIR)\n+\t\t\tunset env(GIT_WORK_TREE)\n \t\t}\n \t\teval exec $cmd $revs \"--\" \"--\" &\n \n-\t\tif {$old_GIT_DIR ne {}} {\n-\t\t\tset env(GIT_DIR) $old_GIT_DIR\n-\t\t}\n+\t\tset env(GIT_DIR) $_gitdir\n+\t\tset env(GIT_WORK_TREE) $_gitworktree\n \t\tcd $pwd\n \n \t\tui_status $::starting_gitk_msg\n@@ -2053,22 +2052,20 @@ proc do_git_gui {} {\n \t\terror_popup [mc \"Couldn't find git gui in PATH\"]\n \t} else {\n \t\tglobal env\n+\t\tglobal _gitdir _gitworktree\n \n-\t\tif {[info exists env(GIT_DIR)]} {\n-\t\t\tset old_GIT_DIR $env(GIT_DIR)\n-\t\t\tunset env(GIT_DIR)\n-\t\t} else {\n-\t\t\tset old_GIT_DIR {}\n-\t\t}\n+\t\t# see note in do_gitk about unsetting these vars when\n+\t\t# running tools in a submodule\n+\t\tunset env(GIT_DIR)\n+\t\tunset env(GIT_WORK_TREE)\n \n \t\tset pwd [pwd]\n \t\tcd $current_diff_path\n \n \t\teval exec $exe gui &\n \n-\t\tif {$old_GIT_DIR ne {}} {\n-\t\t\tset env(GIT_DIR) $old_GIT_DIR\n-\t\t}\n+\t\tset env(GIT_DIR) $_gitdir\n+\t\tset env(GIT_WORK_TREE) $_gitworktree\n \t\tcd $pwd\n \n \t\tui_status $::starting_gitk_msg\n-- \n1.6.6.rc1.295.g3a4e71\n"},{"id":"132521","messageId":"20100124000305.GK12679@spearce.org","threadId":"22355","inReplyTo":"1264291140-16595-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCH] git-gui: set GIT_DIR and GIT_WORK_TREE after setup","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2010-01-24T00:03:05Z","receivedAt":"2010-01-24T00:03:05Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> wrote:\n> Rather than juggling with the env var GIT_DIR around the invocation of\n> gitk, set it and GIT_WORK_TREE after finishing setup, ensuring that any\n> external tool works with the setup we're running with.\n> \n> This also allows us to remove a couple of conditionals when running gitk\n> or git gui in a submodule, as we know that the variables are present and\n> have to be unset and reset before and after the invocation.\n> \n> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n> ---\n>  git-gui.sh |   43 ++++++++++++++++++++-----------------------\n>  1 files changed, 20 insertions(+), 23 deletions(-)\n\nThanks, applied.\n\n-- \nShawn.\n"}]}