{"thread":{"id":"58792","subject":"[PATCH] fetch: support \"--super-prefix\"","startedAt":"2022-11-11T23:55:48Z","lastAt":"2022-11-11T23:55:48Z","messageCount":1,"participants":["Glen Choo via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"467182","messageId":"pull.1378.git.git.1668210935360.gitgitgadget@gmail.com","threadId":"58792","inReplyTo":null,"subject":"[PATCH] fetch: support \"--super-prefix\"","fromName":"Glen Choo via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-11-11T23:55:35Z","receivedAt":"2022-11-11T23:55:48Z","isPatch":true,"sender":{"key":"glencbz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58092771?v=4"},"body":"From: Glen Choo <chooglen@google.com>\n\nIn a repo with partially cloned submodules, \"git restore\n--recurse-submodules\" from the superproject can fail with \"fatal: fetch\ndoesn't support --super-prefix\". This error is encountered when the\nsuper prefix is set (either by passing \"--super-prefix\" or by setting\nthe GIT_INTERNAL_SUPER_PREFIX env var) on a command that isn't marked\nSUPPORT_SUPER_PREFIX. In this case, \"git restore --recurse-submodules\"\ninvokes \"git read-tree --super-prefix=<path to submodule>\", which in\nturn, invokes a \"git fetch\" to fetch promisor objects.\n\nThe usefulness of this \"--super-prefix\" check is up for debate, and\nthere is WIP to get rid of the option altogether [1], but we can't just\nleave \"git restore\" broken in the meantime, so let's do the barest\nminimum to fix this without causing too much trouble for that effort.\n\nMark cmd_fetch as SUPPORT_SUPER_PREFIX, and add a test that shows that\nthis fixes the bug described above.\n\nThere is precedent for using SUPPORT_SUPER_PREFIX solely as a workaround\nfor the super prefix check (c.f. [2]), which is all the more reason to\nget rid of this check.\n\n[1] https://lore.kernel.org/git/Y27D8QUl3I2d4xNe@nand.local/\n[2] 53fcfbc84f (fsmonitor--daemon: allow --super-prefix argument,\n    2022-05-26)\n\nSuggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nSigned-off-by: Glen Choo <chooglen@google.com>\n---\n    fetch: support \"--super-prefix\"\n    \n    Since \"git read-tree\" is seriously broken at the moment, let's not keep\n    it hostage to the work on [1]. This is Ævar's suggested change from [2]\n    combined with my partial clone test case from [3].\n    \n    I think we can take this regardless of where we are with the RFCs; it's\n    simple and obvious enough that it adds virtually no churn to the RFCs.\n    \n    [1] https://lore.kernel.org/git/Y27D8QUl3I2d4xNe@nand.local/ [2]\n    https://lore.kernel.org/git/221109.86y1skq08e.gmgdl@evledraar.gmail.com\n    [3]\n    https://lore.kernel.org/git/20221109004708.97668-4-chooglen@google.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1378%2Fchooglen%2Ffetch%2Fsupport-super-prefix-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1378/chooglen/fetch/support-super-prefix-v1\nPull-Request: https://github.com/git/git/pull/1378\n\n builtin/fetch.c          |  6 ++++++\n git.c                    |  2 +-\n t/t5616-partial-clone.sh | 43 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 50 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 7378cafeec9..9fd64e2f409 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -2114,6 +2114,12 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \tint result = 0;\n \tint prune_tags_ok = 1;\n \n+\t/*\n+\t * NEEDSWORK: we don't actually use \"--super-prefix\". Unset it\n+\t * so that we don't accidentally use it or pass it down.\n+\t */\n+\tunsetenv(GIT_SUPER_PREFIX_ENVIRONMENT);\n+\n \tpacket_trace_identity(\"fetch\");\n \n \t/* Record the command line for the reflog */\ndiff --git a/git.c b/git.c\nindex 6662548986f..b971752f6f0 100644\n--- a/git.c\n+++ b/git.c\n@@ -531,7 +531,7 @@ static struct cmd_struct commands[] = {\n \t{ \"env--helper\", cmd_env__helper },\n \t{ \"fast-export\", cmd_fast_export, RUN_SETUP },\n \t{ \"fast-import\", cmd_fast_import, RUN_SETUP | NO_PARSEOPT },\n-\t{ \"fetch\", cmd_fetch, RUN_SETUP },\n+\t{ \"fetch\", cmd_fetch, RUN_SETUP | SUPPORT_SUPER_PREFIX },\n \t{ \"fetch-pack\", cmd_fetch_pack, RUN_SETUP | NO_PARSEOPT },\n \t{ \"fmt-merge-msg\", cmd_fmt_merge_msg, RUN_SETUP },\n \t{ \"for-each-ref\", cmd_for_each_ref, RUN_SETUP },\ndiff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh\nindex 037941b95d2..9bec57a0476 100755\n--- a/t/t5616-partial-clone.sh\n+++ b/t/t5616-partial-clone.sh\n@@ -644,6 +644,49 @@ test_expect_success 'repack does not loosen promisor objects' '\n \tgrep \"loosen_unused_packed_objects/loosened:0\" trace\n '\n \n+test_expect_success 'setup src repo with submodules' '\n+\ttest_config_global protocol.file.allow always &&\n+\n+\tgit init src-sub &&\n+\tgit -C src-sub config uploadpack.allowfilter 1 &&\n+\tgit -C src-sub config uploadpack.allowanysha1inwant 1 &&\n+\n+\t# This blob must be missing in the subsequent commit.\n+\techo foo >src-sub/file &&\n+\tgit -C src-sub add file &&\n+\tgit -C src-sub commit -m \"submodule one\" &&\n+\tSUB_ONE=$(git -C src-sub rev-parse HEAD) &&\n+\n+\techo bar >src-sub/file &&\n+\tgit -C src-sub add file &&\n+\tgit -C src-sub commit -m \"submodule two\" &&\n+\tSUB_TWO=$(git -C src-sub rev-parse HEAD) &&\n+\n+\tgit init src-super &&\n+\tgit -C src-super config uploadpack.allowfilter 1 &&\n+\tgit -C src-super config uploadpack.allowanysha1inwant 1 &&\n+\tgit -C src-super submodule add ../src-sub src-sub &&\n+\n+\tgit -C src-super/src-sub checkout $SUB_ONE &&\n+\tgit -C src-super add src-sub &&\n+\tgit -C src-super commit -m \"superproject one\" &&\n+\n+\tgit -C src-super/src-sub checkout $SUB_TWO &&\n+\tgit -C src-super add src-sub &&\n+\tgit -C src-super commit -m \"superproject two\"\n+'\n+\n+test_expect_success 'lazy-fetch in submodule succeeds' '\n+\ttest_when_finished \"rm -rf src-super src-sub client\" &&\n+\n+\ttest_config_global protocol.file.allow always &&\n+\tgit clone --filter=blob:none --also-filter-submodules \\\n+\t\t--recurse-submodules \"file://$(pwd)/src-super\" client &&\n+\n+\t# Trigger lazy-fetch from the superproject\n+\tgit -C client restore --recurse-submodules --source=HEAD^ :/\n+'\n+\n . \"$TEST_DIRECTORY\"/lib-httpd.sh\n start_httpd\n \n\nbase-commit: 319605f8f00e402f3ea758a02c63534ff800a711\n-- \ngitgitgadget\n"}]}