]> git.ipfire.org Git - thirdparty/git.git/commit
submodule: fix premature failure in recursive submodule fetch
authorPaulius Zaleckas <paulius.zaleckas@gmail.com>
Thu, 16 Jul 2026 14:09:53 +0000 (17:09 +0300)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Jul 2026 17:07:52 +0000 (10:07 -0700)
commitd1e198ff9ebd2f3af5fb281f618f5e088489971e
tree67077b80793c0dabbf3c99b631679b4519d1e6be
parente9019fcafe0040228b8631c30f97ae1adb61bcdc
submodule: fix premature failure in recursive submodule fetch

When git fetch --recurse-submodules encounters a failure fetching a
submodule's refs (phase 1), it immediately marks the overall operation
as failed, even though a subsequent OID-based fetch (phase 2) is about
to be attempted for any missing commits.  If phase 2 succeeds, the
overall result should be success, but the prematurely set failure flag
makes it look like an error.

Restructure fetch_finish() so that a phase-1 failure does not record an
error immediately.  Instead, the decision is deferred:

 - If missing commits trigger a phase-2 (OID-based) retry and that
   retry succeeds, no error is recorded.
 - If the phase-2 retry also fails, the error is recorded then.
 - If the submodule was fetched unconditionally (RECURSE_SUBMODULES_ON)
   and is not in the changed list, a phase-1 failure is recorded right
   away since there is no OID retry to fall back on.
 - If phase 1 fails but all required commits are already present
   locally, there is no retry to defer to; the failure is still
   recorded, since the fetch itself went wrong (e.g. a transport
   error) even though the wanted commits happen to be available.

This resolves the NEEDSWORK comment added by bd5e567dc7 (submodule:
explain first attempt failure clearly, 2019-03-13).

Extract the common error-recording logic into a helper
record_fetch_error() and use it in fetch_start_failure() and for the
"Could not access submodule" error in get_fetch_task_from_index() as
well; the latter now also lists the submodule in the final error
summary.

Add a test ensuring a failed submodule fetch is still reported when
the gitlinked commits happen to be present locally.

Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Paulius Zaleckas <paulius.zaleckas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c
t/t5526-fetch-submodules.sh