@@ -834,11 +834,37 @@ test_expect_success "fetch new submodule commits on-demand outside standard refs
834834 git commit -m "updated submodules outside of refs/heads" &&
835835 E=$(git rev-parse HEAD) &&
836836 git update-ref refs/changes/3 $E &&
837+ FETCH_TRACE="$(pwd)/trace.out" &&
838+ test_when_finished "rm -f \"$FETCH_TRACE\"" &&
837839 (
838840 cd downstream &&
839- git fetch --recurse-submodules origin refs/changes/3:refs/heads/my_branch &&
841+ DEEP_START=$(git -C submodule/subdir/deepsubmodule rev-parse --short origin/deep) &&
842+ DEEP_END=$(git -C "$pwd/deepsubmodule" rev-parse --short deep) &&
843+ cat >"expect_fetch" <<-EOF &&
844+ From $pwd/.
845+ * [new ref] refs/changes/3 -> my_branch
846+ Fetching submodule sub1
847+ Fetching submodule sub1/subdir/deepsubmodule
848+ Fetching submodule submodule
849+ Fetching submodule submodule/subdir/deepsubmodule
850+ From $pwd/deepsubmodule
851+ $DEEP_START..$DEEP_END deep -> origin/deep
852+ From $pwd/./sub1
853+ * branch $D -> FETCH_HEAD
854+ Fetching submodule sub1/subdir/deepsubmodule
855+ From $pwd/submodule
856+ * branch $C -> FETCH_HEAD
857+ Fetching submodule submodule/subdir/deepsubmodule
858+ EOF
859+ GIT_TRACE="$FETCH_TRACE" git fetch --recurse-submodules origin \
860+ refs/changes/3:refs/heads/my_branch 2>actual_fetch &&
861+ test_cmp expect_fetch actual_fetch &&
840862 git -C submodule cat-file -t $C &&
841863 git -C sub1 cat-file -t $D &&
864+ test_grep "trace: built-in: git submodule--helper get-default-remote sub1" \
865+ "$FETCH_TRACE" &&
866+ test_grep "trace: built-in: git fetch .* --submodule-prefix=sub1/ origin" \
867+ "$FETCH_TRACE" &&
842868 git checkout --recurse-submodules FETCH_HEAD
843869 )
844870'
@@ -929,6 +955,90 @@ test_expect_success 'fetch new submodule commit intermittently referenced by sup
929955 )
930956'
931957
958+ test_expect_success ' fetch new submodule commits on-demand outside standard refspec with custom remote name' '
959+ # depends on the previous test for setup
960+
961+ # Rename the remote in sub1 from "origin" to "custom_remote"
962+ git -C downstream/sub1 remote rename origin custom_remote &&
963+
964+ # Create new commits in the original submodules
965+ C=$(git -C submodule commit-tree \
966+ -m "change outside refs/heads for custom remote" HEAD^{tree}) &&
967+ git -C submodule update-ref refs/changes/custom1 $C &&
968+ git update-index --cacheinfo 160000 $C submodule &&
969+ test_tick &&
970+
971+ D=$(git -C sub1 commit-tree \
972+ -m "change outside refs/heads for custom remote" HEAD^{tree}) &&
973+ git -C sub1 update-ref refs/changes/custom2 $D &&
974+ git update-index --cacheinfo 160000 $D sub1 &&
975+
976+ git commit \
977+ -m "updated submodules outside of refs/heads for custom remote" &&
978+ E=$(git rev-parse HEAD) &&
979+ git update-ref refs/changes/custom3 $E &&
980+ FETCH_TRACE="$(pwd)/trace.out" &&
981+ test_when_finished "rm -f \"$FETCH_TRACE\"" &&
982+ (
983+ cd downstream &&
984+ DEEP_START=$(git -C submodule/subdir/deepsubmodule rev-parse --short \
985+ origin/deep) &&
986+ DEEP_END=$(git -C "$pwd/deepsubmodule" rev-parse --short deep) &&
987+ cat >"expect_fetch_custom" <<-EOF &&
988+ From $pwd/.
989+ * [new ref] refs/changes/custom3 -> my_other_branch
990+ Fetching submodule sub1
991+ Fetching submodule sub1/subdir/deepsubmodule
992+ Fetching submodule submodule
993+ Fetching submodule submodule/subdir/deepsubmodule
994+ From $pwd/./sub1
995+ * branch $D -> FETCH_HEAD
996+ Fetching submodule sub1/subdir/deepsubmodule
997+ From $pwd/submodule
998+ * branch $C -> FETCH_HEAD
999+ Fetching submodule submodule/subdir/deepsubmodule
1000+ EOF
1001+ GIT_TRACE="$FETCH_TRACE" git fetch --recurse-submodules origin \
1002+ refs/changes/custom3:refs/heads/my_other_branch \
1003+ 2>actual_fetch_custom &&
1004+ # the without .gitmodules test above causes warnings
1005+ grep -v "^warning: " actual_fetch_custom >actual_fetch_warnings_removed &&
1006+ test_cmp expect_fetch_custom actual_fetch_warnings_removed &&
1007+
1008+ git -C submodule cat-file -t $C &&
1009+ git -C sub1 cat-file -t $D &&
1010+ test_grep "trace: built-in: git submodule--helper get-default-remote sub1" \
1011+ "$FETCH_TRACE" &&
1012+ test_grep "trace: built-in: git fetch .* --submodule-prefix=sub1/ custom_remote $D" \
1013+ "$FETCH_TRACE" &&
1014+ git checkout --recurse-submodules FETCH_HEAD
1015+ )
1016+ '
1017+
1018+ test_expect_success ' fetch new submodule commit on-demand in FETCH_HEAD from custom remote' '
1019+ # depends on the previous test for setup
1020+
1021+ C=$(git -C submodule commit-tree -m "another change outside refs/heads for custom remote" HEAD^{tree}) &&
1022+ git -C submodule update-ref refs/changes/custom4 $C &&
1023+ git update-index --cacheinfo 160000 $C submodule &&
1024+ test_tick &&
1025+
1026+ D=$(git -C sub1 commit-tree -m "another change outside refs/heads for custom remote" HEAD^{tree}) &&
1027+ git -C sub1 update-ref refs/changes/custom5 $D &&
1028+ git update-index --cacheinfo 160000 $D sub1 &&
1029+
1030+ git commit -m "updated submodules outside of refs/heads" &&
1031+ E=$(git rev-parse HEAD) &&
1032+ git update-ref refs/changes/custom6 $E &&
1033+ (
1034+ cd downstream &&
1035+ git fetch --recurse-submodules origin refs/changes/custom6 &&
1036+ git -C submodule cat-file -t $C &&
1037+ git -C sub1 cat-file -t $D &&
1038+ git checkout --recurse-submodules FETCH_HEAD
1039+ )
1040+ '
1041+
9321042add_commit_push () {
9331043 dir=" $1 " &&
9341044 msg=" $2 " &&
0 commit comments