@@ -192,6 +192,17 @@ isnumber()
192192 n=$(( $1 + 0 )) 2> /dev/null && test " $n " = " $1 "
193193}
194194
195+ # Sanitize the local git environment for use within a submodule. We
196+ # can't simply use clear_local_git_env since we want to preserve some
197+ # of the settings from GIT_CONFIG_PARAMETERS.
198+ sanitize_submodule_env ()
199+ {
200+ save_config=$GIT_CONFIG_PARAMETERS
201+ clear_local_git_env
202+ GIT_CONFIG_PARAMETERS=$save_config
203+ export GIT_CONFIG_PARAMETERS
204+ }
205+
195206#
196207# Add a new submodule to the working tree, .gitmodules and the index
197208#
@@ -347,9 +358,9 @@ Use -f if you really want to add it." >&2
347358 echo " $( eval_gettext " Reactivating local git directory for submodule '\$ sm_name'." ) "
348359 fi
349360 fi
350- git submodule--helper clone ${GIT_QUIET: +--quiet} --prefix " $wt_prefix " --path " $sm_path " --name " $sm_name " --url " $realrepo " " $reference " " $depth " || exit
361+ git submodule--helper clone ${GIT_QUIET: +--quiet} --prefix " $wt_prefix " --path " $sm_path " --name " $sm_name " --url " $realrepo " ${reference : + " $reference " } ${depth : + " $depth " } || exit
351362 (
352- clear_local_git_env
363+ sanitize_submodule_env
353364 cd " $sm_path " &&
354365 # ash fails to wordsplit ${branch:+-b "$branch"...}
355366 case " $branch " in
@@ -418,7 +429,7 @@ cmd_foreach()
418429 name=$( git submodule--helper name " $sm_path " )
419430 (
420431 prefix=" $prefix$sm_path /"
421- clear_local_git_env
432+ sanitize_submodule_env
422433 cd " $sm_path " &&
423434 sm_path=$( relative_path " $sm_path " ) &&
424435 # we make $path available to scripts ...
@@ -592,14 +603,14 @@ cmd_deinit()
592603}
593604
594605is_tip_reachable () (
595- clear_local_git_env
606+ sanitize_submodule_env &&
596607 cd " $1 " &&
597608 rev=$( git rev-list -n 1 " $2 " --not --all 2> /dev/null) &&
598609 test -z " $rev "
599610)
600611
601612fetch_in_submodule () (
602- clear_local_git_env
613+ sanitize_submodule_env &&
603614 cd " $1 " &&
604615 case " $2 " in
605616 ' ' )
@@ -727,11 +738,11 @@ Maybe you want to use 'update --init'?")"
727738
728739 if ! test -d " $sm_path " /.git && ! test -f " $sm_path " /.git
729740 then
730- git submodule--helper clone ${GIT_QUIET: +--quiet} --prefix " $prefix " --path " $sm_path " --name " $name " --url " $url " " $reference " " $depth " || exit
741+ git submodule--helper clone ${GIT_QUIET: +--quiet} --prefix " $prefix " --path " $sm_path " --name " $name " --url " $url " ${reference : + " $reference " } ${depth : + " $depth " } || exit
731742 cloned_modules=" $cloned_modules ;$name "
732743 subsha1=
733744 else
734- subsha1=$( clear_local_git_env ; cd " $sm_path " &&
745+ subsha1=$( sanitize_submodule_env ; cd " $sm_path " &&
735746 git rev-parse --verify HEAD) ||
736747 die " $( eval_gettext " Unable to find current revision in submodule path '\$ displaypath'" ) "
737748 fi
@@ -741,11 +752,11 @@ Maybe you want to use 'update --init'?")"
741752 if test -z " $nofetch "
742753 then
743754 # Fetch remote before determining tracking $sha1
744- (clear_local_git_env ; cd " $sm_path " && git-fetch) ||
755+ (sanitize_submodule_env ; cd " $sm_path " && git-fetch) ||
745756 die " $( eval_gettext " Unable to fetch in submodule path '\$ sm_path'" ) "
746757 fi
747- remote_name=$( clear_local_git_env ; cd " $sm_path " && get_default_remote)
748- sha1=$( clear_local_git_env ; cd " $sm_path " &&
758+ remote_name=$( sanitize_submodule_env ; cd " $sm_path " && get_default_remote)
759+ sha1=$( sanitize_submodule_env ; cd " $sm_path " &&
749760 git rev-parse --verify " ${remote_name} /${branch} " ) ||
750761 die " $( eval_gettext " Unable to find current ${remote_name} /${branch} revision in submodule path '\$ sm_path'" ) "
751762 fi
@@ -810,7 +821,7 @@ Maybe you want to use 'update --init'?")"
810821 die " $( eval_gettext " Invalid update mode '$update_module ' for submodule '$name '" ) "
811822 esac
812823
813- if (clear_local_git_env ; cd " $sm_path " && $command " $sha1 " )
824+ if (sanitize_submodule_env ; cd " $sm_path " && $command " $sha1 " )
814825 then
815826 say " $say_msg "
816827 elif test -n " $must_die_on_failure "
@@ -826,7 +837,7 @@ Maybe you want to use 'update --init'?")"
826837 then
827838 (
828839 prefix=" $prefix$sm_path /"
829- clear_local_git_env
840+ sanitize_submodule_env
830841 cd " $sm_path " &&
831842 eval cmd_update
832843 )
@@ -864,7 +875,7 @@ Maybe you want to use 'update --init'?")"
864875
865876set_name_rev () {
866877 revname=$( (
867- clear_local_git_env
878+ sanitize_submodule_env
868879 cd " $1 " && {
869880 git describe " $2 " 2> /dev/null ||
870881 git describe --tags " $2 " 2> /dev/null ||
@@ -1148,7 +1159,7 @@ cmd_status()
11481159 else
11491160 if test -z " $cached "
11501161 then
1151- sha1=$( clear_local_git_env ; cd " $sm_path " && git rev-parse --verify HEAD)
1162+ sha1=$( sanitize_submodule_env ; cd " $sm_path " && git rev-parse --verify HEAD)
11521163 fi
11531164 set_name_rev " $sm_path " " $sha1 "
11541165 say " +$sha1 $displaypath$revname "
@@ -1158,7 +1169,7 @@ cmd_status()
11581169 then
11591170 (
11601171 prefix=" $displaypath /"
1161- clear_local_git_env
1172+ sanitize_submodule_env
11621173 wt_prefix=
11631174 cd " $sm_path " &&
11641175 eval cmd_status
@@ -1233,7 +1244,7 @@ cmd_sync()
12331244 if test -e " $sm_path " /.git
12341245 then
12351246 (
1236- clear_local_git_env
1247+ sanitize_submodule_env
12371248 cd " $sm_path "
12381249 remote=$( get_default_remote)
12391250 git config remote." $remote " .url " $sub_origin_url "
0 commit comments