Skip to content

Commit

Permalink
submodules: ensure clean environment when operating in a submodule
Browse files Browse the repository at this point in the history
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 <giuseppe.bilotta@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Oblomov authored and gitster committed Feb 25, 2010
1 parent 7d750f0 commit 74ae141
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ cmd_add()

module_clone "$path" "$realrepo" "$reference" || exit
(
unset GIT_DIR
clear_local_git_env
cd "$path" &&
# ash fails to wordsplit ${branch:+-b "$branch"...}
case "$branch" in
Expand Down Expand Up @@ -278,7 +278,7 @@ cmd_foreach()
name=$(module_name "$path")
(
prefix="$prefix$path/"
unset GIT_DIR
clear_local_git_env
cd "$path" &&
eval "$@" &&
if test -n "$recursive"
Expand Down Expand Up @@ -434,7 +434,7 @@ cmd_update()
module_clone "$path" "$url" "$reference"|| exit
subsha1=
else
subsha1=$(unset GIT_DIR; cd "$path" &&
subsha1=$(clear_local_git_env; cd "$path" &&
git rev-parse --verify HEAD) ||
die "Unable to find current revision in submodule path '$path'"
fi
Expand All @@ -454,7 +454,7 @@ cmd_update()

if test -z "$nofetch"
then
(unset GIT_DIR; cd "$path" &&
(clear_local_git_env; cd "$path" &&
git-fetch) ||
die "Unable to fetch in submodule path '$path'"
fi
Expand All @@ -477,22 +477,22 @@ cmd_update()
;;
esac

(unset GIT_DIR; cd "$path" && $command "$sha1") ||
(clear_local_git_env; cd "$path" && $command "$sha1") ||
die "Unable to $action '$sha1' in submodule path '$path'"
say "Submodule path '$path': $msg '$sha1'"
fi

if test -n "$recursive"
then
(unset GIT_DIR; cd "$path" && cmd_update $orig_args) ||
(clear_local_git_env; cd "$path" && cmd_update $orig_args) ||
die "Failed to recurse into submodule path '$path'"
fi
done
}

set_name_rev () {
revname=$( (
unset GIT_DIR
clear_local_git_env
cd "$1" && {
git describe "$2" 2>/dev/null ||
git describe --tags "$2" 2>/dev/null ||
Expand Down Expand Up @@ -757,7 +757,7 @@ cmd_status()
else
if test -z "$cached"
then
sha1=$(unset GIT_DIR; cd "$path" && git rev-parse --verify HEAD)
sha1=$(clear_local_git_env; cd "$path" && git rev-parse --verify HEAD)
set_name_rev "$path" "$sha1"
fi
say "+$sha1 $displaypath$revname"
Expand All @@ -767,7 +767,7 @@ cmd_status()
then
(
prefix="$displaypath/"
unset GIT_DIR
clear_local_git_env
cd "$path" &&
cmd_status $orig_args
) ||
Expand Down Expand Up @@ -818,7 +818,7 @@ cmd_sync()
if test -e "$path"/.git
then
(
unset GIT_DIR
clear_local_git_env
cd "$path"
remote=$(get_default_remote)
say "Synchronizing submodule url for '$name'"
Expand Down

0 comments on commit 74ae141

Please sign in to comment.