@matheusbsbs / matheus-bagliano / commits / 74ae14199d
Fork 0

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" (a9fa11fe5bd5978bb) 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 <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Giuseppe Bilotta committed Feb 25, 2010 at 00:34 UTC 74ae14199dfb4b3b22a10d3dcecb62b457245564
1 file changed +10 -10
git-submodule.sh
+10 -10
@@ -222,7 +222,7 @@ cmd_add()
222
223 module_clone "$path" "$realrepo" "$reference" || exit
224 (
225 - unset GIT_DIR
225 + clear_local_git_env
226 cd "$path" &&
227 # ash fails to wordsplit ${branch:+-b "$branch"...}
228 case "$branch" in
@@ -278,7 +278,7 @@ cmd_foreach()
278 name=$(module_name "$path")
279 (
280 prefix="$prefix$path/"
281 - unset GIT_DIR
281 + clear_local_git_env
282 cd "$path" &&
283 eval "$@" &&
284 if test -n "$recursive"
@@ -434,7 +434,7 @@ cmd_update()
434 module_clone "$path" "$url" "$reference"|| exit
435 subsha1=
436 else
437 - subsha1=$(unset GIT_DIR; cd "$path" &&
437 + subsha1=$(clear_local_git_env; cd "$path" &&
438 git rev-parse --verify HEAD) ||
439 die "Unable to find current revision in submodule path '$path'"
440 fi
@@ -454,7 +454,7 @@ cmd_update()
454
455 if test -z "$nofetch"
456 then
457 - (unset GIT_DIR; cd "$path" &&
457 + (clear_local_git_env; cd "$path" &&
458 git-fetch) ||
459 die "Unable to fetch in submodule path '$path'"
460 fi
@@ -477,14 +477,14 @@ cmd_update()
477 ;;
478 esac
479
480 - (unset GIT_DIR; cd "$path" && $command "$sha1") ||
480 + (clear_local_git_env; cd "$path" && $command "$sha1") ||
481 die "Unable to $action '$sha1' in submodule path '$path'"
482 say "Submodule path '$path': $msg '$sha1'"
483 fi
484
485 if test -n "$recursive"
486 then
487 - (unset GIT_DIR; cd "$path" && cmd_update $orig_args) ||
487 + (clear_local_git_env; cd "$path" && cmd_update $orig_args) ||
488 die "Failed to recurse into submodule path '$path'"
489 fi
490 done
@@ -492,7 +492,7 @@ cmd_update()
492
493 set_name_rev () {
494 revname=$( (
495 - unset GIT_DIR
495 + clear_local_git_env
496 cd "$1" && {
497 git describe "$2" 2>/dev/null ||
498 git describe --tags "$2" 2>/dev/null ||
@@ -757,7 +757,7 @@ cmd_status()
757 else
758 if test -z "$cached"
759 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)
761 set_name_rev "$path" "$sha1"
762 fi
763 say "+$sha1 $displaypath$revname"
@@ -767,7 +767,7 @@ cmd_status()
767 then
768 (
769 prefix="$displaypath/"
770 - unset GIT_DIR
770 + clear_local_git_env
771 cd "$path" &&
772 cmd_status $orig_args
773 ) ||
@@ -818,7 +818,7 @@ cmd_sync()
818 if test -e "$path"/.git
819 then
820 (
821 - unset GIT_DIR
821 + clear_local_git_env
822 cd "$path"
823 remote=$(get_default_remote)
824 say "Synchronizing submodule url for '$name'"