Skip to content

Commit 9671a76

Browse files
committed
Merge branch 'sb/submodule-fetch-nontip'
When "git submodule update" did not result in fetching the commit object in the submodule that is referenced by the superproject, the command learned to retry another fetch, specifically asking for that commit that may not be connected to the refs it usually fetches. * sb/submodule-fetch-nontip: submodule: try harder to fetch needed sha1 by direct fetching sha1
2 parents 03f682b + fb43e31 commit 9671a76

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

git-submodule.sh

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,24 @@ cmd_deinit()
591591
done
592592
}
593593

594+
is_tip_reachable () (
595+
clear_local_git_env
596+
cd "$1" &&
597+
rev=$(git rev-list -n 1 "$2" --not --all 2>/dev/null) &&
598+
test -z "$rev"
599+
)
600+
601+
fetch_in_submodule () (
602+
clear_local_git_env
603+
cd "$1" &&
604+
case "$2" in
605+
'')
606+
git fetch ;;
607+
*)
608+
git fetch $(get_default_remote) "$2" ;;
609+
esac
610+
)
611+
594612
#
595613
# Update each submodule path to correct revision, using clone and checkout as needed
596614
#
@@ -745,10 +763,15 @@ Maybe you want to use 'update --init'?")"
745763
then
746764
# Run fetch only if $sha1 isn't present or it
747765
# is not reachable from a ref.
748-
(clear_local_git_env; cd "$sm_path" &&
749-
( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
750-
test -z "$rev") || git-fetch)) ||
766+
is_tip_reachable "$sm_path" "$sha1" ||
767+
fetch_in_submodule "$sm_path" ||
751768
die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
769+
770+
# Now we tried the usual fetch, but $sha1 may
771+
# not be reachable from any of the refs
772+
is_tip_reachable "$sm_path" "$sha1" ||
773+
fetch_in_submodule "$sm_path" "$sha1" ||
774+
die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain $sha1. Direct fetching of that commit failed.")"
752775
fi
753776

754777
# Is this something we just cloned?

0 commit comments

Comments
 (0)