Skip to content

Commit a7eff1a

Browse files
lilyballgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Kevin Ballard <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c3fced6 commit a7eff1a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

git-submodule.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ cmd_init()
374374
cmd_update()
375375
{
376376
# parse $args after "submodule ... update".
377-
orig_args="$@"
377+
orig_args=$(git rev-parse --sq-quote "$@")
378378
while test $# -ne 0
379379
do
380380
case "$1" in
@@ -500,7 +500,7 @@ cmd_update()
500500

501501
if test -n "$recursive"
502502
then
503-
(clear_local_git_env; cd "$path" && cmd_update $orig_args) ||
503+
(clear_local_git_env; cd "$path" && eval cmd_update "$orig_args") ||
504504
die "Failed to recurse into submodule path '$path'"
505505
fi
506506
done
@@ -733,7 +733,7 @@ cmd_summary() {
733733
cmd_status()
734734
{
735735
# parse $args after "submodule ... status".
736-
orig_args="$@"
736+
orig_args=$(git rev-parse --sq-quote "$@")
737737
while test $# -ne 0
738738
do
739739
case "$1" in
@@ -790,7 +790,7 @@ cmd_status()
790790
prefix="$displaypath/"
791791
clear_local_git_env
792792
cd "$path" &&
793-
cmd_status $orig_args
793+
eval cmd_status "$orig_args"
794794
) ||
795795
die "Failed to recurse into submodule path '$path'"
796796
fi

t/t7407-submodule-foreach.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,20 @@ test_expect_success 'use "git clone --recursive" to checkout all submodules' '
238238
test -d clone4/nested1/nested2/nested3/submodule/.git
239239
'
240240

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+
241257
test_done

0 commit comments

Comments
 (0)