Skip to content

Commit 461ee00

Browse files
hvoigtdscho
authored andcommitted
Revert "git-gui: set GIT_DIR and GIT_WORK_TREE after setup"
This reverts commit a9fa11f.
1 parent 0a03264 commit 461ee00

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
@@ -1326,9 +1326,6 @@ if {[lindex $_reponame end] eq {.git}} {
13261326
set _reponame [lindex $_reponame end]
13271327
}
13281328
1329-
set env(GIT_DIR) $_gitdir
1330-
set env(GIT_WORK_TREE) $_gitworktree
1331-
13321329
######################################################################
13331330
##
13341331
## global init
@@ -2153,7 +2150,7 @@ set starting_gitk_msg [mc "Starting gitk... please wait..."]
21532150
21542151
proc do_gitk {revs {is_submodule false}} {
21552152
global current_diff_path file_states current_diff_side ui_index
2156-
global _gitdir _gitworktree
2153+
global _gitworktree
21572154
21582155
# -- Always start gitk through whatever we were loaded with. This
21592156
# lets us bypass using shell process on Windows systems.
@@ -2165,12 +2162,19 @@ proc do_gitk {revs {is_submodule false}} {
21652162
} else {
21662163
global env
21672164
2165+
if {[info exists env(GIT_DIR)]} {
2166+
set old_GIT_DIR $env(GIT_DIR)
2167+
} else {
2168+
set old_GIT_DIR {}
2169+
}
2170+
21682171
set pwd [pwd]
21692172
21702173
if {!$is_submodule} {
21712174
if {![is_bare]} {
21722175
cd $_gitworktree
21732176
}
2177+
set env(GIT_DIR) [file normalize [gitdir]]
21742178
} else {
21752179
cd $current_diff_path
21762180
if {$revs eq {--}} {
@@ -2191,18 +2195,15 @@ proc do_gitk {revs {is_submodule false}} {
21912195
}
21922196
set revs $old_sha1...$new_sha1
21932197
}
2194-
# GIT_DIR and GIT_WORK_TREE for the submodule are not the ones
2195-
# we've been using for the main repository, so unset them.
2196-
# TODO we could make life easier (start up faster?) for gitk
2197-
# by setting these to the appropriate values to allow gitk
2198-
# to skip the heuristics to find their proper value
2199-
unset env(GIT_DIR)
2200-
unset env(GIT_WORK_TREE)
2198+
if {[info exists env(GIT_DIR)]} {
2199+
unset env(GIT_DIR)
2200+
}
22012201
}
22022202
eval exec $cmd $revs "--" "--" &
22032203
2204-
set env(GIT_DIR) $_gitdir
2205-
set env(GIT_WORK_TREE) $_gitworktree
2204+
if {$old_GIT_DIR ne {}} {
2205+
set env(GIT_DIR) $old_GIT_DIR
2206+
}
22062207
cd $pwd
22072208
22082209
ui_status $::starting_gitk_msg
@@ -2223,20 +2224,22 @@ proc do_git_gui {} {
22232224
error_popup [mc "Couldn't find git gui in PATH"]
22242225
} else {
22252226
global env
2226-
global _gitdir _gitworktree
22272227
2228-
# see note in do_gitk about unsetting these vars when
2229-
# running tools in a submodule
2230-
unset env(GIT_DIR)
2231-
unset env(GIT_WORK_TREE)
2228+
if {[info exists env(GIT_DIR)]} {
2229+
set old_GIT_DIR $env(GIT_DIR)
2230+
unset env(GIT_DIR)
2231+
} else {
2232+
set old_GIT_DIR {}
2233+
}
22322234
22332235
set pwd [pwd]
22342236
cd $current_diff_path
22352237
22362238
eval exec $exe gui &
22372239
2238-
set env(GIT_DIR) $_gitdir
2239-
set env(GIT_WORK_TREE) $_gitworktree
2240+
if {$old_GIT_DIR ne {}} {
2241+
set env(GIT_DIR) $old_GIT_DIR
2242+
}
22402243
cd $pwd
22412244
22422245
ui_status $::starting_gitk_msg

0 commit comments

Comments
 (0)