fetch: fix segfault in --negotiate-only without --negotiation-tip=*

The recent --negotiate-only option would segfault in the call to oid_array_for_each() in negotiate_using_fetch() unless one or more --negotiation-tip=* options were provided. All of the other tests for the feature combine both, but nothing was checking this assumption, let's do that and add a test for it. Fixes a bug in 9c1e657a8fd (fetch: teach independent negotiation (no packfile), 2021-05-04). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jul 8, 2021 at 12:53 UTC eff40457a4ab4887c677453d11774322a494a98c
2 files changed +19
builtin/fetch.c
+3
@@ -1990,6 +1990,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1990 fetch_config_from_gitmodules(sfjc, rs);
1991 }
1992
1993 + if (negotiate_only && !negotiation_tip.nr)
1994 + die(_("--negotiate-only needs one or more --negotiate-tip=*"));
1995 +
1996 if (deepen_relative) {
1997 if (deepen_relative < 0)
1998 die(_("Negative depth in --deepen is not supported"));
t/t5702-protocol-v2.sh
+16
@@ -599,6 +599,22 @@ setup_negotiate_only () {
599 test_commit -C client three
600 }
601
602 +test_expect_success 'usage: --negotiate-only without --negotiation-tip' '
603 + SERVER="server" &&
604 + URI="file://$(pwd)/server" &&
605 +
606 + setup_negotiate_only "$SERVER" "$URI" &&
607 +
608 + cat >err.expect <<-\EOF &&
609 + fatal: --negotiate-only needs one or more --negotiate-tip=*
610 + EOF
611 +
612 + test_must_fail git -c protocol.version=2 -C client fetch \
613 + --negotiate-only \
614 + origin 2>err.actual &&
615 + test_cmp err.expect err.actual
616 +'
617 +
618 test_expect_success 'file:// --negotiate-only' '
619 SERVER="server" &&
620 URI="file://$(pwd)/server" &&