@matheusbsbs / matheus-bagliano / commits / 98dbe63dbc
Fork 0

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 <kevin@sb.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kevin Ballard committed Nov 2, 2010 at 23:26 UTC 98dbe63dbcb44218e23ccc92e1491c36b2e31945
2 files changed +42 -11
git-submodule.sh
+8 -11
@@ -374,41 +374,35 @@ cmd_init()
374 cmd_update()
375 {
376 # parse $args after "submodule ... update".
377 - orig_args=$(git rev-parse --sq-quote "$@")
377 + orig_flags=
378 while test $# -ne 0
379 do
380 case "$1" in
381 -q|--quiet)
382 - shift
382 GIT_QUIET=1
383 ;;
384 -i|--init)
385 init=1
387 - shift
386 ;;
387 -N|--no-fetch)
390 - shift
388 nofetch=1
389 ;;
390 -r|--rebase)
394 - shift
391 update="rebase"
392 ;;
393 --reference)
394 case "$2" in '') usage ;; esac
395 reference="--reference=$2"
400 - shift 2
396 + orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
397 + shift
398 ;;
399 --reference=*)
400 reference="$1"
404 - shift
401 ;;
402 -m|--merge)
407 - shift
403 update="merge"
404 ;;
405 --recursive)
411 - shift
406 recursive=1
407 ;;
408 --)
@@ -422,6 +416,8 @@ cmd_update()
416 break
417 ;;
418 esac
419 + orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
420 + shift
421 done
422
423 if test -n "$init"
@@ -500,7 +496,7 @@ cmd_update()
496
497 if test -n "$recursive"
498 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") ||
500 die "Failed to recurse into submodule path '$path'"
501 fi
502 done
@@ -733,7 +729,7 @@ cmd_summary() {
729 cmd_status()
730 {
731 # parse $args after "submodule ... status".
736 - orig_args=$(git rev-parse --sq-quote "$@")
732 + orig_flags=
733 while test $# -ne 0
734 do
735 case "$1" in
@@ -757,6 +753,7 @@ cmd_status()
753 break
754 ;;
755 esac
756 + orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
757 shift
758 done
759
t/t7407-submodule-foreach.sh
+34
@@ -226,6 +226,21 @@ test_expect_success 'test "status --recursive"' '
226 test_cmp expect actual
227 '
228
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 +
244 test_expect_success 'use "git clone --recursive" to checkout all submodules' '
245 git clone --recursive super clone4 &&
246 test -d clone4/.git &&
@@ -254,4 +269,23 @@ test_expect_success 'test "update --recursive" with a flag with spaces' '
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 +
291 test_done