Skip to content

Commit b5847b9

Browse files
committed
Merge branch 'hx/push-atomic-with-cert'
"git push" that wants to be atomic and wants to send push certificate learned not to prepare and sign the push certificate when it fails the local check (hence due to atomicity it is known that no certificate is needed). * hx/push-atomic-with-cert: send-pack: run GPG after atomic push checking
2 parents 407d914 + a4f324a commit b5847b9

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

send-pack.c

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,12 @@ static int check_to_send_update(const struct ref *ref, const struct send_pack_ar
303303
return CHECK_REF_STATUS_REJECTED;
304304
case REF_STATUS_UPTODATE:
305305
return CHECK_REF_UPTODATE;
306+
306307
default:
308+
case REF_STATUS_EXPECTING_REPORT:
309+
/* already passed checks on the local side */
310+
case REF_STATUS_OK:
311+
/* of course this is OK */
307312
return 0;
308313
}
309314
}
@@ -510,13 +515,6 @@ int send_pack(struct send_pack_args *args,
510515
if (ref->deletion && !allow_deleting_refs)
511516
ref->status = REF_STATUS_REJECT_NODELETE;
512517

513-
if (!args->dry_run)
514-
advertise_shallow_grafts_buf(&req_buf);
515-
516-
if (!args->dry_run && push_cert_nonce)
517-
cmds_sent = generate_push_cert(&req_buf, remote_refs, args,
518-
cap_buf.buf, push_cert_nonce);
519-
520518
/*
521519
* Clear the status for each ref and see if we need to send
522520
* the pack data.
@@ -552,31 +550,35 @@ int send_pack(struct send_pack_args *args,
552550
ref->status = REF_STATUS_EXPECTING_REPORT;
553551
}
554552

553+
if (!args->dry_run)
554+
advertise_shallow_grafts_buf(&req_buf);
555+
555556
/*
556557
* Finally, tell the other end!
557558
*/
558-
for (ref = remote_refs; ref; ref = ref->next) {
559-
char *old_hex, *new_hex;
560-
561-
if (args->dry_run || push_cert_nonce)
562-
continue;
559+
if (!args->dry_run && push_cert_nonce)
560+
cmds_sent = generate_push_cert(&req_buf, remote_refs, args,
561+
cap_buf.buf, push_cert_nonce);
562+
else if (!args->dry_run)
563+
for (ref = remote_refs; ref; ref = ref->next) {
564+
char *old_hex, *new_hex;
563565

564-
if (check_to_send_update(ref, args) < 0)
565-
continue;
566+
if (check_to_send_update(ref, args) < 0)
567+
continue;
566568

567-
old_hex = oid_to_hex(&ref->old_oid);
568-
new_hex = oid_to_hex(&ref->new_oid);
569-
if (!cmds_sent) {
570-
packet_buf_write(&req_buf,
571-
"%s %s %s%c%s",
572-
old_hex, new_hex, ref->name, 0,
573-
cap_buf.buf);
574-
cmds_sent = 1;
575-
} else {
576-
packet_buf_write(&req_buf, "%s %s %s",
577-
old_hex, new_hex, ref->name);
569+
old_hex = oid_to_hex(&ref->old_oid);
570+
new_hex = oid_to_hex(&ref->new_oid);
571+
if (!cmds_sent) {
572+
packet_buf_write(&req_buf,
573+
"%s %s %s%c%s",
574+
old_hex, new_hex, ref->name, 0,
575+
cap_buf.buf);
576+
cmds_sent = 1;
577+
} else {
578+
packet_buf_write(&req_buf, "%s %s %s",
579+
old_hex, new_hex, ref->name);
580+
}
578581
}
579-
}
580582

581583
if (use_push_options) {
582584
struct string_list_item *item;

t/t5534-push-signed.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,27 @@ test_expect_success GPGSM 'fail without key and heed user.signingkey x509' '
273273
test_cmp expect dst/push-cert-status
274274
'
275275

276+
test_expect_success GPG 'failed atomic push does not execute GPG' '
277+
prepare_dst &&
278+
git -C dst config receive.certnonceseed sekrit &&
279+
write_script gpg <<-EOF &&
280+
# should check atomic push locally before running GPG.
281+
exit 1
282+
EOF
283+
test_must_fail env PATH="$TRASH_DIRECTORY:$PATH" git push \
284+
--signed --atomic --porcelain \
285+
dst noop ff noff >out 2>&1 &&
286+
287+
test_i18ngrep ! "gpg failed to sign" out &&
288+
sed -n -e "/^To dst/,$ p" out >actual &&
289+
cat >expect <<-EOF &&
290+
To dst
291+
= refs/heads/noop:refs/heads/noop [up to date]
292+
! refs/heads/ff:refs/heads/ff [rejected] (atomic push failed)
293+
! refs/heads/noff:refs/heads/noff [rejected] (non-fast-forward)
294+
Done
295+
EOF
296+
test_i18ncmp expect actual
297+
'
298+
276299
test_done

0 commit comments

Comments
 (0)