1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-31 22:37:54 +01:00

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
This commit is contained in:
Junio C Hamano 2016-02-26 13:37:24 -08:00
commit 9671a76c17

View file

@ -591,6 +591,24 @@ cmd_deinit()
done done
} }
is_tip_reachable () (
clear_local_git_env
cd "$1" &&
rev=$(git rev-list -n 1 "$2" --not --all 2>/dev/null) &&
test -z "$rev"
)
fetch_in_submodule () (
clear_local_git_env
cd "$1" &&
case "$2" in
'')
git fetch ;;
*)
git fetch $(get_default_remote) "$2" ;;
esac
)
# #
# Update each submodule path to correct revision, using clone and checkout as needed # Update each submodule path to correct revision, using clone and checkout as needed
# #
@ -745,10 +763,15 @@ Maybe you want to use 'update --init'?")"
then then
# Run fetch only if $sha1 isn't present or it # Run fetch only if $sha1 isn't present or it
# is not reachable from a ref. # is not reachable from a ref.
(clear_local_git_env; cd "$sm_path" && is_tip_reachable "$sm_path" "$sha1" ||
( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) && fetch_in_submodule "$sm_path" ||
test -z "$rev") || git-fetch)) ||
die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")" die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
# Now we tried the usual fetch, but $sha1 may
# not be reachable from any of the refs
is_tip_reachable "$sm_path" "$sha1" ||
fetch_in_submodule "$sm_path" "$sha1" ||
die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain $sha1. Direct fetching of that commit failed.")"
fi fi
# Is this something we just cloned? # Is this something we just cloned?