Git development
 help / color / mirror / Atom feed
From: Tyler Cipriani <tyler@tylercipriani.com>
To: git@vger.kernel.org
Cc: Tyler Cipriani <tyler@tylercipriani.com>,
	Srinidhi Kaushik <shrinidhi.kaushik@gmail.com>,
	Stefan Haller <lists@haller-berlin.de>,
	"D. Ben Knoble" <ben.knoble@gmail.com>,
	Phillip Wood <phillip.wood123@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v5 3/3] push: --force-if-includes should allow fast-forward
Date: Tue, 15 Sep 2026 17:33:05 -0600	[thread overview]
Message-ID: <20260915233305.334115-4-tyler@tylercipriani.com> (raw)
In-Reply-To: <20260915233305.334115-1-tyler@tylercipriani.com>

In set_ref_status_for_push, we verify --force-if-includes's reflog
reachability checks before fast-forward rules. As a result, valid
fast-forward pushes may be rejected when a force push is unneeded; like
when the reflog is expired:

    git clone repo.git repo
    git commit --allow-empty -m 1
    git reflog expire --expire=all --all
    git push --force-with-lease --force-if-includes origin main
    ! [rejected]    main -> main (remote ref updated since checkout)

Rejecting fast-forwards is a mismatch with the --force-if-includes
documentation "Force an update only if the tip of the remote-tracking
ref has been integrated locally."

Instead, defer check for --force-if-includes until after determining if
a push force is needed.

Opted to create a deferred_reject_reason in set_ref_status_for_push
rather than move the computation of reachability or verifiability to
winnow scope of changes in this patch. Lazily checking for reachability
or verifiability is a valid followup.

Signed-off-by: Tyler Cipriani <tyler@tylercipriani.com>
---
 remote.c            | 16 +++++++++++++---
 t/t5533-push-cas.sh | 27 +++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/remote.c b/remote.c
index b7b5ac0d28..db0b50b030 100644
--- a/remote.c
+++ b/remote.c
@@ -1669,6 +1669,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 	for (ref = remote_refs; ref; ref = ref->next) {
 		int force_ref_update = ref->force || force_update;
 		int reject_reason = 0;
+		int deferred_reject_reason = 0;
 
 		if (ref->peer_ref)
 			oidcpy(&ref->new_oid, &ref->peer_ref->new_oid);
@@ -1693,16 +1694,17 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 		 *
 		 * If the tip of the remote-tracking ref is unreachable
 		 * from any reflog entry of its local ref indicating a
-		 * possible update since checkout; reject the push.
+		 * possible update since checkout, then remember the
+		 * rejection in case the push is non-fast-forward.
 		 */
 		if (ref->expect_old_sha1) {
 			if (!oideq(&ref->old_oid, &ref->old_oid_expect))
 				reject_reason = REF_STATUS_REJECT_STALE;
 			else if (ref->check_reachable && ref->unreachable)
-				reject_reason =
+				deferred_reject_reason =
 					REF_STATUS_REJECT_REMOTE_UPDATED;
 			else if (ref->check_reachable && ref->unverifiable)
-				reject_reason =
+				deferred_reject_reason =
 					REF_STATUS_REJECT_UNVERIFIABLE;
 			else
 				/*
@@ -1746,6 +1748,14 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
 				reject_reason = REF_STATUS_REJECT_NONFASTFORWARD;
 		}
 
+		/*
+		 * If push is non-fast-forward and we were asked to
+		 * verify the reflog but were unable to, then reflog
+		 * verification is the right reject_reason.
+		 */
+		if (deferred_reject_reason && reject_reason)
+			reject_reason = deferred_reject_reason;
+
 		/*
 		 * "--force" will defeat any rejection implemented
 		 * by the rules above.
diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh
index 38576917e4..53e241c5b1 100755
--- a/t/t5533-push-cas.sh
+++ b/t/t5533-push-cas.sh
@@ -421,6 +421,33 @@ test_expect_success '"--force-if-includes" should allow forced update from HEAD'
 	)
 '
 
+test_expect_success '"--force-if-includes" should allow fast-forward push without local reflog' '
+	setup_src_dup_dst &&
+	test_when_finished "rm -fr dst src dup" &&
+	(
+		cd src &&
+		git fetch &&
+		git switch main &&
+		git reset --hard origin/main &&
+		test_commit I &&
+		git reflog expire --expire=all --all &&
+		git push --force-with-lease --force-if-includes origin main
+	)
+'
+
+test_expect_success '"--force-if-includes" should allow fast-forward push from tag' '
+	setup_src_dup_dst &&
+	test_when_finished "rm -fr dst src dup" &&
+	(
+		cd src &&
+		git fetch &&
+		git switch -c newbranch origin/main &&
+		test_commit I &&
+		git tag T &&
+		git push --force-with-lease --force-if-includes origin T:main
+	)
+'
+
 test_expect_success '"--force-if-includes" should reject forced update from differently named branches when local lacks remote ref' '
 	setup_src_dup_dst &&
 	test_when_finished "rm -fr dst src dup" &&
-- 
2.47.3


  parent reply	other threads:[~2026-09-15 23:33 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04 21:01 [PATCH 0/2] push: fix --force-if-includes consulting wrong ref Tyler Cipriani
2026-09-04 21:01 ` [PATCH 1/2] push: check pushed ref for --force-if-includes Tyler Cipriani
2026-09-05 18:57   ` Ben Knoble
2026-09-04 21:01 ` [PATCH 2/2] push: fix --force-if-includes detached HEAD advice Tyler Cipriani
2026-09-05 18:59 ` [PATCH 0/2] push: fix --force-if-includes consulting wrong ref Ben Knoble
2026-09-06 20:24   ` Tyler Cipriani
2026-09-08 22:20 ` [PATCH v2 " Tyler Cipriani
2026-09-09 11:59   ` D. Ben Knoble
2026-09-08 22:20 ` [PATCH v2 1/2] push: check pushed ref for --force-if-includes Tyler Cipriani
2026-09-10 18:43   ` Junio C Hamano
2026-09-10 22:08     ` Tyler Cipriani
2026-09-08 22:20 ` [PATCH v2 2/2] push: fix --force-if-includes detached HEAD advice Tyler Cipriani
2026-09-10 23:05 ` [PATCH v3 0/2] push: fix --force-if-includes consulting wrong ref Tyler Cipriani
2026-09-10 23:05   ` [PATCH v3 1/2] push: check pushed ref for --force-if-includes Tyler Cipriani
2026-09-11  6:55     ` Patrick Steinhardt
2026-09-11 22:58       ` Tyler Cipriani
2026-09-11 15:31     ` Junio C Hamano
2026-09-11 23:47       ` Tyler Cipriani
2026-09-10 23:05   ` [PATCH v3 2/2] push: fix --force-if-includes detached HEAD advice Tyler Cipriani
2026-09-11  6:55     ` Patrick Steinhardt
2026-09-11 16:03       ` Junio C Hamano
2026-09-11 15:40     ` Junio C Hamano
2026-09-14  4:00 ` [PATCH v4 0/2] push: check pushed ref for --force-if-includes Tyler Cipriani
2026-09-14  4:00   ` [PATCH v4 1/2] " Tyler Cipriani
2026-09-14  4:00   ` [PATCH v4 2/2] push: fix --force-if-includes non-branch advice Tyler Cipriani
2026-09-14 13:03   ` [PATCH v4 0/2] push: check pushed ref for --force-if-includes D. Ben Knoble
2026-09-14 19:27     ` Tyler Cipriani
2026-09-14 20:52       ` D. Ben Knoble
2026-09-15 23:33 ` [PATCH v5 0/3] " Tyler Cipriani
2026-09-15 23:33   ` [PATCH v5 1/3] " Tyler Cipriani
2026-09-15 23:33   ` [PATCH v5 2/3] push: fix --force-if-includes non-branch advice Tyler Cipriani
2026-09-15 23:33   ` Tyler Cipriani [this message]
2026-09-16 12:29     ` [PATCH v5 3/3] push: --force-if-includes should allow fast-forward D. Ben Knoble
2026-09-16 15:52       ` Tyler Cipriani
2026-09-16 17:53         ` Ben Knoble
2026-09-17 22:43 ` [PATCH v6 0/3] push: check pushed ref for --force-if-includes Tyler Cipriani
2026-09-17 22:43   ` [PATCH v6 1/3] " Tyler Cipriani
2026-09-17 22:43   ` [PATCH v6 2/3] push: fix --force-if-includes non-branch advice Tyler Cipriani
2026-09-17 22:43   ` [PATCH v6 3/3] push: --force-if-includes should allow fast-forward Tyler Cipriani
2026-10-05 21:26   ` [PATCH v6 0/3] push: check pushed ref for --force-if-includes Tyler Cipriani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260915233305.334115-4-tyler@tylercipriani.com \
    --to=tyler@tylercipriani.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=ben.knoble@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=lists@haller-berlin.de \
    --cc=phillip.wood123@gmail.com \
    --cc=shrinidhi.kaushik@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox