]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: delay fetch_if_missing=0 until after config
authorJonathan Tan <jonathantanmy@google.com>
Wed, 23 Oct 2019 23:34:03 +0000 (16:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 24 Oct 2019 02:34:44 +0000 (11:34 +0900)
Suppose, from a repository that has ".gitmodules", we clone with
--filter=blob:none:

  git clone --filter=blob:none --no-checkout \
    https://kernel.googlesource.com/pub/scm/git/git

Then we fetch:

  git -C git fetch

This will cause a "unable to load config blob object", because the
fetch_config_from_gitmodules() invocation in cmd_fetch() will attempt to
load ".gitmodules" (which Git knows to exist because the client has the
tree of HEAD) while fetch_if_missing is set to 0.

fetch_if_missing is set to 0 too early - ".gitmodules" here should be
lazily fetched.  Git must set fetch_if_missing to 0 before the fetch
because as part of the fetch, packfile negotiation happens (and we do
not want to fetch any missing objects when checking existence of
objects), but we do not need to set it so early. Move the setting of
fetch_if_missing to the earliest possible point in cmd_fetch(), right
before any fetching happens.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c

index 0c345b5dfe4b09e8d626815cb9909ef1f78e6338..863c858fde9afb3daac09c7ecf83cf44834574d5 100644 (file)
@@ -1755,8 +1755,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 
        packet_trace_identity("fetch");
 
-       fetch_if_missing = 0;
-
        /* Record the command line for the reflog */
        strbuf_addstr(&default_rla, "fetch");
        for (i = 1; i < argc; i++)
@@ -1824,6 +1822,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
                }
        }
 
+       fetch_if_missing = 0;
+
        if (remote) {
                if (filter_options.choice || has_promisor_remote())
                        fetch_one_setup_partial(remote);