submodule update: respect depth in subsequent fetches
When depth is given the user may have a reasonable expectation that any remote operation is using the given depth. Add a test to demonstrate we still get the desired sha1 even if the depth is too short to include the actual commit. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Jul 28, 2016 at 17:44 UTC
6cbf454a2eaa016efff04bd696dc1ec24b515c11
2 files changed
+21
-4
git-submodule.sh
+5
-4
@@ -479,7 +479,8 @@ fetch_in_submodule () (
479
'')
480
git fetch ;;
481
*)
482
- git fetch $(get_default_remote) "$2" ;;
482
+ shift
483
+ git fetch $(get_default_remote) "$@" ;;
484
esac
485
)
486
@@ -617,7 +618,7 @@ cmd_update()
618
if test -z "$nofetch"
619
then
620
# Fetch remote before determining tracking $sha1
620
- fetch_in_submodule "$sm_path" ||
621
+ fetch_in_submodule "$sm_path" $depth ||
622
die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
623
fi
624
remote_name=$(sanitize_submodule_env; cd "$sm_path" && get_default_remote)
@@ -640,13 +641,13 @@ cmd_update()
641
# Run fetch only if $sha1 isn't present or it
642
# is not reachable from a ref.
643
is_tip_reachable "$sm_path" "$sha1" ||
643
- fetch_in_submodule "$sm_path" ||
644
+ fetch_in_submodule "$sm_path" $depth ||
645
die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
646
647
# Now we tried the usual fetch, but $sha1 may
648
# not be reachable from any of the refs
649
is_tip_reachable "$sm_path" "$sha1" ||
649
- fetch_in_submodule "$sm_path" "$sha1" ||
650
+ fetch_in_submodule "$sm_path" $depth "$sha1" ||
651
die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain \$sha1. Direct fetching of that commit failed.")"
652
fi
653
t/t7406-submodule-update.sh
+16
@@ -856,6 +856,22 @@ test_expect_success 'submodule update clone shallow submodule' '
856
)
857
'
858
859
+test_expect_success 'submodule update clone shallow submodule outside of depth' '
860
+ test_when_finished "rm -rf super3" &&
861
+ git clone cloned super3 &&
862
+ pwd=$(pwd) &&
863
+ (
864
+ cd super3 &&
865
+ sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
866
+ mv -f .gitmodules.tmp .gitmodules &&
867
+ test_must_fail git submodule update --init --depth=1 2>actual &&
868
+ test_i18ngrep "Direct fetching of that commit failed." actual &&
869
+ git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
870
+ git submodule update --init --depth=1 >actual &&
871
+ test 1 = $(git -C submodule log --oneline | wc -l)
872
+ )
873
+'
874
+
875
test_expect_success 'submodule update --recursive drops module name before recursing' '
876
(cd super2 &&
877
(cd deeper/submodule/subsubmodule &&