Skip to content

Commit eff4045

Browse files
avargitster
authored andcommitted
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 9c1e657 (fetch: teach independent negotiation (no packfile), 2021-05-04). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 60fadf8 commit eff4045

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

builtin/fetch.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
19901990
fetch_config_from_gitmodules(sfjc, rs);
19911991
}
19921992

1993+
if (negotiate_only && !negotiation_tip.nr)
1994+
die(_("--negotiate-only needs one or more --negotiate-tip=*"));
1995+
19931996
if (deepen_relative) {
19941997
if (deepen_relative < 0)
19951998
die(_("Negative depth in --deepen is not supported"));

t/t5702-protocol-v2.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,22 @@ setup_negotiate_only () {
599599
test_commit -C client three
600600
}
601601

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+
602618
test_expect_success 'file:// --negotiate-only' '
603619
SERVER="server" &&
604620
URI="file://$(pwd)/server" &&

0 commit comments

Comments
 (0)