Skip to content

Commit 4d8ee03

Browse files
committed
push: avoid showing false negotiation errors
When "git push" is configured to use the push negotiation, a push of deletion of a branch (without pushing anything else) may end up not having anything to negotiate for the common ancestor discovery. In such a case, we end up making an internal invocation of "git fetch --negotiate-only" without any "--negotiate-tip" parameters that stops the negotiate-only fetch from being run, which by itself is not a bad thing (one fewer round-trip), but the end-user sees a "fatal: --negotiate-only needs one or more --negotiation-tip=*" message that the user cannot act upon. Teach "git push" to notice the situation and omit performing the negotiate-only fetch to begin with. One fewer process spawned, one fewer "alarming" message given the user. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 337b4d4 commit 4d8ee03

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

send-pack.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,26 @@ static void get_commons_through_negotiation(const char *url,
425425
struct child_process child = CHILD_PROCESS_INIT;
426426
const struct ref *ref;
427427
int len = the_hash_algo->hexsz + 1; /* hash + NL */
428+
int nr_negotiation_tip = 0;
428429

429430
child.git_cmd = 1;
430431
child.no_stdin = 1;
431432
child.out = -1;
432433
strvec_pushl(&child.args, "fetch", "--negotiate-only", NULL);
433434
for (ref = remote_refs; ref; ref = ref->next) {
434-
if (!is_null_oid(&ref->new_oid))
435-
strvec_pushf(&child.args, "--negotiation-tip=%s", oid_to_hex(&ref->new_oid));
435+
if (!is_null_oid(&ref->new_oid)) {
436+
strvec_pushf(&child.args, "--negotiation-tip=%s",
437+
oid_to_hex(&ref->new_oid));
438+
nr_negotiation_tip++;
439+
}
436440
}
437441
strvec_push(&child.args, url);
438442

443+
if (!nr_negotiation_tip) {
444+
child_process_clear(&child);
445+
return;
446+
}
447+
439448
if (start_command(&child))
440449
die(_("send-pack: unable to fork off fetch subprocess"));
441450

t/t5516-fetch-push.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ test_expect_success 'push with negotiation proceeds anyway even if negotiation f
230230
test_grep "push negotiation failed" err
231231
'
232232

233+
test_expect_success 'push deletion with negotiation' '
234+
mk_empty testrepo &&
235+
git push testrepo $the_first_commit:refs/heads/master &&
236+
git -c push.negotiate=1 push testrepo \
237+
:master $the_first_commit:refs/heads/next 2>errors-2 &&
238+
test_grep ! "negotiate-only needs one or " errors-2 &&
239+
git -c push.negotiate=1 push testrepo :next 2>errors-1 &&
240+
test_grep ! "negotiate-only needs one or " errors-1
241+
'
242+
233243
test_expect_success 'push with negotiation does not attempt to fetch submodules' '
234244
mk_empty submodule_upstream &&
235245
test_commit -C submodule_upstream submodule_commit &&

0 commit comments

Comments
 (0)