@matheusbsbs / matheus-bagliano / commits / a7eff1a87a
Fork 0

submodule: preserve all arguments exactly when recursing

Shell variables only hold strings, not lists of parameters, so $orig_args after orig_args="$@" fails to remember where each parameter starts and ends, if some include whitespace. So git submodule update \ --reference='/var/lib/common objects.git' \ --recursive --init becomes git submodule update --reference=/var/lib/common \ objects.git --recursive --init in the inner repositories. Use "git rev-parse --sq-quote" to save parameters in quoted form ready for evaluation by the shell, avoiding this problem. Helped-By: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Kevin Ballard <kevin@sb.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kevin Ballard committed Nov 2, 2010 at 23:26 UTC a7eff1a87ad8cdcb93f60efc7969042bc3e669ee
2 files changed +20 -4
git-submodule.sh
+4 -4
@@ -374,7 +374,7 @@ cmd_init()
374 cmd_update()
375 {
376 # parse $args after "submodule ... update".
377 - orig_args="$@"
377 + orig_args=$(git rev-parse --sq-quote "$@")
378 while test $# -ne 0
379 do
380 case "$1" in
@@ -500,7 +500,7 @@ cmd_update()
500
501 if test -n "$recursive"
502 then
503 - (clear_local_git_env; cd "$path" && cmd_update $orig_args) ||
503 + (clear_local_git_env; cd "$path" && eval cmd_update "$orig_args") ||
504 die "Failed to recurse into submodule path '$path'"
505 fi
506 done
@@ -733,7 +733,7 @@ cmd_summary() {
733 cmd_status()
734 {
735 # parse $args after "submodule ... status".
736 - orig_args="$@"
736 + orig_args=$(git rev-parse --sq-quote "$@")
737 while test $# -ne 0
738 do
739 case "$1" in
@@ -790,7 +790,7 @@ cmd_status()
790 prefix="$displaypath/"
791 clear_local_git_env
792 cd "$path" &&
793 - cmd_status $orig_args
793 + eval cmd_status "$orig_args"
794 ) ||
795 die "Failed to recurse into submodule path '$path'"
796 fi
t/t7407-submodule-foreach.sh
+16
@@ -238,4 +238,20 @@ test_expect_success 'use "git clone --recursive" to checkout all submodules' '
238 test -d clone4/nested1/nested2/nested3/submodule/.git
239 '
240
241 +test_expect_success 'test "update --recursive" with a flag with spaces' '
242 + git clone super "common objects" &&
243 + git clone super clone5 &&
244 + (
245 + cd clone5 &&
246 + test ! -d nested1/.git &&
247 + git submodule update --init --recursive --reference="$(dirname "$PWD")/common objects" &&
248 + test -d nested1/.git &&
249 + test -d nested1/nested2/.git &&
250 + test -d nested1/nested2/nested3/.git &&
251 + test -f nested1/.git/objects/info/alternates &&
252 + test -f nested1/nested2/.git/objects/info/alternates &&
253 + test -f nested1/nested2/nested3/.git/objects/info/alternates
254 + )
255 +'
256 +
257 test_done