Skip to content

Commit 74ae141

Browse files
Oblomovgitster
authored andcommitted
submodules: ensure clean environment when operating in a submodule
git-submodule used to take care of clearing GIT_DIR whenever it operated on a submodule index or configuration, but forgot to unset GIT_WORK_TREE or other repo-local variables. This would lead to failures e.g. when GIT_WORK_TREE was set. This only happened in very unusual contexts such as operating on the main worktree from outside of it, but since "git-gui: set GIT_DIR and GIT_WORK_TREE after setup" (a9fa11f) such failures could also be provoked by invoking an external tool such as "git submodule update" from the Git Gui in a standard setup. Solve by using the newly introduced clear_local_git_env() shell function to ensure that all repo-local environment variables are unset. Signed-off-by: Giuseppe Bilotta <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d750f0 commit 74ae141

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

git-submodule.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ cmd_add()
222222

223223
module_clone "$path" "$realrepo" "$reference" || exit
224224
(
225-
unset GIT_DIR
225+
clear_local_git_env
226226
cd "$path" &&
227227
# ash fails to wordsplit ${branch:+-b "$branch"...}
228228
case "$branch" in
@@ -278,7 +278,7 @@ cmd_foreach()
278278
name=$(module_name "$path")
279279
(
280280
prefix="$prefix$path/"
281-
unset GIT_DIR
281+
clear_local_git_env
282282
cd "$path" &&
283283
eval "$@" &&
284284
if test -n "$recursive"
@@ -434,7 +434,7 @@ cmd_update()
434434
module_clone "$path" "$url" "$reference"|| exit
435435
subsha1=
436436
else
437-
subsha1=$(unset GIT_DIR; cd "$path" &&
437+
subsha1=$(clear_local_git_env; cd "$path" &&
438438
git rev-parse --verify HEAD) ||
439439
die "Unable to find current revision in submodule path '$path'"
440440
fi
@@ -454,7 +454,7 @@ cmd_update()
454454

455455
if test -z "$nofetch"
456456
then
457-
(unset GIT_DIR; cd "$path" &&
457+
(clear_local_git_env; cd "$path" &&
458458
git-fetch) ||
459459
die "Unable to fetch in submodule path '$path'"
460460
fi
@@ -477,22 +477,22 @@ cmd_update()
477477
;;
478478
esac
479479

480-
(unset GIT_DIR; cd "$path" && $command "$sha1") ||
480+
(clear_local_git_env; cd "$path" && $command "$sha1") ||
481481
die "Unable to $action '$sha1' in submodule path '$path'"
482482
say "Submodule path '$path': $msg '$sha1'"
483483
fi
484484

485485
if test -n "$recursive"
486486
then
487-
(unset GIT_DIR; cd "$path" && cmd_update $orig_args) ||
487+
(clear_local_git_env; cd "$path" && cmd_update $orig_args) ||
488488
die "Failed to recurse into submodule path '$path'"
489489
fi
490490
done
491491
}
492492

493493
set_name_rev () {
494494
revname=$( (
495-
unset GIT_DIR
495+
clear_local_git_env
496496
cd "$1" && {
497497
git describe "$2" 2>/dev/null ||
498498
git describe --tags "$2" 2>/dev/null ||
@@ -757,7 +757,7 @@ cmd_status()
757757
else
758758
if test -z "$cached"
759759
then
760-
sha1=$(unset GIT_DIR; cd "$path" && git rev-parse --verify HEAD)
760+
sha1=$(clear_local_git_env; cd "$path" && git rev-parse --verify HEAD)
761761
set_name_rev "$path" "$sha1"
762762
fi
763763
say "+$sha1 $displaypath$revname"
@@ -767,7 +767,7 @@ cmd_status()
767767
then
768768
(
769769
prefix="$displaypath/"
770-
unset GIT_DIR
770+
clear_local_git_env
771771
cd "$path" &&
772772
cmd_status $orig_args
773773
) ||
@@ -818,7 +818,7 @@ cmd_sync()
818818
if test -e "$path"/.git
819819
then
820820
(
821-
unset GIT_DIR
821+
clear_local_git_env
822822
cd "$path"
823823
remote=$(get_default_remote)
824824
say "Synchronizing submodule url for '$name'"

0 commit comments

Comments
 (0)