git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] submodule--helper: correct index computation

From
Stefan Beller <sbeller@google.com>
Date
Jul 21, 2016, 01:39 UTC
Message-ID
<20160721013923.17435-1-sbeller@google.com>

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 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.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c |  4 +++-
 t/t7406-submodule-update.sh | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 494e088..5d54885 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -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);
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 88e9750..ffb329f 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -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
-- 
2.9.2.370.g4a59376.dirty
Message 1 of 1 in “submodule--helper: correct index computation”
  1. submodule--helper: correct index computationStefan Beller, Jul 21, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.