Skip to content

Commit b2fc822

Browse files
committed
Merge branch 'ab/fetch-negotiate-segv-fix'
Code recently added to support common ancestry negotiation during "git push" did not sanity check its arguments carefully enough. * ab/fetch-negotiate-segv-fix: fetch: fix segfault in --negotiate-only without --negotiation-tip=* fetch: document the --negotiate-only option send-pack.c: move "no refs in common" abort earlier
2 parents 368cab7 + eff4045 commit b2fc822

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

Documentation/config/fetch.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ fetch.negotiationAlgorithm::
6969
setting defaults to "skipping".
7070
Unknown values will cause 'git fetch' to error out.
7171
+
72-
See also the `--negotiation-tip` option for linkgit:git-fetch[1].
72+
See also the `--negotiate-only` and `--negotiation-tip` options to
73+
linkgit:git-fetch[1].
7374

7475
fetch.showForcedUpdates::
7576
Set to false to enable `--no-show-forced-updates` in

Documentation/fetch-options.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,17 @@ The argument to this option may be a glob on ref names, a ref, or the (possibly
6262
abbreviated) SHA-1 of a commit. Specifying a glob is equivalent to specifying
6363
this option multiple times, one for each matching ref name.
6464
+
65-
See also the `fetch.negotiationAlgorithm` configuration variable
66-
documented in linkgit:git-config[1].
65+
See also the `fetch.negotiationAlgorithm` and `push.negotiate`
66+
configuration variables documented in linkgit:git-config[1], and the
67+
`--negotiate-only` option below.
68+
69+
--negotiate-only::
70+
Do not fetch anything from the server, and instead print the
71+
ancestors of the provided `--negotiation-tip=*` arguments,
72+
which we have in common with the server.
73+
+
74+
Internally this is used to implement the `push.negotiate` option, see
75+
linkgit:git-config[1].
6776

6877
--dry-run::
6978
Show what would be done, without making any changes.

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"));

send-pack.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ int send_pack(struct send_pack_args *args,
486486
const char *push_cert_nonce = NULL;
487487
struct packet_reader reader;
488488

489+
if (!remote_refs) {
490+
fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
491+
"Perhaps you should specify a branch.\n");
492+
return 0;
493+
}
494+
489495
git_config_get_bool("push.negotiate", &push_negotiate);
490496
if (push_negotiate)
491497
get_commons_through_negotiation(args->url, remote_refs, &commons);
@@ -534,11 +540,6 @@ int send_pack(struct send_pack_args *args,
534540
}
535541
}
536542

537-
if (!remote_refs) {
538-
fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
539-
"Perhaps you should specify a branch.\n");
540-
return 0;
541-
}
542543
if (args->atomic && !atomic_supported)
543544
die(_("the receiving end does not support --atomic push"));
544545

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)