Skip to content

Commit bd5e567

Browse files
jonathantanmygitster
authored andcommitted
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'... <messages about cloning of superproject> Submodule '<name>' (<uri>) registered for path '<submodule path>' Cloning into '<submodule path>'... fatal: Couldn't find remote ref HEAD Unable to fetch in submodule path '<submodule path>' <messages about fetching with SHA-1> From <uri> * branch <hash> -> FETCH_HEAD Submodule path '<submodule path>': checked out '<hash>' 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 fb43e31 ("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 e30d833 ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb582a commit bd5e567

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

git-submodule.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ cmd_update()
593593
# is not reachable from a ref.
594594
is_tip_reachable "$sm_path" "$sha1" ||
595595
fetch_in_submodule "$sm_path" $depth ||
596-
say "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
596+
say "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'; trying to directly fetch \$sha1:")"
597597

598598
# Now we tried the usual fetch, but $sha1 may
599599
# not be reachable from any of the refs

submodule.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,13 @@ static int fetch_finish(int retvalue, struct strbuf *err,
15441544
struct oid_array *commits;
15451545

15461546
if (retvalue)
1547+
/*
1548+
* NEEDSWORK: This indicates that the overall fetch
1549+
* failed, even though there may be a subsequent fetch
1550+
* by commit hash that might work. It may be a good
1551+
* idea to not indicate failure in this case, and only
1552+
* indicate failure if the subsequent fetch fails.
1553+
*/
15471554
spf->result = 1;
15481555

15491556
if (!task || !task->sub)

0 commit comments

Comments
 (0)