git-gui: set GIT_DIR and GIT_WORK_TREE after setup
Rather than juggling with the env var GIT_DIR around the invocation of gitk, set it and GIT_WORK_TREE after finishing setup, ensuring that any external tool works with the setup we're running with. This also allows us to remove a couple of conditionals when running gitk or git gui in a submodule, as we know that the variables are present and have to be unset and reset before and after the invocation. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Giuseppe Bilotta committed
Jan 24, 2010 at 00:59 UTC
a9fa11fe5bd5978bb175b3b5663f6477a345d428
1 file changed
+20
-23
git-gui.sh
+20
-23
@@ -1171,6 +1171,9 @@ if {[lindex $_reponame end] eq {.git}} {
1171
set _reponame [lindex $_reponame end]
1172
}
1173
1174
+set env(GIT_DIR) $_gitdir
1175
+set env(GIT_WORK_TREE) $_gitworktree
1176
+
1177
######################################################################
1178
##
1179
## global init
@@ -1979,7 +1982,7 @@ set starting_gitk_msg [mc "Starting gitk... please wait..."]
1982
1983
proc do_gitk {revs {is_submodule false}} {
1984
global current_diff_path file_states current_diff_side ui_index
1982
- global _gitworktree
1985
+ global _gitdir _gitworktree
1986
1987
# -- Always start gitk through whatever we were loaded with. This
1988
# lets us bypass using shell process on Windows systems.
@@ -1991,19 +1994,12 @@ proc do_gitk {revs {is_submodule false}} {
1994
} else {
1995
global env
1996
1994
- if {[info exists env(GIT_DIR)]} {
1995
- set old_GIT_DIR $env(GIT_DIR)
1996
- } else {
1997
- set old_GIT_DIR {}
1998
- }
1999
-
1997
set pwd [pwd]
1998
1999
if {!$is_submodule} {
2000
if {![is_bare]} {
2001
cd $_gitworktree
2002
}
2006
- set env(GIT_DIR) [file normalize [gitdir]]
2003
} else {
2004
cd $current_diff_path
2005
if {$revs eq {--}} {
@@ -2024,15 +2020,18 @@ proc do_gitk {revs {is_submodule false}} {
2020
}
2021
set revs $old_sha1...$new_sha1
2022
}
2027
- if {[info exists env(GIT_DIR)]} {
2028
- unset env(GIT_DIR)
2029
- }
2023
+ # GIT_DIR and GIT_WORK_TREE for the submodule are not the ones
2024
+ # we've been using for the main repository, so unset them.
2025
+ # TODO we could make life easier (start up faster?) for gitk
2026
+ # by setting these to the appropriate values to allow gitk
2027
+ # to skip the heuristics to find their proper value
2028
+ unset env(GIT_DIR)
2029
+ unset env(GIT_WORK_TREE)
2030
}
2031
eval exec $cmd $revs "--" "--" &
2032
2033
- if {$old_GIT_DIR ne {}} {
2034
- set env(GIT_DIR) $old_GIT_DIR
2035
- }
2033
+ set env(GIT_DIR) $_gitdir
2034
+ set env(GIT_WORK_TREE) $_gitworktree
2035
cd $pwd
2036
2037
ui_status $::starting_gitk_msg
@@ -2053,22 +2052,20 @@ proc do_git_gui {} {
2052
error_popup [mc "Couldn't find git gui in PATH"]
2053
} else {
2054
global env
2055
+ global _gitdir _gitworktree
2056
2057
- if {[info exists env(GIT_DIR)]} {
2058
- set old_GIT_DIR $env(GIT_DIR)
2059
- unset env(GIT_DIR)
2060
- } else {
2061
- set old_GIT_DIR {}
2062
- }
2057
+ # see note in do_gitk about unsetting these vars when
2058
+ # running tools in a submodule
2059
+ unset env(GIT_DIR)
2060
+ unset env(GIT_WORK_TREE)
2061
2062
set pwd [pwd]
2063
cd $current_diff_path
2064
2065
eval exec $exe gui &
2066
2069
- if {$old_GIT_DIR ne {}} {
2070
- set env(GIT_DIR) $old_GIT_DIR
2071
- }
2067
+ set env(GIT_DIR) $_gitdir
2068
+ set env(GIT_WORK_TREE) $_gitworktree
2069
cd $pwd
2070
2071
ui_status $::starting_gitk_msg