From bd5e567dc75abae58cb364d1e55cbaf67edb8c98 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Wed, 13 Mar 2019 10:57:38 -0700 Subject: submodule: explain first attempt failure clearly When cloning with --recurse-submodules a superproject with at least one submodule with HEAD pointing to an unborn branch, the clone goes something like this: Cloning into 'test'... Submodule '' () registered for path '' Cloning into ''... fatal: Couldn't find remote ref HEAD Unable to fetch in submodule path '' From * branch -> FETCH_HEAD Submodule path '': checked out '' In other words, first, a fetch is done with no hash arguments (that is, a fetch of HEAD) resulting in a "Couldn't find remote ref HEAD" error; then, a fetch is done given a hash, which succeeds. The fetch given a hash was added in fb43e31f2b ("submodule: try harder to fetch needed sha1 by direct fetching sha1", 2016-02-24), and the "Unable to fetch..." message was downgraded from a fatal error to a notice in e30d833671 ("git-submodule.sh: try harder to fetch a submodule", 2018-05-16). This commit improves the notice to be clearer that we are retrying the fetch, and that the previous messages (in particular, the fatal errors from fetch) do not necessarily indicate that the whole command fails. In other words: - If the HEAD-fetch succeeds and we then have the commit we want, git-submodule prints no explanation. - If the HEAD-fetch succeeds and we do not have the commit we want, but the hash-fetch succeeds, git-submodule prints no explanation. - If the HEAD-fetch succeeds and we do not have the commit we want, but the hash-fetch fails, git-submodule prints a fatal error. - If the HEAD-fetch fails, fetch prints a fatal error, and git-submodule informs the user that it will retry by fetching specific commits by hash. - If the hash-fetch then succeeds, git-submodule prints no explanation (besides the ones already printed). - If the HEAD-fetch then fails, git-submodule prints a fatal error. It could be said that we should just eliminate the HEAD-fetch altogether, but that changes some behavior (in particular, some refs that were opportunistically updated would no longer be), so I have left that alone for now. There is an analogous situation with the fetching code in fetch_finish() and surrounding functions. For now, I have added a NEEDSWORK. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano diff --git a/git-submodule.sh b/git-submodule.sh index b5f2bee..cc750b5 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -593,7 +593,7 @@ cmd_update() # is not reachable from a ref. is_tip_reachable "$sm_path" "$sha1" || fetch_in_submodule "$sm_path" $depth || - say "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")" + say "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'; trying to directly fetch \$sha1:")" # Now we tried the usual fetch, but $sha1 may # not be reachable from any of the refs diff --git a/submodule.c b/submodule.c index 934ecfa..b6f6fa7 100644 --- a/submodule.c +++ b/submodule.c @@ -1544,6 +1544,13 @@ static int fetch_finish(int retvalue, struct strbuf *err, struct oid_array *commits; if (retvalue) + /* + * NEEDSWORK: This indicates that the overall fetch + * failed, even though there may be a subsequent fetch + * by commit hash that might work. It may be a good + * idea to not indicate failure in this case, and only + * indicate failure if the subsequent fetch fails. + */ spf->result = 1; if (!task || !task->sub) -- cgit v0.10.2-6-g49f6