Skip to content

Commit 98dbe63

Browse files
lilyballgitster
authored andcommitted
submodule: only preserve flags across recursive status/update invocations
Recursive invocations of submodule update/status preserve all arguments, so executing git submodule update --recursive -- foo attempts to recursively update a submodule named "foo". Naturally, this fails as one cannot have an infinitely-deep stack of submodules each containing a submodule named "foo". The desired behavior is instead to update foo and then recursively update all submodules inside of foo. This commit accomplishes that by only saving the flags for use in the recursive invocation. Signed-off-by: Kevin Ballard <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a7eff1a commit 98dbe63

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

git-submodule.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,41 +374,35 @@ cmd_init()
374374
cmd_update()
375375
{
376376
# parse $args after "submodule ... update".
377-
orig_args=$(git rev-parse --sq-quote "$@")
377+
orig_flags=
378378
while test $# -ne 0
379379
do
380380
case "$1" in
381381
-q|--quiet)
382-
shift
383382
GIT_QUIET=1
384383
;;
385384
-i|--init)
386385
init=1
387-
shift
388386
;;
389387
-N|--no-fetch)
390-
shift
391388
nofetch=1
392389
;;
393390
-r|--rebase)
394-
shift
395391
update="rebase"
396392
;;
397393
--reference)
398394
case "$2" in '') usage ;; esac
399395
reference="--reference=$2"
400-
shift 2
396+
orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
397+
shift
401398
;;
402399
--reference=*)
403400
reference="$1"
404-
shift
405401
;;
406402
-m|--merge)
407-
shift
408403
update="merge"
409404
;;
410405
--recursive)
411-
shift
412406
recursive=1
413407
;;
414408
--)
@@ -422,6 +416,8 @@ cmd_update()
422416
break
423417
;;
424418
esac
419+
orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
420+
shift
425421
done
426422

427423
if test -n "$init"
@@ -500,7 +496,7 @@ cmd_update()
500496

501497
if test -n "$recursive"
502498
then
503-
(clear_local_git_env; cd "$path" && eval cmd_update "$orig_args") ||
499+
(clear_local_git_env; cd "$path" && eval cmd_update "$orig_flags") ||
504500
die "Failed to recurse into submodule path '$path'"
505501
fi
506502
done
@@ -733,7 +729,7 @@ cmd_summary() {
733729
cmd_status()
734730
{
735731
# parse $args after "submodule ... status".
736-
orig_args=$(git rev-parse --sq-quote "$@")
732+
orig_flags=
737733
while test $# -ne 0
738734
do
739735
case "$1" in
@@ -757,6 +753,7 @@ cmd_status()
757753
break
758754
;;
759755
esac
756+
orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
760757
shift
761758
done
762759

t/t7407-submodule-foreach.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,21 @@ test_expect_success 'test "status --recursive"' '
226226
test_cmp expect actual
227227
'
228228

229+
sed -e "/nested1 /s/.*/+$nested1sha1 nested1 (file2~1)/;/sub[1-3]/d" < expect > expect2
230+
mv -f expect2 expect
231+
232+
test_expect_success 'ensure "status --cached --recursive" preserves the --cached flag' '
233+
(
234+
cd clone3 &&
235+
(
236+
cd nested1 &&
237+
test_commit file2
238+
) &&
239+
git submodule status --cached --recursive -- nested1 > ../actual
240+
) &&
241+
test_cmp expect actual
242+
'
243+
229244
test_expect_success 'use "git clone --recursive" to checkout all submodules' '
230245
git clone --recursive super clone4 &&
231246
test -d clone4/.git &&
@@ -254,4 +269,23 @@ test_expect_success 'test "update --recursive" with a flag with spaces' '
254269
)
255270
'
256271

272+
test_expect_success 'use "update --recursive nested1" to checkout all submodules rooted in nested1' '
273+
git clone super clone6 &&
274+
(
275+
cd clone6 &&
276+
test ! -d sub1/.git &&
277+
test ! -d sub2/.git &&
278+
test ! -d sub3/.git &&
279+
test ! -d nested1/.git &&
280+
git submodule update --init --recursive -- nested1 &&
281+
test ! -d sub1/.git &&
282+
test ! -d sub2/.git &&
283+
test ! -d sub3/.git &&
284+
test -d nested1/.git &&
285+
test -d nested1/nested2/.git &&
286+
test -d nested1/nested2/nested3/.git &&
287+
test -d nested1/nested2/nested3/submodule/.git
288+
)
289+
'
290+
257291
test_done

0 commit comments

Comments
 (0)