clone: teach --recurse-submodules to optionally take a pathspec
Teach clone --recurse-submodules to optionally take a pathspec argument which describes which submodules should be recursively initialized and cloned. If no pathspec is provided, --recurse-submodules will recursively initialize and clone all submodules by using a default pathspec of ".". In order to construct more complex pathspecs, --recurse-submodules can be given multiple times. This also configures the 'submodule.active' configuration option to be the given pathspec, such that any future invocation of `git submodule update` will keep up with the pathspec. Additionally the switch '--recurse' is removed from the Documentation as well as marked hidden in the options array, to streamline the options for submodules. A simple '--recurse' doesn't convey what is being recursed, e.g. it could mean directories or trees (c.f. ls-tree) In a lot of other commands we already have '--recurse-submodules' to mean recursing into submodules, so advertise this spelling here as the genuine option. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
3e7eaed016
commit
bb62e0a99f
@ -1188,4 +1188,72 @@ test_expect_success 'submodule update and setting submodule.<name>.active' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'clone --recurse-submodules with a pathspec works' '
|
||||
test_when_finished "rm -rf multisuper_clone" &&
|
||||
cat >expected <<-\EOF &&
|
||||
sub0 (test2)
|
||||
-sub1
|
||||
-sub2
|
||||
-sub3
|
||||
EOF
|
||||
|
||||
git clone --recurse-submodules="sub0" multisuper multisuper_clone &&
|
||||
git -C multisuper_clone submodule status |cut -c1,43- >actual &&
|
||||
test_cmp actual expected
|
||||
'
|
||||
|
||||
test_expect_success 'clone with multiple --recurse-submodules options' '
|
||||
test_when_finished "rm -rf multisuper_clone" &&
|
||||
cat >expect <<-\EOF &&
|
||||
-sub0
|
||||
sub1 (test2)
|
||||
-sub2
|
||||
sub3 (test2)
|
||||
EOF
|
||||
|
||||
git clone --recurse-submodules="." \
|
||||
--recurse-submodules=":(exclude)sub0" \
|
||||
--recurse-submodules=":(exclude)sub2" \
|
||||
multisuper multisuper_clone &&
|
||||
git -C multisuper_clone submodule status |cut -c1,43- >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'clone and subsequent updates correctly auto-initialize submodules' '
|
||||
test_when_finished "rm -rf multisuper_clone" &&
|
||||
cat <<-\EOF >expect &&
|
||||
-sub0
|
||||
sub1 (test2)
|
||||
-sub2
|
||||
sub3 (test2)
|
||||
EOF
|
||||
|
||||
cat <<-\EOF >expect2 &&
|
||||
-sub0
|
||||
sub1 (test2)
|
||||
-sub2
|
||||
sub3 (test2)
|
||||
-sub4
|
||||
sub5 (test2)
|
||||
EOF
|
||||
|
||||
git clone --recurse-submodules="." \
|
||||
--recurse-submodules=":(exclude)sub0" \
|
||||
--recurse-submodules=":(exclude)sub2" \
|
||||
--recurse-submodules=":(exclude)sub4" \
|
||||
multisuper multisuper_clone &&
|
||||
|
||||
git -C multisuper_clone submodule status |cut -c1,43- >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
git -C multisuper submodule add ../sub1 sub4 &&
|
||||
git -C multisuper submodule add ../sub1 sub5 &&
|
||||
git -C multisuper commit -m "add more submodules" &&
|
||||
# obtain the new superproject
|
||||
git -C multisuper_clone pull &&
|
||||
git -C multisuper_clone submodule update --init &&
|
||||
git -C multisuper_clone submodule status |cut -c1,43- >actual &&
|
||||
test_cmp expect2 actual
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user