{"thread":{"id":"42897","subject":"[PATCH] submodule--helper: correct index computation","startedAt":"2016-07-21T01:39:31Z","lastAt":"2016-07-21T01:39:31Z","messageCount":1,"participants":["Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"291902","messageId":"20160721013923.17435-1-sbeller@google.com","threadId":"42897","inReplyTo":null,"subject":"[PATCH] submodule--helper: correct index computation","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-07-21T01:39:23Z","receivedAt":"2016-07-21T01:39:31Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"In 665b35eccd39 (2016-06-09, submodule--helper: initial clone learns\nretry logic), the index computation for the second round is wrong; it\nshould make use of the index that was handed in via the idx_task_cb\npointer. When that commit was introduced, I wrote:\n\n> I wonder how we can test this properly as the git binary we have here\n> is too reliable, but I observed the correctness of this patch when\n> cloning a repo with lots of submodules and one of them failing.\n\nThis was only partially true as I did not observe the second try failing,\nonly the first retry succeeding. Testing however is really easy, when the\nurl of one submodule is bogus, so add a test for that.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/submodule--helper.c |  4 +++-\n t/t7406-submodule-update.sh | 16 ++++++++++++++++\n 2 files changed, 19 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 494e088..5d54885 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -795,7 +795,9 @@ static int update_clone_task_finished(int result,\n \t\tsuc->failed_clones[suc->failed_clones_nr++] = ce;\n \t\treturn 0;\n \t} else {\n-\t\tidx = suc->current - suc->list.nr;\n+\t\tidx -= suc->list.nr;\n+\t\tif (idx >= suc->failed_clones_nr)\n+\t\t\tdie(\"BUG: idx too large???\");\n \t\tce  = suc->failed_clones[idx];\n \t\tstrbuf_addf(err, _(\"Failed to clone '%s' a second time, aborting\"),\n \t\t\t    ce->name);\ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex 88e9750..ffb329f 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -889,4 +889,20 @@ test_expect_success 'git clone passes the parallel jobs config on to submodules'\n \trm -rf super4\n '\n \n+cat << EOF >expect\n+Submodule 'deeper/submodule' (bogus-url) registered for path 'deeper/submodule'\n+fatal: clone of 'bogus-url' into submodule path '$pwd/super4/deeper/submodule' failed\n+Failed to clone 'deeper/submodule'. Retry scheduled\n+fatal: clone of 'bogus-url' into submodule path '$pwd/super4/deeper/submodule' failed\n+Failed to clone 'deeper/submodule' a second time, aborting\n+EOF\n+\n+test_expect_success 'correct message for retries' '\n+\ttest_when_finished \"rm -rf super4\" &&\n+\tgit -C super config -f .gitmodules submodule.\"deeper/submodule\".url bogus-url &&\n+\tgit -C super commit -a -m \"bogus url for one submodule\" &&\n+\ttest_must_fail git clone --recurse-submodules -j 1 super super4 2>&1 | grep deeper >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.9.2.370.g4a59376.dirty\n\n"}]}