Skip to content

Commit 7920803

Browse files
authored
Merge pull request #2452 from oldium/fix-unset-env
git-gui: fix GIT_DIR handling for submodules It would appear that https://groups.google.com/d/msg/msysgit/FkdTopndAes/BRVBc95idk8J was intended to supersede the patch `Revert "git-gui: set GIT_DIR and GIT_WORK_TREE after setup"`, and it made it into Git's `master` via the merge bd08ecc (Merge branch 'gb/maint-submodule-env' into maint, 2010-03-08) (the patch in question is 74ae141 (submodules: ensure clean environment when operating in a submodule, 2010-02-25)). Therefore, let's drop that patch (and the follow-up patch made necessary by it) at long last -- after almost 10 years. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents d16625c + 803e81e commit 7920803

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

git-gui/git-gui.sh

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,9 @@ if {[lindex $_reponame end] eq {.git}} {
13351335
set _reponame [lindex $_reponame end]
13361336
}
13371337
1338+
set env(GIT_DIR) $_gitdir
1339+
set env(GIT_WORK_TREE) $_gitworktree
1340+
13381341
######################################################################
13391342
##
13401343
## global init
@@ -2161,7 +2164,7 @@ set starting_gitk_msg [mc "Starting gitk... please wait..."]
21612164
21622165
proc do_gitk {revs {is_submodule false}} {
21632166
global current_diff_path file_states current_diff_side ui_index
2164-
global _gitworktree
2167+
global _gitdir _gitworktree
21652168
21662169
# -- Always start gitk through whatever we were loaded with. This
21672170
# lets us bypass using shell process on Windows systems.
@@ -2173,19 +2176,12 @@ proc do_gitk {revs {is_submodule false}} {
21732176
} else {
21742177
global env
21752178
2176-
if {[info exists env(GIT_DIR)]} {
2177-
set old_GIT_DIR $env(GIT_DIR)
2178-
} else {
2179-
set old_GIT_DIR {}
2180-
}
2181-
21822179
set pwd [pwd]
21832180
21842181
if {!$is_submodule} {
21852182
if {![is_bare]} {
21862183
cd $_gitworktree
21872184
}
2188-
set env(GIT_DIR) [file normalize [gitdir]]
21892185
} else {
21902186
cd $current_diff_path
21912187
if {$revs eq {--}} {
@@ -2206,17 +2202,18 @@ proc do_gitk {revs {is_submodule false}} {
22062202
}
22072203
set revs $old_sha1...$new_sha1
22082204
}
2209-
if {[info exists env(GIT_DIR)]} {
2210-
unset env(GIT_DIR)
2211-
}
2205+
# GIT_DIR and GIT_WORK_TREE for the submodule are not the ones
2206+
# we've been using for the main repository, so unset them.
2207+
# TODO we could make life easier (start up faster?) for gitk
2208+
# by setting these to the appropriate values to allow gitk
2209+
# to skip the heuristics to find their proper value
2210+
unset env(GIT_DIR)
2211+
unset env(GIT_WORK_TREE)
22122212
}
22132213
eval exec $cmd $revs "--" "--" &
22142214
2215-
if {$old_GIT_DIR ne {}} {
2216-
set env(GIT_DIR) $old_GIT_DIR
2217-
} else {
2218-
unset env(GIT_DIR)
2219-
}
2215+
set env(GIT_DIR) $_gitdir
2216+
set env(GIT_WORK_TREE) $_gitworktree
22202217
cd $pwd
22212218
22222219
ui_status $::starting_gitk_msg
@@ -2237,22 +2234,20 @@ proc do_git_gui {} {
22372234
error_popup [mc "Couldn't find git gui in PATH"]
22382235
} else {
22392236
global env
2237+
global _gitdir _gitworktree
22402238
2241-
if {[info exists env(GIT_DIR)]} {
2242-
set old_GIT_DIR $env(GIT_DIR)
2243-
unset env(GIT_DIR)
2244-
} else {
2245-
set old_GIT_DIR {}
2246-
}
2239+
# see note in do_gitk about unsetting these vars when
2240+
# running tools in a submodule
2241+
unset env(GIT_DIR)
2242+
unset env(GIT_WORK_TREE)
22472243
22482244
set pwd [pwd]
22492245
cd $current_diff_path
22502246
22512247
eval exec $exe gui &
22522248
2253-
if {$old_GIT_DIR ne {}} {
2254-
set env(GIT_DIR) $old_GIT_DIR
2255-
}
2249+
set env(GIT_DIR) $_gitdir
2250+
set env(GIT_WORK_TREE) $_gitworktree
22562251
cd $pwd
22572252
22582253
ui_status $::starting_gitk_msg

0 commit comments

Comments
 (0)