Skip to content

Commit

Permalink
Merge branch 'jc/disable-push-nego-for-deletion' into next
Browse files Browse the repository at this point in the history
"git push" that pushes only deletion gave an unnecessary and
harmless error message when push negotiation is configured, which
has been corrected.

* jc/disable-push-nego-for-deletion:
  push: avoid showing false negotiation errors
  • Loading branch information
gitster committed Jul 8, 2024
2 parents efcb154 + 4d8ee03 commit 18411fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions send-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,17 +427,26 @@ static void get_commons_through_negotiation(const char *url,
struct child_process child = CHILD_PROCESS_INIT;
const struct ref *ref;
int len = the_hash_algo->hexsz + 1; /* hash + NL */
int nr_negotiation_tip = 0;

child.git_cmd = 1;
child.no_stdin = 1;
child.out = -1;
strvec_pushl(&child.args, "fetch", "--negotiate-only", NULL);
for (ref = remote_refs; ref; ref = ref->next) {
if (!is_null_oid(&ref->new_oid))
strvec_pushf(&child.args, "--negotiation-tip=%s", oid_to_hex(&ref->new_oid));
if (!is_null_oid(&ref->new_oid)) {
strvec_pushf(&child.args, "--negotiation-tip=%s",
oid_to_hex(&ref->new_oid));
nr_negotiation_tip++;
}
}
strvec_push(&child.args, url);

if (!nr_negotiation_tip) {
child_process_clear(&child);
return;
}

if (start_command(&child))
die(_("send-pack: unable to fork off fetch subprocess"));

Expand Down
10 changes: 10 additions & 0 deletions t/t5516-fetch-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ test_expect_success 'push with negotiation proceeds anyway even if negotiation f
test_grep "push negotiation failed" err
'

test_expect_success 'push deletion with negotiation' '
mk_empty testrepo &&
git push testrepo $the_first_commit:refs/heads/master &&
git -c push.negotiate=1 push testrepo \
:master $the_first_commit:refs/heads/next 2>errors-2 &&
test_grep ! "negotiate-only needs one or " errors-2 &&
git -c push.negotiate=1 push testrepo :next 2>errors-1 &&
test_grep ! "negotiate-only needs one or " errors-1
'

test_expect_success 'push with negotiation does not attempt to fetch submodules' '
mk_empty submodule_upstream &&
test_commit -C submodule_upstream submodule_commit &&
Expand Down

0 comments on commit 18411fb

Please sign in to comment.