Skip to content

Commit 87d88e8

Browse files
hvoigtdscho
authored andcommitted
Revert "git-gui: set GIT_DIR and GIT_WORK_TREE after setup"
This reverts commit a9fa11f.
1 parent 62f3116 commit 87d88e8

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

git-gui/git-gui.sh

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,9 +1340,6 @@ if {[lindex $_reponame end] eq {.git}} {
13401340
set _reponame [lindex $_reponame end]
13411341
}
13421342
1343-
set env(GIT_DIR) $_gitdir
1344-
set env(GIT_WORK_TREE) $_gitworktree
1345-
13461343
######################################################################
13471344
##
13481345
## global init
@@ -2165,7 +2162,7 @@ set starting_gitk_msg [mc "Starting gitk... please wait..."]
21652162
21662163
proc do_gitk {revs {is_submodule false}} {
21672164
global current_diff_path file_states current_diff_side ui_index
2168-
global _gitdir _gitworktree
2165+
global _gitworktree
21692166
21702167
# -- Always start gitk through whatever we were loaded with. This
21712168
# lets us bypass using shell process on Windows systems.
@@ -2177,12 +2174,19 @@ proc do_gitk {revs {is_submodule false}} {
21772174
} else {
21782175
global env
21792176
2177+
if {[info exists env(GIT_DIR)]} {
2178+
set old_GIT_DIR $env(GIT_DIR)
2179+
} else {
2180+
set old_GIT_DIR {}
2181+
}
2182+
21802183
set pwd [pwd]
21812184
21822185
if {!$is_submodule} {
21832186
if {![is_bare]} {
21842187
cd $_gitworktree
21852188
}
2189+
set env(GIT_DIR) [file normalize [gitdir]]
21862190
} else {
21872191
cd $current_diff_path
21882192
if {$revs eq {--}} {
@@ -2203,18 +2207,15 @@ proc do_gitk {revs {is_submodule false}} {
22032207
}
22042208
set revs $old_sha1...$new_sha1
22052209
}
2206-
# GIT_DIR and GIT_WORK_TREE for the submodule are not the ones
2207-
# we've been using for the main repository, so unset them.
2208-
# TODO we could make life easier (start up faster?) for gitk
2209-
# by setting these to the appropriate values to allow gitk
2210-
# to skip the heuristics to find their proper value
2211-
unset env(GIT_DIR)
2212-
unset env(GIT_WORK_TREE)
2210+
if {[info exists env(GIT_DIR)]} {
2211+
unset env(GIT_DIR)
2212+
}
22132213
}
22142214
eval exec $cmd $revs "--" "--" &
22152215
2216-
set env(GIT_DIR) $_gitdir
2217-
set env(GIT_WORK_TREE) $_gitworktree
2216+
if {$old_GIT_DIR ne {}} {
2217+
set env(GIT_DIR) $old_GIT_DIR
2218+
}
22182219
cd $pwd
22192220
22202221
ui_status $::starting_gitk_msg
@@ -2235,20 +2236,22 @@ proc do_git_gui {} {
22352236
error_popup [mc "Couldn't find git gui in PATH"]
22362237
} else {
22372238
global env
2238-
global _gitdir _gitworktree
22392239
2240-
# see note in do_gitk about unsetting these vars when
2241-
# running tools in a submodule
2242-
unset env(GIT_DIR)
2243-
unset env(GIT_WORK_TREE)
2240+
if {[info exists env(GIT_DIR)]} {
2241+
set old_GIT_DIR $env(GIT_DIR)
2242+
unset env(GIT_DIR)
2243+
} else {
2244+
set old_GIT_DIR {}
2245+
}
22442246
22452247
set pwd [pwd]
22462248
cd $current_diff_path
22472249
22482250
eval exec $exe gui &
22492251
2250-
set env(GIT_DIR) $_gitdir
2251-
set env(GIT_WORK_TREE) $_gitworktree
2252+
if {$old_GIT_DIR ne {}} {
2253+
set env(GIT_DIR) $old_GIT_DIR
2254+
}
22522255
cd $pwd
22532256
22542257
ui_status $::starting_gitk_msg

0 commit comments

Comments
 (0)