Skip to contentSkip to conversation

submodule--helper: correct index computation

PATCH New Stefan Beller 1 participant 1 message Jul 21, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 submodule--helper: correct index computation

In 665b35eccd39 (2016-06-09, submodule--helper: initial clone learns retry logic), the index computation for the second round is wrong; it should make use of the index that was handed in via the idx_task_cb

Quoted 3 lines · pointer. When that commit was introduced, I wrote:

I wonder how we can test this properly as the git binary we have here is too reliable, but I observed the correctness of this patch when cloning a repo with lots of submodules and one of them failing.

This was only partially true as I did not observe the second try failing, only the first retry succeeding. Testing however is really easy, when the url of one submodule is bogus, so add a test for that.

---
 builtin/submodule--helper.c |  4 +++-
 t/t7406-submodule-update.sh | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
builtin/submodule--helper.c +3 -1
index 494e088..5d54885 100644
@@ -795,7 +795,9 @@ static int update_clone_task_finished(int result,
 		suc->failed_clones[suc->failed_clones_nr++] = ce;
 		return 0;
 	} else {
-		idx = suc->current - suc->list.nr;
+		idx -= suc->list.nr;
+		if (idx >= suc->failed_clones_nr)
+			die("BUG: idx too large???");
 		ce  = suc->failed_clones[idx];
 		strbuf_addf(err, _("Failed to clone '%s' a second time, aborting"),
 			    ce->name);
t/t7406-submodule-update.sh +16 -0
index 88e9750..ffb329f 100755
@@ -889,4 +889,20 @@ test_expect_success 'git clone passes the parallel jobs config on to submodules'
 	rm -rf super4
 '
 
+cat << EOF >expect
+Submodule 'deeper/submodule' (bogus-url) registered for path 'deeper/submodule'
+fatal: clone of 'bogus-url' into submodule path '$pwd/super4/deeper/submodule' failed
+Failed to clone 'deeper/submodule'. Retry scheduled
+fatal: clone of 'bogus-url' into submodule path '$pwd/super4/deeper/submodule' failed
+Failed to clone 'deeper/submodule' a second time, aborting
+EOF
+
+test_expect_success 'correct message for retries' '
+	test_when_finished "rm -rf super4" &&
+	git -C super config -f .gitmodules submodule."deeper/submodule".url bogus-url &&
+	git -C super commit -a -m "bogus url for one submodule" &&
+	test_must_fail git clone --recurse-submodules -j 1 super super4 2>&1 | grep deeper >actual &&
+	test_cmp expect actual
+'
+
 test_done
Signature · 1 line
2.9.2.370.g4a59376.dirty