submodule-helper: fix indexing in clone retry error reporting path

'git submodule--helper update-clone' has logic to retry failed clones a second time. For this purpose, there is a list of submodules to clone, and a second list that is filled with the submodules to retry. Within these lists, the submodules are identified by an index as if both lists were just appended. This works nicely except when the second clone attempt fails as well. To report an error, the identifying index must be adjusted by an offset so that it can be used as an index into the second list. However, the calculation uses the logical total length of the lists so that the result always points one past the end of the second list. Pick the correct index. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Acked-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Jul 22, 2016 at 21:15 UTC eb09121b745e9aa5bbd3fa438f873c3511f48b33
3 files changed +5 -5
builtin/submodule--helper.c
+1 -1
@@ -795,7 +795,7 @@ static int update_clone_task_finished(int result,
795 suc->failed_clones[suc->failed_clones_nr++] = ce;
796 return 0;
797 } else {
798 - idx = suc->current - suc->list.nr;
798 + idx -= suc->list.nr;
799 ce = suc->failed_clones[idx];
800 strbuf_addf(err, _("Failed to clone '%s' a second time, aborting"),
801 ce->name);
t/t5815-submodule-protos.sh
+2 -2
@@ -18,7 +18,7 @@ test_expect_success 'setup repository with submodules' '
18 git commit -m "add submodules"
19 '
20
21 -test_expect_failure 'clone with recurse-submodules fails' '
21 +test_expect_success 'clone with recurse-submodules fails' '
22 test_must_fail git clone --recurse-submodules . dst
23 '
24
@@ -32,7 +32,7 @@ test_expect_success 'update of ssh allowed' '
32 git -C dst submodule update ssh-module
33 '
34
35 -test_expect_failure 'update of ext not allowed' '
35 +test_expect_success 'update of ext not allowed' '
36 test_must_fail git -C dst submodule update ext-module
37 '
38
t/t7400-submodule-basic.sh
+2 -2
@@ -352,7 +352,7 @@ test_expect_success 'sync should fail with unknown submodule' '
352 test_failure_with_unknown_submodule sync
353 '
354
355 -test_expect_failure 'update should fail when path is used by a file' '
355 +test_expect_success 'update should fail when path is used by a file' '
356 echo hello >expect &&
357
358 echo "hello" >init &&
@@ -361,7 +361,7 @@ test_expect_failure 'update should fail when path is used by a file' '
361 test_cmp expect init
362 '
363
364 -test_expect_failure 'update should fail when path is used by a nonempty directory' '
364 +test_expect_success 'update should fail when path is used by a nonempty directory' '
365 echo hello >expect &&
366
367 rm -fr init &&