Skip to content

Commit 96ca2bd

Browse files
hvoigtdscho
authored andcommitted
Revert "git-gui: set GIT_DIR and GIT_WORK_TREE after setup"
This reverts commit a9fa11f.
1 parent 5adb572 commit 96ca2bd

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
@@ -1337,9 +1337,6 @@ if {[lindex $_reponame end] eq {.git}} {
13371337
set _reponame [lindex $_reponame end]
13381338
}
13391339
1340-
set env(GIT_DIR) $_gitdir
1341-
set env(GIT_WORK_TREE) $_gitworktree
1342-
13431340
######################################################################
13441341
##
13451342
## global init
@@ -2159,7 +2156,7 @@ set starting_gitk_msg [mc "Starting gitk... please wait..."]
21592156
21602157
proc do_gitk {revs {is_submodule false}} {
21612158
global current_diff_path file_states current_diff_side ui_index
2162-
global _gitdir _gitworktree
2159+
global _gitworktree
21632160
21642161
# -- Always start gitk through whatever we were loaded with. This
21652162
# lets us bypass using shell process on Windows systems.
@@ -2171,12 +2168,19 @@ proc do_gitk {revs {is_submodule false}} {
21712168
} else {
21722169
global env
21732170
2171+
if {[info exists env(GIT_DIR)]} {
2172+
set old_GIT_DIR $env(GIT_DIR)
2173+
} else {
2174+
set old_GIT_DIR {}
2175+
}
2176+
21742177
set pwd [pwd]
21752178
21762179
if {!$is_submodule} {
21772180
if {![is_bare]} {
21782181
cd $_gitworktree
21792182
}
2183+
set env(GIT_DIR) [file normalize [gitdir]]
21802184
} else {
21812185
cd $current_diff_path
21822186
if {$revs eq {--}} {
@@ -2197,18 +2201,15 @@ proc do_gitk {revs {is_submodule false}} {
21972201
}
21982202
set revs $old_sha1...$new_sha1
21992203
}
2200-
# GIT_DIR and GIT_WORK_TREE for the submodule are not the ones
2201-
# we've been using for the main repository, so unset them.
2202-
# TODO we could make life easier (start up faster?) for gitk
2203-
# by setting these to the appropriate values to allow gitk
2204-
# to skip the heuristics to find their proper value
2205-
unset env(GIT_DIR)
2206-
unset env(GIT_WORK_TREE)
2204+
if {[info exists env(GIT_DIR)]} {
2205+
unset env(GIT_DIR)
2206+
}
22072207
}
22082208
eval exec $cmd $revs "--" "--" &
22092209
2210-
set env(GIT_DIR) $_gitdir
2211-
set env(GIT_WORK_TREE) $_gitworktree
2210+
if {$old_GIT_DIR ne {}} {
2211+
set env(GIT_DIR) $old_GIT_DIR
2212+
}
22122213
cd $pwd
22132214
22142215
ui_status $::starting_gitk_msg
@@ -2229,20 +2230,22 @@ proc do_git_gui {} {
22292230
error_popup [mc "Couldn't find git gui in PATH"]
22302231
} else {
22312232
global env
2232-
global _gitdir _gitworktree
22332233
2234-
# see note in do_gitk about unsetting these vars when
2235-
# running tools in a submodule
2236-
unset env(GIT_DIR)
2237-
unset env(GIT_WORK_TREE)
2234+
if {[info exists env(GIT_DIR)]} {
2235+
set old_GIT_DIR $env(GIT_DIR)
2236+
unset env(GIT_DIR)
2237+
} else {
2238+
set old_GIT_DIR {}
2239+
}
22382240
22392241
set pwd [pwd]
22402242
cd $current_diff_path
22412243
22422244
eval exec $exe gui &
22432245
2244-
set env(GIT_DIR) $_gitdir
2245-
set env(GIT_WORK_TREE) $_gitworktree
2246+
if {$old_GIT_DIR ne {}} {
2247+
set env(GIT_DIR) $old_GIT_DIR
2248+
}
22462249
cd $pwd
22472250
22482251
ui_status $::starting_gitk_msg

0 commit comments

Comments
 (0)