From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=121.127.44.66 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796466186; b=zqzcXtbI/O7N2fd/aLFAAloEiYUKVbnzN9XHjfbsx8EGfnSph6vBXt9byAZh50ot004Z k0SKoLUeIaW97fatCJEuMWs+R6TbTZ0fFGrxBWRsJkkTBxUgAiBPbeqS9poOOwT91CnUu WJ5+R0dKx9QJNXUu82qwwU76Icet1YDMv+VkJKA92QAvEM/VDEmq1b8sqCCPIIjH08Obk ZuYrAFlvg4YMAl1jnpLA4g3WoNAVfmfbMFOE7kpjOfflVURuSPOyXwGUH0qIjHcJwkcpH ZPHSn7EG3iZCD5gITtJ4ts7XzJYMzt9aaTxrCHSLh4ndcz7k5bP8k2dOoRmj/PY6yOQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796466186; h=DMARC-Filter:DKIM-Signature:DKIM-Signature:CFBL-Feedback-ID: CFBL-Address:X-Forward-Email-ID:X-Forward-Email-Sender: X-Forward-Email-Version:X-Forward-Email-Website:X-Complaints-To: X-Report-Abuse:X-Report-Abuse-To:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=zeqNlKaxayNdSnpZ2LEd14ll49z+AKm5zb+SPPEjfV8=; b=1SMGwWy3V3fqqe6yMusXSS+odd6/n17AIAEDvHYjJSvDXLDXjBVd4JAcfsDFwqMindvW BWooGkLKCY8VgRK3rlJ/Ih7CpKd0/GLK4DkFQ8lHeb9XM4JW/I+s0LRp2U3tMgGhZtJex xsOnT9Tp/HI0R53pIGzwlwUzMyoAq86hYp9v+7Pavg/51d1Ifx31/wLq177dK+nCzpyCf ektnbzg9vURGNQ6uvHI8e9g6hghv1rPJCQi6mAbBCcQ2v54Qq6c2vcdu4g4ZuVPaPvlrY HBS112sLI+xypwXQ0qroEpQShGaZndxAGcqGJMbjDKqHkTcigPFnMEazMoSiCvGGpZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=pfeifer-mail.de; spf=pass smtp.mailfrom=fe-bounces.pfeifer-mail.de; dkim=pass header.d=pfeifer-mail.de header.i=@pfeifer-mail.de header.a=rsa-sha256 header.s=fe-ee63e92792 header.b=lXNtASx5; dkim=pass header.d=forwardemail.net header.i=@forwardemail.net header.a=rsa-sha256 header.s=default header.b=cBqWFK9H; arc=none smtp.remote-ip=121.127.44.66 Received: from smtp.forwardemail.net (smtp.forwardemail.net [121.127.44.66]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10EEB606A32F for ; Sat, 5 Dec 2026 10:23:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 10EEB606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pfeifer-mail.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fe-bounces.pfeifer-mail.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=pfeifer-mail.de header.i=@pfeifer-mail.de header.a=rsa-sha256 header.s=fe-ee63e92792 header.b=lXNtASx5; dkim=pass (1024-bit key, unprotected) header.d=forwardemail.net header.i=@forwardemail.net header.a=rsa-sha256 header.s=default header.b=cBqWFK9H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pfeifer-mail.de; h=Content-Transfer-Encoding: MIME-Version: Message-ID: Date: Subject: Cc: To: From: CFBL-Address: CFBL-Feedback-ID; q=dns/txt; s=fe-ee63e92792; t=1796466185; bh=zeqNlKaxayNdSnpZ2LEd14ll49z+AKm5zb+SPPEjfV8=; b=lXNtASx5y3ZQ33AHaN5dDiHjGy2nyW6lkOqRMfl5nH3wmXl9ORzFDNv1bPDi601rHIWXYEdV9 KkziTJhdmIB1ZpfF/QJkUB3EtoSM80kHNs+PA8G32JztC2PEF6/ihbZs8niZwMzgDDQnIlJG8Ho 38bVOwbvoyRT40RyP8hoYXA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=forwardemail.net; h=Content-Transfer-Encoding: MIME-Version: Message-ID: Date: Subject: Cc: To: From: CFBL-Address: CFBL-Feedback-ID; q=dns/txt; s=default; t=1796466185; bh=zeqNlKaxayNdSnpZ2LEd14ll49z+AKm5zb+SPPEjfV8=; b=cBqWFK9HZEy0KRWgrQk4+4SedV8EDnKKZBhEoeQdx7wCd2eVONNIEUcnJSN1/VgRubaPaLOqJ jo0h/OHzzV2klhhzBk2enWF603x/klphuMV2zhExGIv5IHvfmwK6TN29HxLzqmULEPHiDpvXg46 kqdWGQOnMX0eAnRDrSnS06g= CFBL-Feedback-ID: 6b13e607cb727889df5570ad:ae8fefc6f07e897e234ac60e9bc2ddb0 CFBL-Address: abuse@forwardemail.net; report=arf X-Forward-Email-ID: 6b13e607cb727889df5570ad X-Forward-Email-Sender: rfc822; daniel@pfeifer-mail.de, smtp.forwardemail.net, 121.127.44.66 X-Forward-Email-Version: 2.19.47 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Daniel Pfeifer To: git@vger.kernel.org Cc: Daniel Pfeifer , Jiang Xin , =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= , Frantisek Hrbata , Junio C Hamano , Josh Steadmon Subject: [PATCH] transport-helper: negotiate dry-run before list Date: Sat, 5 Dec 2026 11:17:42 +0100 Message-ID: <20261205102246.47182-1-daniel@pfeifer-mail.de> X-Mailer: git-send-email 2.56.1 X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When all refs are up to date, push_refs_with_push() returns before sending the dry-run option. This makes an ordinary push indistinguishable from a dry run for the remote helper. Negotiate dry-run before listing refs. Send false explicitly so helpers can distinguish ordinary pushes from sessions initiated by older versions of Git. Preserve the existing behavior for helpers that do not support the dry-run option. Signed-off-by: Daniel Pfeifer --- I maintain git-nostr (https://git-nostr.dev), a remote helper that uses existing Git hosting services for object storage and publishes repository state to Nostr relays. A push to the Git server may succeed while publication to one or more Nostr relays fails. I would like users to be able to retry publication by simply repeating `git push`, without having to change any refs. The helper could reconcile the published state with the actual repository state at the end of the session. However, when all refs are already up to date, both `git push` and `git push --dry-run` produce the same protocol sequence: ``` capabilities option progress false option verbosity 1 list for-push ``` The helper cannot determine whether it is permitted to publish anything. Sending an explicit dry-run value before `list for-push` would resolve this ambiguity. Sending false explicitly also allows the helper to remain compatible with older Git versions without relying on version detection. Documentation/gitremote-helpers.adoc | 4 + t/t5803-remote-helper-push.sh | 106 +++++++++++++++++++++++++++ transport-helper.c | 20 ++++- transport.c | 1 + transport.h | 3 + 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100755 t/t5803-remote-helper-push.sh diff --git a/Documentation/gitremote-helpers.adoc b/Documentation/gitremote-helpers.adoc index 440a55d9c7..faa843834b 100644 --- a/Documentation/gitremote-helpers.adoc +++ b/Documentation/gitremote-helpers.adoc @@ -507,6 +507,10 @@ set by Git if the remote helper has the 'option' capability. If true, pretend the operation completed successfully, but don't actually change any repository data. For most helpers this only applies to the 'push', if supported. + When preparing a push via the 'push' or 'export' capability, + Git sends this option before listing refs when the helper + advertises the 'option' capability, even if no ref updates + are needed. 'option servpath ':: Sets service path (--upload-pack, --receive-pack etc.) for diff --git a/t/t5803-remote-helper-push.sh b/t/t5803-remote-helper-push.sh new file mode 100755 index 0000000000..cf1201949f --- /dev/null +++ b/t/t5803-remote-helper-push.sh @@ -0,0 +1,106 @@ +#!/bin/sh + +test_description='Test remote-helper push options' + +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + +. ./test-lib.sh + +test_expect_success 'setup remote helper with push capability' ' + test_commit initial && + HELPER_OID=$(git rev-parse HEAD) && + HELPER_LOG="$PWD/helper.log" && + export HELPER_OID HELPER_LOG && + write_script git-remote-dryrun <<-\EOF && + while read -r line + do + case "$line" in + capabilities) + printf "push\noption\nobject-format\n\n" + ;; + "option dry-run "*) + echo "$line" >>"$HELPER_LOG" + echo "${HELPER_DRY_RUN_RESPONSE:-ok}" + ;; + "option object-format true") + echo ok + ;; + option\ *) + echo unsupported + ;; + "list for-push") + echo "$line" >>"$HELPER_LOG" + echo ":object-format $(git rev-parse --show-object-format)" + echo "$HELPER_OID refs/heads/main" + echo + ;; + push\ *) + echo "$line" >>"$HELPER_LOG" + read -r end && test -z "$end" || exit 1 + printf "ok refs/heads/main\n\n" + ;; + "") + exit 0 + ;; + *) + exit 1 + ;; + esac + done + EOF + PATH="$PWD:$PATH" && + export PATH && + git remote add origin dryrun::test +' + +test_expect_success 'up-to-date push tells helper it is not a dry run' ' + test_write_lines "option dry-run false" "list for-push" >expect && + >"$HELPER_LOG" && + git push origin HEAD:refs/heads/main && + test_cmp expect "$HELPER_LOG" +' + +test_expect_success 'send dry-run before listing up-to-date refs' ' + test_write_lines "option dry-run true" "list for-push" >expect && + >"$HELPER_LOG" && + git push --dry-run origin HEAD:refs/heads/main && + test_cmp expect "$HELPER_LOG" +' + +test_expect_success 'up-to-date dry-run tolerates unsupported option' ' + test_write_lines "option dry-run true" "list for-push" >expect && + >"$HELPER_LOG" && + HELPER_DRY_RUN_RESPONSE=unsupported \ + git push --dry-run origin HEAD:refs/heads/main && + test_cmp expect "$HELPER_LOG" +' + +test_expect_success 'dry-run option is sent once even if refs need updating' ' + test_commit second && + test_write_lines "option dry-run true" "list for-push" \ + "push HEAD:refs/heads/main" >expect && + >"$HELPER_LOG" && + git push --dry-run origin HEAD:refs/heads/main && + test_cmp expect "$HELPER_LOG" +' + +test_expect_success 'dry-run with ref updates requires helper support' ' + test_write_lines "option dry-run true" "list for-push" >expect && + >"$HELPER_LOG" && + test_must_fail env HELPER_DRY_RUN_RESPONSE=unsupported \ + git push --dry-run origin HEAD:refs/heads/main 2>err && + test_grep "does not support dry-run" err && + test_cmp expect "$HELPER_LOG" +' + +test_expect_success 'normal push tolerates unsupported dry-run option' ' + test_write_lines "option dry-run false" "list for-push" \ + "push HEAD:refs/heads/main" >expect && + >"$HELPER_LOG" && + HELPER_DRY_RUN_RESPONSE=unsupported \ + git push origin HEAD:refs/heads/main && + test_cmp expect "$HELPER_LOG" +' + +test_done diff --git a/transport-helper.c b/transport-helper.c index 14d179e0f6..e1470a4901 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -50,6 +50,8 @@ struct helper_data { */ unsigned get_refs_list_called : 1; + unsigned dry_run_option_accepted : 1; + char *export_marks; char *import_marks; /* These go from remote name (as in "list") to private name */ @@ -1007,8 +1009,10 @@ static int push_update_refs_status(struct helper_data *data, static void set_common_push_options(struct transport *transport, const char *name, int flags) { + struct helper_data *data = transport->data; + if (flags & TRANSPORT_PUSH_DRY_RUN) { - if (set_helper_option(transport, "dry-run", "true") != 0) + if (!data->dry_run_option_accepted) die(_("helper %s does not support dry-run"), name); } else if (flags & TRANSPORT_PUSH_CERT_ALWAYS) { if (set_helper_option(transport, TRANS_OPT_PUSH_CERT, "true") != 0) @@ -1251,12 +1255,26 @@ static int has_attribute(const char *attrs, const char *attr) static struct ref *get_refs_list(struct transport *transport, int for_push, struct transport_ls_refs_options *transport_options) { + struct helper_data *data = transport->data; + get_helper(transport); if (process_connect(transport, for_push)) return transport->vtable->get_refs_list(transport, for_push, transport_options); + /* + * A push can finish without sending updates. Communicate dry-run + * mode before listing refs, but defer checking whether the helper + * supports it until a transfer is requested. + */ + if (for_push && (data->push || data->export)) { + const char *dry_run = transport_options->dry_run ? "true" : "false"; + + data->dry_run_option_accepted = + !set_helper_option(transport, "dry-run", dry_run); + } + return get_refs_list_using_list(transport, for_push); } diff --git a/transport.c b/transport.c index 4491443b28..398a0079fe 100644 --- a/transport.c +++ b/transport.c @@ -1495,6 +1495,7 @@ int transport_push(struct repository *r, if (check_push_refs(local_refs, rs) < 0) goto done; + transport_options.dry_run = !!pretend; refspec_ref_prefixes(rs, &transport_options.ref_prefixes); trace2_region_enter("transport_push", "get_refs_list", r); diff --git a/transport.h b/transport.h index cb262ee3da..0e8f87ef29 100644 --- a/transport.h +++ b/transport.h @@ -267,6 +267,9 @@ int transport_push(struct repository *repo, unsigned int * reject_reasons); struct transport_ls_refs_options { + /* Whether the push being prepared is a dry run. */ + unsigned dry_run : 1; + /* * Optionally, a list of ref prefixes can be provided which can be sent * to the server (when communicating using protocol v2) to enable it to -- 2.56.1