]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/clone: propagate ref storage format to submodules
authorPatrick Steinhardt <ps@pks.im>
Thu, 8 Aug 2024 07:35:37 +0000 (09:35 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Aug 2024 16:21:39 +0000 (09:21 -0700)
When recursively cloning a repository with a non-default ref storage
format, e.g. by passing the `--ref-format=` option, then only the
top-level repository will end up using that ref storage format, and
all recursively cloned submodules will instead use the default format.

While mixed-format constellations are expected to work alright, the
outcome still is somewhat surprising as we have essentially ignored
the user's request.

Fix this by propagating the requested ref format to cloned submodules.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clone.c
t/t7424-submodule-mixed-ref-formats.sh

index af6017d41a3de8a57a9531d3802ee6f2eb83bd36..75b15b5773b3058c8a7d1c34e3d6fb309a8f769b 100644 (file)
@@ -729,7 +729,8 @@ static int git_sparse_checkout_init(const char *repo)
        return result;
 }
 
-static int checkout(int submodule_progress, int filter_submodules)
+static int checkout(int submodule_progress, int filter_submodules,
+                   enum ref_storage_format ref_storage_format)
 {
        struct object_id oid;
        char *head;
@@ -813,6 +814,10 @@ static int checkout(int submodule_progress, int filter_submodules)
                        strvec_push(&cmd.args, "--no-fetch");
                }
 
+               if (ref_storage_format != REF_STORAGE_FORMAT_UNKNOWN)
+                       strvec_pushf(&cmd.args, "--ref-format=%s",
+                                    ref_storage_format_to_name(ref_storage_format));
+
                if (filter_submodules && filter_options.choice)
                        strvec_pushf(&cmd.args, "--filter=%s",
                                     expand_list_objects_filter_spec(&filter_options));
@@ -1536,7 +1541,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                return 1;
 
        junk_mode = JUNK_LEAVE_REPO;
-       err = checkout(submodule_progress, filter_submodules);
+       err = checkout(submodule_progress, filter_submodules,
+                      ref_storage_format);
 
        free(remote_name);
        strbuf_release(&reflog_msg);
index de8400755477416ebecdcd206a2f2f63d3afe51f..4e4991d04c54ab874fbd8bc73d77f5263536895e 100755 (executable)
@@ -21,6 +21,29 @@ test_expect_success 'setup' '
        git config set --global protocol.file.allow always
 '
 
+test_expect_success 'recursive clone propagates ref storage format' '
+       test_when_finished "rm -rf submodule upstream downstream" &&
+
+       git init submodule &&
+       test_commit -C submodule submodule-initial &&
+       git init upstream &&
+       git -C upstream submodule add "file://$(pwd)/submodule" &&
+       git -C upstream commit -am "add submodule" &&
+
+       # The upstream repository and its submodule should be using the default
+       # ref format.
+       test_ref_format upstream "$GIT_DEFAULT_REF_FORMAT" &&
+       test_ref_format upstream/submodule "$GIT_DEFAULT_REF_FORMAT" &&
+
+       # The cloned repositories should use the other ref format that we have
+       # specified via `--ref-format`. The option should propagate to cloned
+       # submodules.
+       git clone --ref-format=$OTHER_FORMAT --recurse-submodules \
+               upstream downstream &&
+       test_ref_format downstream "$OTHER_FORMAT" &&
+       test_ref_format downstream/submodule "$OTHER_FORMAT"
+'
+
 test_expect_success 'clone submodules with different ref storage format' '
        test_when_finished "rm -rf submodule upstream downstream" &&