Skip to content

Commit aef5c38

Browse files
committed
Merge branch 'kb/maint-submodule-savearg'
* kb/maint-submodule-savearg: submodule: only preserve flags across recursive status/update invocations submodule: preserve all arguments exactly when recursing
2 parents 6f49ed6 + 98dbe63 commit aef5c38

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

git-submodule.sh

Lines changed: 9 additions & 12 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="$@"
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" && 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="$@"
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

@@ -790,7 +787,7 @@ cmd_status()
790787
prefix="$displaypath/"
791788
clear_local_git_env
792789
cd "$path" &&
793-
cmd_status $orig_args
790+
eval cmd_status "$orig_args"
794791
) ||
795792
die "Failed to recurse into submodule path '$path'"
796793
fi

t/t7407-submodule-foreach.sh

Lines changed: 50 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 &&
@@ -238,4 +253,39 @@ test_expect_success 'use "git clone --recursive" to checkout all submodules' '
238253
test -d clone4/nested1/nested2/nested3/submodule/.git
239254
'
240255

256+
test_expect_success 'test "update --recursive" with a flag with spaces' '
257+
git clone super "common objects" &&
258+
git clone super clone5 &&
259+
(
260+
cd clone5 &&
261+
test ! -d nested1/.git &&
262+
git submodule update --init --recursive --reference="$(dirname "$PWD")/common objects" &&
263+
test -d nested1/.git &&
264+
test -d nested1/nested2/.git &&
265+
test -d nested1/nested2/nested3/.git &&
266+
test -f nested1/.git/objects/info/alternates &&
267+
test -f nested1/nested2/.git/objects/info/alternates &&
268+
test -f nested1/nested2/nested3/.git/objects/info/alternates
269+
)
270+
'
271+
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+
241291
test_done

0 commit comments

Comments
 (0)