{"thread":{"id":"44649","subject":"[PATCH] submodule--helper: set alternateLocation for cloned submodules","startedAt":"2016-12-08T01:38:32Z","lastAt":"2016-12-12T18:00:46Z","messageCount":4,"participants":["vi0oss@gmail.com","vi0oss","Stefan Beller","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"307210","messageId":"20161208013814.4943-1-vi0oss@gmail.com","threadId":"44649","inReplyTo":null,"subject":"[PATCH] submodule--helper: set alternateLocation for cloned submodules","fromName":"","fromEmail":"vi0oss@gmail.com","sentAt":"2016-12-08T01:38:14Z","receivedAt":"2016-12-08T01:38:32Z","isPatch":true,"sender":{"key":"vi0oss@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173219?v=4"},"body":"From: \"Vitaly \\\"_Vi\\\" Shukela\" <vi0oss@gmail.com>\n\nIn 31224cbdc7 (clone: recursive and reference option triggers\nsubmodule alternates, 2016-08-17) a mechanism was added to\nhave submodules referenced.  It did not address _nested_\nsubmodules, however.\n\nThis patch makes all not just the root repository, but also\nall submodules (recursively) have submodule.alternateLocation\nand submodule.alternateErrorStrategy configured, making Git\nsearch for possible alternates for nested submodules as well.\n\nAs submodule's alternate target does not end in .git/objects\n(rather .git/modules/qqqqqq/objects), this alternate target\npath restriction for in add_possible_reference_from_superproject\nrelates from \"*.git/objects\" to just */objects\".\n\nNew tests have been added to t7408-submodule-reference.\n\nSigned-off-by: Vitaly _Vi Shukela <vi0oss@gmail.com>\n---\n\nNotes:\n    Third review: missing && in test fixed.\n    \n    Mailmap change not included.\n\n builtin/submodule--helper.c    | 19 ++++++++++--\n t/t7408-submodule-reference.sh | 66 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 83 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 4beeda5..92fd676 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -498,9 +498,9 @@ static int add_possible_reference_from_superproject(\n \n \t/*\n \t * If the alternate object store is another repository, try the\n-\t * standard layout with .git/modules/<name>/objects\n+\t * standard layout with .git/(modules/<name>)+/objects\n \t */\n-\tif (ends_with(alt->path, \".git/objects\")) {\n+\tif (ends_with(alt->path, \"/objects\")) {\n \t\tchar *sm_alternate;\n \t\tstruct strbuf sb = STRBUF_INIT;\n \t\tstruct strbuf err = STRBUF_INIT;\n@@ -583,6 +583,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)\n \tstruct strbuf rel_path = STRBUF_INIT;\n \tstruct strbuf sb = STRBUF_INIT;\n \tstruct string_list reference = STRING_LIST_INIT_NODUP;\n+\tchar *sm_alternate = NULL, *error_strategy = NULL;\n \n \tstruct option module_clone_options[] = {\n \t\tOPT_STRING(0, \"prefix\", &prefix,\n@@ -672,6 +673,20 @@ static int module_clone(int argc, const char **argv, const char *prefix)\n \t\tdie(_(\"could not get submodule directory for '%s'\"), path);\n \tgit_config_set_in_file(p, \"core.worktree\",\n \t\t\t       relative_path(path, sm_gitdir, &rel_path));\n+\n+\t/* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */\n+\tgit_config_get_string(\"submodule.alternateLocation\", &sm_alternate);\n+\tif (sm_alternate)\n+\t\tgit_config_set_in_file(p, \"submodule.alternateLocation\",\n+\t\t\t\t\t   sm_alternate);\n+\tgit_config_get_string(\"submodule.alternateErrorStrategy\", &error_strategy);\n+\tif (error_strategy)\n+\t\tgit_config_set_in_file(p, \"submodule.alternateErrorStrategy\",\n+\t\t\t\t\t   error_strategy);\n+\n+\tfree(sm_alternate);\n+\tfree(error_strategy);\n+\n \tstrbuf_release(&sb);\n \tstrbuf_release(&rel_path);\n \tfree(sm_gitdir);\ndiff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh\nindex 1c1e289..e159fc5 100755\n--- a/t/t7408-submodule-reference.sh\n+++ b/t/t7408-submodule-reference.sh\n@@ -125,4 +125,70 @@ test_expect_success 'ignoring missing submodule alternates passes clone and subm\n \t)\n '\n \n+test_expect_success 'preparing second superproject with a nested submodule plus partial clone' '\n+\ttest_create_repo supersuper &&\n+\t(\n+\t\tcd supersuper &&\n+\t\techo \"I am super super.\" >file &&\n+\t\tgit add file &&\n+\t\tgit commit -m B-super-super-initial\n+\t\tgit submodule add \"file://$base_dir/super\" subwithsub &&\n+\t\tgit commit -m B-super-super-added &&\n+\t\tgit submodule update --init --recursive &&\n+\t\tgit repack -ad\n+\t) &&\n+\tgit clone supersuper supersuper2 &&\n+\t(\n+\t\tcd supersuper2 &&\n+\t\tgit submodule update --init\n+\t)\n+'\n+\n+# At this point there are three root-level positories: A, B, super and super2\n+\n+test_expect_success 'nested submodule alternate in works and is actually used' '\n+\ttest_when_finished \"rm -rf supersuper-clone\" &&\n+\tgit clone --recursive --reference supersuper supersuper supersuper-clone &&\n+\t(\n+\t\tcd supersuper-clone &&\n+\t\t# test superproject has alternates setup correctly\n+\t\ttest_alternate_is_used .git/objects/info/alternates . &&\n+\t\t# immediate submodule has alternate:\n+\t\ttest_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub &&\n+\t\t# nested submodule also has alternate:\n+\t\ttest_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub\n+\t)\n+'\n+\n+check_that_two_of_three_alternates_are_used() {\n+\ttest_alternate_is_used .git/objects/info/alternates . &&\n+\t# immediate submodule has alternate:\n+\ttest_alternate_is_used .git/modules/subwithsub/objects/info/alternates subwithsub &&\n+\t# but nested submodule has no alternate:\n+\ttest_must_fail test_alternate_is_used .git/modules/subwithsub/modules/sub/objects/info/alternates subwithsub/sub\n+}\n+\n+\n+test_expect_success 'missing nested submodule alternate fails clone and submodule update' '\n+\ttest_when_finished \"rm -rf supersuper-clone\" &&\n+\ttest_must_fail git clone --recursive --reference supersuper2 supersuper2 supersuper-clone &&\n+\t(\n+\t\tcd supersuper-clone &&\n+\t\tcheck_that_two_of_three_alternates_are_used &&\n+\t\t# update of the submodule fails\n+\t\ttest_must_fail git submodule update --init --recursive\n+\t)\n+'\n+\n+test_expect_success 'missing nested submodule alternate in --reference-if-able mode' '\n+\ttest_when_finished \"rm -rf supersuper-clone\" &&\n+\tgit clone --recursive --reference-if-able supersuper2 supersuper2 supersuper-clone &&\n+\t(\n+\t\tcd supersuper-clone &&\n+\t\tcheck_that_two_of_three_alternates_are_used &&\n+\t\t# update of the submodule succeeds\n+\t\tgit submodule update --init --recursive\n+\t)\n+'\n+\n test_done\n-- \n2.10.2\n\n"},{"id":"307438","messageId":"12000496-2191-2915-8a9e-fe7c314c5676@gmail.com","threadId":"44649","inReplyTo":"20161208013814.4943-1-vi0oss@gmail.com","subject":"Re: [PATCH] submodule--helper: set alternateLocation for cloned submodules","fromName":"vi0oss","fromEmail":"vi0oss@gmail.com","sentAt":"2016-12-10T13:41:32Z","receivedAt":"2016-12-10T13:41:41Z","isPatch":true,"sender":{"key":"vi0oss@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173219?v=4"},"body":"On 12/08/2016 04:38 AM, vi0oss@gmail.com wrote:\n>      Third review: missing && in test fixed.\n>      \nShall something more be done about this or just wait until the patch \ngets reviewed and integrated?\n"},{"id":"307485","messageId":"CAGZ79kYUbsy2TQ1noqS-9zLVUkQaeJbv6vwxykS+A_HHcxGnCw@mail.gmail.com","threadId":"44649","inReplyTo":"12000496-2191-2915-8a9e-fe7c314c5676@gmail.com","subject":"Re: [PATCH] submodule--helper: set alternateLocation for cloned submodules","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-12-12T05:35:26Z","receivedAt":"2016-12-12T05:35:34Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sat, Dec 10, 2016 at 5:41 AM, vi0oss <vi0oss@gmail.com> wrote:\n> On 12/08/2016 04:38 AM, vi0oss@gmail.com wrote:\n>>\n>>      Third review: missing && in test fixed.\n>>\n>\n> Shall something more be done about this or just wait until the patch gets\n> reviewed and integrated?\n\nI have no further comments and think the most recent version you sent\nto the list\nis fine. However others are invited to comment as well. :)\n\nThanks,\nStefan\n"},{"id":"307513","messageId":"xmqqzik1m3i1.fsf@gitster.mtv.corp.google.com","threadId":"44649","inReplyTo":"CAGZ79kYUbsy2TQ1noqS-9zLVUkQaeJbv6vwxykS+A_HHcxGnCw@mail.gmail.com","subject":"Re: [PATCH] submodule--helper: set alternateLocation for cloned submodules","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-12-12T18:00:38Z","receivedAt":"2016-12-12T18:00:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> On Sat, Dec 10, 2016 at 5:41 AM, vi0oss <vi0oss@gmail.com> wrote:\n>> On 12/08/2016 04:38 AM, vi0oss@gmail.com wrote:\n>>>\n>>>      Third review: missing && in test fixed.\n>>>\n>>\n>> Shall something more be done about this or just wait until the patch gets\n>> reviewed and integrated?\n>\n> I have no further comments and think the most recent version you sent\n> to the list\n> is fine. However others are invited to comment as well. :)\n\nI'll take that as a reviewed-by from you and queue it.\n\nThanks, both.\n"}]}