git-submodule.sh: Don't use $path variable in eval_gettext string

The eval_gettext (and eval_gettextln) i18n shell functions call git-sh-i18n--envsubst to process the variable references in the string parameter. Unfortunately, environment variables are case insensitive on windows, which leads to failure on cygwin when eval_gettext exports $path. Commit df599e9 (Windows: teach getenv to do a case-sensitive search, 06-06-2011) attempts to solve this problem on MinGW by overriding the system getenv() function to allow git-sh-i18n--envsubst to read $path rather than $PATH from the environment. However, this commit does not address cygwin at all and, furthermore, does not fix all problems on MinGW. In particular, when executing test #38 in t7400-submodule-basic.sh, an 'git-sh-i18n-envsubst.exe - Unable To Locate Component' dialog pops up saying that the application "failed to start because libiconv2.dll was not found." After studying the voluminous trace output from the process monitor, it is clear that the system is attempting to use $path, rather than $PATH, to search for the DLL file. (Note that, after dismissing the dialog, the test passes anyway!) As an alternative, we finesse the problem by renaming the $path variable to $sm_path (submodule path). This fixes the problem on MinGW along with all test failures on cygwin (t7400.{7,32,34}, t7406.3 and t7407.{2,6}). We note that the foreach subcommand provides $path to user scripts (ie it is part of the API), so we can't simply rename it to $sm_path. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Acked-by: Jens Lehmann <Jens.Lehmann@web.de> Tested-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramsay Jones committed Apr 17, 2012 at 19:00 UTC 64394e3ae9194836ffd4068006bbdd5ad9810a4b
1 file changed +82 -79
git-submodule.sh
+82 -79
@@ -101,11 +101,12 @@ module_list()
101 module_name()
102 {
103 # Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
104 + sm_path="$1"
105 re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
106 name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
107 sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
108 test -z "$name" &&
108 - die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$path'")"
109 + die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$sm_path'")"
110 echo "$name"
111 }
112
@@ -119,7 +120,7 @@ module_name()
120 #
121 module_clone()
122 {
122 - path=$1
123 + sm_path=$1
124 url=$2
125 reference="$3"
126 quiet=
@@ -130,8 +131,8 @@ module_clone()
131
132 gitdir=
133 gitdir_base=
133 - name=$(module_name "$path" 2>/dev/null)
134 - test -n "$name" || name="$path"
134 + name=$(module_name "$sm_path" 2>/dev/null)
135 + test -n "$name" || name="$sm_path"
136 base_name=$(dirname "$name")
137
138 gitdir=$(git rev-parse --git-dir)
@@ -140,17 +141,17 @@ module_clone()
141
142 if test -d "$gitdir"
143 then
143 - mkdir -p "$path"
144 + mkdir -p "$sm_path"
145 rm -f "$gitdir/index"
146 else
147 mkdir -p "$gitdir_base"
148 git clone $quiet -n ${reference:+"$reference"} \
148 - --separate-git-dir "$gitdir" "$url" "$path" ||
149 - die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")"
149 + --separate-git-dir "$gitdir" "$url" "$sm_path" ||
150 + die "$(eval_gettext "Clone of '\$url' into submodule path '\$sm_path' failed")"
151 fi
152
153 a=$(cd "$gitdir" && pwd)/
153 - b=$(cd "$path" && pwd)/
154 + b=$(cd "$sm_path" && pwd)/
155 # normalize Windows-style absolute paths to POSIX-style absolute paths
156 case $a in [a-zA-Z]:/*) a=/${a%%:*}${a#*:} ;; esac
157 case $b in [a-zA-Z]:/*) b=/${b%%:*}${b#*:} ;; esac
@@ -168,10 +169,10 @@ module_clone()
169 b=${b%/}
170
171 rel=$(echo $b | sed -e 's|[^/]*|..|g')
171 - echo "gitdir: $rel/$a" >"$path/.git"
172 + echo "gitdir: $rel/$a" >"$sm_path/.git"
173
174 rel=$(echo $a | sed -e 's|[^/]*|..|g')
174 - (clear_local_git_env; cd "$path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
175 + (clear_local_git_env; cd "$sm_path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
176 }
177
178 #
@@ -222,14 +223,14 @@ cmd_add()
223 done
224
225 repo=$1
225 - path=$2
226 + sm_path=$2
227
227 - if test -z "$path"; then
228 - path=$(echo "$repo" |
228 + if test -z "$sm_path"; then
229 + sm_path=$(echo "$repo" |
230 sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
231 fi
232
232 - if test -z "$repo" -o -z "$path"; then
233 + if test -z "$repo" -o -z "$sm_path"; then
234 usage
235 fi
236
@@ -250,7 +251,7 @@ cmd_add()
251
252 # normalize path:
253 # multiple //; leading ./; /./; /../; trailing /
253 - path=$(printf '%s/\n' "$path" |
254 + sm_path=$(printf '%s/\n' "$sm_path" |
255 sed -e '
256 s|//*|/|g
257 s|^\(\./\)*||
@@ -260,49 +261,49 @@ cmd_add()
261 tstart
262 s|/*$||
263 ')
263 - git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
264 - die "$(eval_gettext "'\$path' already exists in the index")"
264 + git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
265 + die "$(eval_gettext "'\$sm_path' already exists in the index")"
266
266 - if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
267 + if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1
268 then
269 eval_gettextln "The following path is ignored by one of your .gitignore files:
269 -\$path
270 +\$sm_path
271 Use -f if you really want to add it." >&2
272 exit 1
273 fi
274
275 # perhaps the path exists and is already a git repo, else clone it
275 - if test -e "$path"
276 + if test -e "$sm_path"
277 then
277 - if test -d "$path"/.git -o -f "$path"/.git
278 + if test -d "$sm_path"/.git -o -f "$sm_path"/.git
279 then
279 - eval_gettextln "Adding existing repo at '\$path' to the index"
280 + eval_gettextln "Adding existing repo at '\$sm_path' to the index"
281 else
281 - die "$(eval_gettext "'\$path' already exists and is not a valid git repo")"
282 + die "$(eval_gettext "'\$sm_path' already exists and is not a valid git repo")"
283 fi
284
285 else
286
286 - module_clone "$path" "$realrepo" "$reference" || exit
287 + module_clone "$sm_path" "$realrepo" "$reference" || exit
288 (
289 clear_local_git_env
289 - cd "$path" &&
290 + cd "$sm_path" &&
291 # ash fails to wordsplit ${branch:+-b "$branch"...}
292 case "$branch" in
293 '') git checkout -f -q ;;
294 ?*) git checkout -f -q -B "$branch" "origin/$branch" ;;
295 esac
295 - ) || die "$(eval_gettext "Unable to checkout submodule '\$path'")"
296 + ) || die "$(eval_gettext "Unable to checkout submodule '\$sm_path'")"
297 fi
297 - git config submodule."$path".url "$realrepo"
298 + git config submodule."$sm_path".url "$realrepo"
299
299 - git add $force "$path" ||
300 - die "$(eval_gettext "Failed to add submodule '\$path'")"
300 + git add $force "$sm_path" ||
301 + die "$(eval_gettext "Failed to add submodule '\$sm_path'")"
302
302 - git config -f .gitmodules submodule."$path".path "$path" &&
303 - git config -f .gitmodules submodule."$path".url "$repo" &&
303 + git config -f .gitmodules submodule."$sm_path".path "$sm_path" &&
304 + git config -f .gitmodules submodule."$sm_path".url "$repo" &&
305 git add --force .gitmodules ||
305 - die "$(eval_gettext "Failed to register submodule '\$path'")"
306 + die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
307 }
308
309 #
@@ -340,23 +341,25 @@ cmd_foreach()
341 exec 3<&0
342
343 module_list |
343 - while read mode sha1 stage path
344 + while read mode sha1 stage sm_path
345 do
345 - if test -e "$path"/.git
346 + if test -e "$sm_path"/.git
347 then
347 - say "$(eval_gettext "Entering '\$prefix\$path'")"
348 - name=$(module_name "$path")
348 + say "$(eval_gettext "Entering '\$prefix\$sm_path'")"
349 + name=$(module_name "$sm_path")
350 (
350 - prefix="$prefix$path/"
351 + prefix="$prefix$sm_path/"
352 clear_local_git_env
352 - cd "$path" &&
353 + # we make $path available to scripts ...
354 + path=$sm_path
355 + cd "$sm_path" &&
356 eval "$@" &&
357 if test -n "$recursive"
358 then
359 cmd_foreach "--recursive" "$@"
360 fi
361 ) <&3 3<&- ||
359 - die "$(eval_gettext "Stopping at '\$path'; script returned non-zero status.")"
362 + die "$(eval_gettext "Stopping at '\$sm_path'; script returned non-zero status.")"
363 fi
364 done
365 }
@@ -390,15 +393,15 @@ cmd_init()
393 done
394
395 module_list "$@" |
393 - while read mode sha1 stage path
396 + while read mode sha1 stage sm_path
397 do
398 # Skip already registered paths
396 - name=$(module_name "$path") || exit
399 + name=$(module_name "$sm_path") || exit
400 if test -z "$(git config "submodule.$name.url")"
401 then
402 url=$(git config -f .gitmodules submodule."$name".url)
403 test -z "$url" &&
401 - die "$(eval_gettext "No url found for submodule path '\$path' in .gitmodules")"
404 + die "$(eval_gettext "No url found for submodule path '\$sm_path' in .gitmodules")"
405
406 # Possibly a url relative to parent
407 case "$url" in
@@ -407,7 +410,7 @@ cmd_init()
410 ;;
411 esac
412 git config submodule."$name".url "$url" ||
410 - die "$(eval_gettext "Failed to register url for submodule path '\$path'")"
413 + die "$(eval_gettext "Failed to register url for submodule path '\$sm_path'")"
414 fi
415
416 # Copy "update" setting when it is not set yet
@@ -415,9 +418,9 @@ cmd_init()
418 test -z "$upd" ||
419 test -n "$(git config submodule."$name".update)" ||
420 git config submodule."$name".update "$upd" ||
418 - die "$(eval_gettext "Failed to register update mode for submodule path '\$path'")"
421 + die "$(eval_gettext "Failed to register update mode for submodule path '\$sm_path'")"
422
420 - say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$path'")"
423 + say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$sm_path'")"
424 done
425 }
426
@@ -489,14 +492,14 @@ cmd_update()
492 cloned_modules=
493 module_list "$@" | {
494 err=
492 - while read mode sha1 stage path
495 + while read mode sha1 stage sm_path
496 do
497 if test "$stage" = U
498 then
496 - echo >&2 "Skipping unmerged submodule $path"
499 + echo >&2 "Skipping unmerged submodule $sm_path"
500 continue
501 fi
499 - name=$(module_name "$path") || exit
502 + name=$(module_name "$sm_path") || exit
503 url=$(git config submodule."$name".url)
504 if ! test -z "$update"
505 then
@@ -507,7 +510,7 @@ cmd_update()
510
511 if test "$update_module" = "none"
512 then
510 - echo "Skipping submodule '$path'"
513 + echo "Skipping submodule '$sm_path'"
514 continue
515 fi
516
@@ -516,20 +519,20 @@ cmd_update()
519 # Only mention uninitialized submodules when its
520 # path have been specified
521 test "$#" != "0" &&
519 - say "$(eval_gettext "Submodule path '\$path' not initialized
522 + say "$(eval_gettext "Submodule path '\$sm_path' not initialized
523 Maybe you want to use 'update --init'?")"
524 continue
525 fi
526
524 - if ! test -d "$path"/.git -o -f "$path"/.git
527 + if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
528 then
526 - module_clone "$path" "$url" "$reference"|| exit
529 + module_clone "$sm_path" "$url" "$reference"|| exit
530 cloned_modules="$cloned_modules;$name"
531 subsha1=
532 else
530 - subsha1=$(clear_local_git_env; cd "$path" &&
533 + subsha1=$(clear_local_git_env; cd "$sm_path" &&
534 git rev-parse --verify HEAD) ||
532 - die "$(eval_gettext "Unable to find current revision in submodule path '\$path'")"
535 + die "$(eval_gettext "Unable to find current revision in submodule path '\$sm_path'")"
536 fi
537
538 if test "$subsha1" != "$sha1"
@@ -545,10 +548,10 @@ Maybe you want to use 'update --init'?")"
548 then
549 # Run fetch only if $sha1 isn't present or it
550 # is not reachable from a ref.
548 - (clear_local_git_env; cd "$path" &&
551 + (clear_local_git_env; cd "$sm_path" &&
552 ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
553 test -z "$rev") || git-fetch)) ||
551 - die "$(eval_gettext "Unable to fetch in submodule path '\$path'")"
554 + die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
555 fi
556
557 # Is this something we just cloned?
@@ -562,24 +565,24 @@ Maybe you want to use 'update --init'?")"
565 case "$update_module" in
566 rebase)
567 command="git rebase"
565 - die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$path'")"
566 - say_msg="$(eval_gettext "Submodule path '\$path': rebased into '\$sha1'")"
568 + die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$sm_path'")"
569 + say_msg="$(eval_gettext "Submodule path '\$sm_path': rebased into '\$sha1'")"
570 must_die_on_failure=yes
571 ;;
572 merge)
573 command="git merge"
571 - die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$path'")"
572 - say_msg="$(eval_gettext "Submodule path '\$path': merged in '\$sha1'")"
574 + die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$sm_path'")"
575 + say_msg="$(eval_gettext "Submodule path '\$sm_path': merged in '\$sha1'")"
576 must_die_on_failure=yes
577 ;;
578 *)
579 command="git checkout $subforce -q"
577 - die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$path'")"
578 - say_msg="$(eval_gettext "Submodule path '\$path': checked out '\$sha1'")"
580 + die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$sm_path'")"
581 + say_msg="$(eval_gettext "Submodule path '\$sm_path': checked out '\$sha1'")"
582 ;;
583 esac
584
582 - if (clear_local_git_env; cd "$path" && $command "$sha1")
585 + if (clear_local_git_env; cd "$sm_path" && $command "$sha1")
586 then
587 say "$say_msg"
588 elif test -n "$must_die_on_failure"
@@ -593,11 +596,11 @@ Maybe you want to use 'update --init'?")"
596
597 if test -n "$recursive"
598 then
596 - (clear_local_git_env; cd "$path" && eval cmd_update "$orig_flags")
599 + (clear_local_git_env; cd "$sm_path" && eval cmd_update "$orig_flags")
600 res=$?
601 if test $res -gt 0
602 then
600 - die_msg="$(eval_gettext "Failed to recurse into submodule path '\$path'")"
603 + die_msg="$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
604 if test $res -eq 1
605 then
606 err="${err};$die_msg"
@@ -884,30 +887,30 @@ cmd_status()
887 done
888
889 module_list "$@" |
887 - while read mode sha1 stage path
890 + while read mode sha1 stage sm_path
891 do
889 - name=$(module_name "$path") || exit
892 + name=$(module_name "$sm_path") || exit
893 url=$(git config submodule."$name".url)
891 - displaypath="$prefix$path"
894 + displaypath="$prefix$sm_path"
895 if test "$stage" = U
896 then
897 say "U$sha1 $displaypath"
898 continue
899 fi
897 - if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git
900 + if test -z "$url" || ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
901 then
902 say "-$sha1 $displaypath"
903 continue;
904 fi
902 - set_name_rev "$path" "$sha1"
903 - if git diff-files --ignore-submodules=dirty --quiet -- "$path"
905 + set_name_rev "$sm_path" "$sha1"
906 + if git diff-files --ignore-submodules=dirty --quiet -- "$sm_path"
907 then
908 say " $sha1 $displaypath$revname"
909 else
910 if test -z "$cached"
911 then
909 - sha1=$(clear_local_git_env; cd "$path" && git rev-parse --verify HEAD)
910 - set_name_rev "$path" "$sha1"
912 + sha1=$(clear_local_git_env; cd "$sm_path" && git rev-parse --verify HEAD)
913 + set_name_rev "$sm_path" "$sha1"
914 fi
915 say "+$sha1 $displaypath$revname"
916 fi
@@ -917,10 +920,10 @@ cmd_status()
920 (
921 prefix="$displaypath/"
922 clear_local_git_env
920 - cd "$path" &&
923 + cd "$sm_path" &&
924 eval cmd_status "$orig_args"
925 ) ||
923 - die "$(eval_gettext "Failed to recurse into submodule path '\$path'")"
926 + die "$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
927 fi
928 done
929 }
@@ -952,9 +955,9 @@ cmd_sync()
955 done
956 cd_to_toplevel
957 module_list "$@" |
955 - while read mode sha1 stage path
958 + while read mode sha1 stage sm_path
959 do
957 - name=$(module_name "$path")
960 + name=$(module_name "$sm_path")
961 url=$(git config -f .gitmodules --get submodule."$name".url)
962
963 # Possibly a url relative to parent
@@ -969,11 +972,11 @@ cmd_sync()
972 say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
973 git config submodule."$name".url "$url"
974
972 - if test -e "$path"/.git
975 + if test -e "$sm_path"/.git
976 then
977 (
978 clear_local_git_env
976 - cd "$path"
979 + cd "$sm_path"
980 remote=$(get_default_remote)
981 git config remote."$remote".url "$url"
982 )