Thread View: linux.kernel.git
4 messages
4 total messages
Started by Tyler Cipriani
Sun, 18 Oct 2026 20:32
[PATCH v7 0/3] push: check pushed ref for --force-if-includes
Author: Tyler Cipriani
Date: Sun, 18 Oct 2026 20:32
Date: Sun, 18 Oct 2026 20:32
156 lines
15553 bytes
15553 bytes
--force-if-includes is meant to refuse a forced push unless the tip of
the remote-tracking ref has been integrated into the ref you're pushing.
But it checks the reflog of the local branch named after the
destination, regardless of the ref being pushed.
For example, this command consults the reflog of main instead of src:
git push --force-with-lease --force-if-includes origin src:main
Checking the wrong ref causes two problems:
- Data loss: if the local main has integrated origin/main, then the
check passes even when src is an unrelated or outdated branch,
allowing a push that clobbers the remote main.
- False rejections: if src has integrated origin/main but the local
main is behind or missing, the push is rejected with "remote ref
updated since checkout". Stefan Haller[0] and D. Ben Knoble[1] have
both reported this.
1/3 checks the reflog of the branch that the pushed ref resolves to.
2/3 gives pushes that cannot be checked their own rejection status and
advice.
3/3 fixes an existing bug: --force-if-includes runs its reflog check
before the fast-forward rules, so it can reject a push that needs no
force at all, e.g., when the reflog has expired. 1/3 makes this worse,
since every push of a non-branch ref now fails the reflog check.
Behavior change
---------------
Only a branch's reflog records whether the remote tip was integrated
into it, so --force-if-includes can only verify a source that resolves
to a branch. HEAD's reflog spans all branches, and was rejected as too
broad in the original review[2]. A tag's reflog, when it exists, records
where the tag pointed. Mapping an oid to "the branch that points at it"
is ambiguous, since many branches can point at the same commit.
So a forced push whose source does not resolve to a branch (a detached
HEAD, a tag, an oid) is now rejected as unverifiable. The advice
suggests naming the expected value with
--force-with-lease=<ref>:<expect>, or skipping the check with
--no-force-if-includes.
This breaks workflows that only appear to work today. For example, this
passes today if a local "hotfix" branch has integrated origin/hotfix,
even though nothing about <tag> is checked:
git push --force-with-lease --force-if-includes origin <tag>:hotfix
Fast-forward pushes of non-branch refs are still allowed (3/3), since a
fast-forward shows the remote tip has been integrated.
I'd welcome opinions on this trade-off.
Changes since v6:
- 1/3: fix a doubled "for" and the spelling of
check_if_includes_upstream in the log message.
- 3/3: add missing "()" to function name in log message.
- Rebase on maint at v2.56.0, resolving conflicts with a85a43c480
(push: suggest <remote> <branch> for a slash slip, 2026-06-27). The
advice changes in the 2/3 range-diff are context from the
pushRepoLooksLikeRef advice added there.
- The textual conflict in t5533 with as/push-force-if-includes-no-reflog
remains: both topics add tests after the same existing test.
Earlier changes are listed in the v6 cover letter[3].
The new tests fail on maint and pass with this series applied.
[0]: <https://lore.kernel.org/git/f51c73ed-eb03-83ca-fb31-d3e2645c9a63@haller-berlin.de>
[1]: <https://lore.kernel.org/git/CALnO6CCk0SgwObQRnpd5Pt_DvCKF8dBmyVHivU6Nr_O-GusGLA@mail.gmail.com>
[2]: <https://lore.kernel.org/git/xmqqsgbdk69b.fsf@gitster.c.googlers.com/>
[3]: <https://lore.kernel.org/git/20260917224351.57171-1-tyler@tylercipriani.com/>
Tyler Cipriani (3):
push: check pushed ref for --force-if-includes
push: fix --force-if-includes non-branch advice
push: --force-if-includes should allow fast-forward
Documentation/config/advice.adoc | 4 ++
advice.c | 1 +
advice.h | 1 +
builtin/push.c | 17 +++++
builtin/send-pack.c | 5 ++
remote.c | 43 ++++++++++--
remote.h | 10 ++-
send-pack.c | 1 +
t/t5533-push-cas.sh | 115 ++++++++++++++++++++++++++++++-
transport-helper.c | 5 ++
transport.c | 8 +++
transport.h | 1 +
12 files changed, 203 insertions(+), 8 deletions(-)
Range-diff against v6:
1: e7912c3fd0 ! 1: 959490bb0a push: check pushed ref for --force-if-includes
@@ Commit message
The early return when peer_ref is missing in check_if_includes_upstream
is necessary because apply_push_cas walks every advertised ref whenever
use_tracking_for_rest is set (i.e., a bare --force-with-lease), so
- check_if_includes upstream is called for for refs that are not part of
- the push.
+ check_if_includes upstream is called for refs that are not part of the
+ push.
Remove unnecessary check for empty return from get_local_ref, since it
never returns NULL for a non-empty name.
2: f85041efa8 ! 2: 92ef5412e1 push: fix --force-if-includes non-branch advice
@@ Documentation/config/advice.adoc: all advice messages.
+ Shown when linkgit:git-push[1] rejects a forced update of
+ a branch when we are unable to verify the remote-tracking
+ ref is integrated locally.
- pushUnqualifiedRefname::
- Shown when linkgit:git-push[1] gives up trying to
- guess based on the source and destination refs what
+ pushRepoLooksLikeRef::
+ Shown when the repository given to linkgit:git-push[1] is not
+ a configured remote but looks like a `<remote>/<branch>` ref,
## advice.c ##
@@ advice.c: static struct {
@@ advice.c: static struct {
[ADVICE_PUSH_NON_FF_MATCHING] = { "pushNonFFMatching" },
[ADVICE_PUSH_REF_NEEDS_UPDATE] = { "pushRefNeedsUpdate" },
+ [ADVICE_PUSH_REF_UNVERIFIABLE] = { "pushRefUnverifiable" },
+ [ADVICE_PUSH_REPO_LOOKS_LIKE_REF] = { "pushRepoLooksLikeRef" },
[ADVICE_PUSH_UNQUALIFIED_REF_NAME] = { "pushUnqualifiedRefName" },
[ADVICE_PUSH_UPDATE_REJECTED] = { "pushUpdateRejected" },
- [ADVICE_PUSH_UPDATE_REJECTED_ALIAS] = { "pushNonFastForward" }, /* backwards compatibility */
## advice.h ##
@@ advice.h: enum advice_type {
@@ advice.h: enum advice_type {
ADVICE_PUSH_NON_FF_MATCHING,
ADVICE_PUSH_REF_NEEDS_UPDATE,
+ ADVICE_PUSH_REF_UNVERIFIABLE,
+ ADVICE_PUSH_REPO_LOOKS_LIKE_REF,
ADVICE_PUSH_UNQUALIFIED_REF_NAME,
ADVICE_PUSH_UPDATE_REJECTED,
- ADVICE_PUSH_UPDATE_REJECTED_ALIAS,
## builtin/push.c ##
@@ builtin/push.c: static const char message_advice_ref_needs_update[] =
3: f9d97b0644 ! 3: f97092092d push: --force-if-includes should allow fast-forward
@@ Metadata
## Commit message ##
push: --force-if-includes should allow fast-forward
- In set_ref_status_for_push, we apply --force-if-includes's reflog
+ In set_ref_status_for_push(), we apply --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:
--
2.47.3
[PATCH v7 1/3] push: check pushed ref for --force-if-includes
Author: Tyler Cipriani
Date: Sun, 18 Oct 2026 20:32
Date: Sun, 18 Oct 2026 20:32
194 lines
14896 bytes
14896 bytes
"--force-if-includes" ensures, "tip of the remote-tracking ref is
reachable from one of the 'reflog' entries of the local branch."
But check_if_includes_upstream() uses the local per-branch reflog based
on the destination branch rather than the branch being pushed; using
ref->name vs. ref->peer_ref->name.
For example, this command looks at the reflog for main vs. src, even
though src is being pushed:
git push --force-if-includes --force-with-lease origin src:main
This can cause confusing rejections or unintended data loss.
False rejections: when src is up-to-date with the tip of origin's main,
but main is out-of-date or nonexistent, then the force-if-includes check
will fail, telling users the remote ref has been updated since the last
checkout.
Data loss: when src is an orphan/out-dated branch, but main is
up-to-date, then the force-if-includes check will allow the push,
clobbering the remote main.
Instead, use ref->peer_ref to locate a branch with a reflog. But if ref
does not resolve to a branch (e.g., a detached HEAD, a tag, an oid),
then we reject the push. The alternative would be to use HEAD's reflog,
which is too broad to tell us if the history being pushed includes the
tip of the remote. We need a per-branch reflog, which means that pushes
of a ref that do not resolve to a branch are rejected. Rejecting the
push of a ref like a detached HEAD already happens today (if the
same-named local branch lacks the remote tip); now the detached HEAD and
other non-branch pushes are explicitly rejected.
Allow deletions, e.g.:
git push --force-if-includes --force-with-lease origin :main
A deletion has no source ref, so no branch reflog can be checked.
Existing tests already enforce that deletions should work with
force-if-includes.
ref->deletion is set after apply_push_cas (which triggers
check_if_includes_upstream). The ref->peer_ref name is "(delete)".
Instead check with is_null_oid to detect and allow deletion.
The early return when peer_ref is missing in check_if_includes_upstream
is necessary because apply_push_cas walks every advertised ref whenever
use_tracking_for_rest is set (i.e., a bare --force-with-lease), so
check_if_includes upstream is called for refs that are not part of the
push.
Remove unnecessary check for empty return from get_local_ref, since it
never returns NULL for a non-empty name.
Reported-by: Stefan Haller <lists@haller-berlin.de>
Reported-by: D. Ben Knoble <ben.knoble@gmail.com>
Signed-off-by: Tyler Cipriani <tyler@tylercipriani.com>
---
remote.c | 26 +++++++++++++--
t/t5533-push-cas.sh | 81 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+), 2 deletions(-)
diff --git a/remote.c b/remote.c
index fe62068463..7cd7b0d6d4 100644
--- a/remote.c
+++ b/remote.c
@@ -2899,10 +2899,32 @@ static int is_reachable_in_reflog(const char *local, const struct ref *remote)
*/
static void check_if_includes_upstream(struct ref *remote)
{
- struct ref *local = get_local_ref(remote->name);
- if (!local)
+ struct ref *local;
+ const char *name;
+
+ /* ref without peer_ref will not be pushed */
+ if (!remote->peer_ref)
return;
+ /* A deletion has no local history to check against. */
+ if (is_null_oid(&remote->peer_ref->new_oid))
+ return;
+
+ name = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
+ remote->peer_ref->name,
+ RESOLVE_REF_READING, NULL, NULL);
+
+ /*
+ * if we resolve the ref to anything other than a branch,
+ * then there is no reliable reflog to check
+ */
+ if (!name || !starts_with(name, "refs/heads/")) {
+ remote->unreachable = 1;
+ return;
+ }
+
+ local = get_local_ref(name);
+
if (is_reachable_in_reflog(local->name, remote) <= 0)
remote->unreachable = 1;
free_one_ref(local);
diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh
index 2e14aecaa2..febf16fa7c 100755
--- a/t/t5533-push-cas.sh
+++ b/t/t5533-push-cas.sh
@@ -396,4 +396,85 @@ test_expect_success '"--force-if-includes" should allow deletes' '
)
'
+test_expect_success '"--force-if-includes" should allow forced update when using differently named branches' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ (
+ cd src &&
+ git fetch &&
+ git switch -c newbranch origin/main &&
+ git rebase HEAD --onto HEAD^ &&
+ git push --force-if-includes --force-with-lease origin newbranch:main
+ )
+'
+
+test_expect_success '"--force-if-includes" should allow forced update from HEAD' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ (
+ cd src &&
+ git fetch &&
+ git switch -c newbranch origin/main &&
+ git rebase HEAD --onto HEAD^ &&
+ git push --force-if-includes --force-with-lease origin HEAD: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" &&
+ (
+ cd src &&
+ git fetch &&
+ git switch main &&
+ git reset --hard origin/main &&
+ git switch --orphan orphan &&
+ test_commit I &&
+ test_must_fail git push --force-with-lease --force-if-includes origin orphan:main
+ )
+'
+
+test_expect_success '"--force-if-includes" should reject forced update from HEAD when it lacks remote ref' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ (
+ cd src &&
+ git fetch &&
+ git switch main &&
+ git reset --hard origin/main &&
+ git switch --orphan orphan &&
+ test_commit I &&
+ test_must_fail git push --force-with-lease --force-if-includes origin HEAD:main
+ )
+'
+
+test_expect_success '"--force-if-includes" should reject forced update from detached HEAD' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ (
+ cd src &&
+ git fetch &&
+ git switch main &&
+ git reset --hard origin/main &&
+ git switch -c newbranch origin/main &&
+ git checkout HEAD^ &&
+ test_must_fail git push --force-if-includes --force-with-lease origin HEAD:main
+ )
+'
+
+test_expect_success '"--force-if-includes" should reject forced update from tag' '
+ setup_src_dup_dst &&
+ test_when_finished "rm -fr dst src dup" &&
+ (
+ cd src &&
+ git fetch &&
+ git switch main &&
+ git reset --hard origin/main &&
+ git switch -c newbranch origin/main &&
+ git checkout HEAD^ &&
+ git tag stable &&
+ test_must_fail git push --force-if-includes --force-with-lease origin stable:main
+ )
+'
+
test_done
--
2.47.3
[PATCH v7 2/3] push: fix --force-if-includes non-branch advice
Author: Tyler Cipriani
Date: Sun, 18 Oct 2026 20:32
Date: Sun, 18 Oct 2026 20:32
306 lines
20278 bytes
20278 bytes
When a --force-if-includes push is rejected due to lacking a reflog to
consult, the advice is misleading:
! [rejected] HEAD -> main (remote ref updated since checkout)
error: failed to push some refs to '<remote>'
hint: Updates were rejected because the tip of the remote-tracking
hint: branch has been updated since the last checkout. If you want
hint: to integrate the remote changes, use 'git pull' before
hint: pushing again. See the 'Note about fast-forwards' in 'git
hint: push --help' for details.
But a `git pull` will not fix this rejection. What is required is either
- Specify the expected remote tip with --force-with-lease=<ref>:<expect>
- Ignore the error with --no-force-if-includes
Add ref->unverifiable to differentiate pushing something without a
reflog to consult vs. a remote update rejection.
Ensure tests check the rejection message.
Reported-by: D. Ben Knoble <ben.knoble@gmail.com>
Signed-off-by: Tyler Cipriani <tyler@tylercipriani.com>
---
Documentation/config/advice.adoc | 4 ++++
advice.c | 1 +
advice.h | 1 +
builtin/push.c | 17 +++++++++++++++++
builtin/send-pack.c | 5 +++++
remote.c | 5 ++++-
remote.h | 10 +++++++---
send-pack.c | 1 +
t/t5533-push-cas.sh | 11 ++++++++---
transport-helper.c | 5 +++++
transport.c | 8 ++++++++
transport.h | 1 +
12 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 81f80a9274..26078bc300 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -94,6 +94,10 @@ all advice messages.
Shown when linkgit:git-push[1] rejects a forced update of
a branch when its remote-tracking ref has updates that we
do not have locally.
+ pushRefUnverifiable::
+ Shown when linkgit:git-push[1] rejects a forced update of
+ a branch when we are unable to verify the remote-tracking
+ ref is integrated locally.
pushRepoLooksLikeRef::
Shown when the repository given to linkgit:git-push[1] is not
a configured remote but looks like a `<remote>/<branch>` ref,
diff --git a/advice.c b/advice.c
index 63bf8b0c5f..bcabc76a4f 100644
--- a/advice.c
+++ b/advice.c
@@ -69,6 +69,7 @@ static struct {
[ADVICE_PUSH_NON_FF_CURRENT] = { "pushNonFFCurrent" },
[ADVICE_PUSH_NON_FF_MATCHING] = { "pushNonFFMatching" },
[ADVICE_PUSH_REF_NEEDS_UPDATE] = { "pushRefNeedsUpdate" },
+ [ADVICE_PUSH_REF_UNVERIFIABLE] = { "pushRefUnverifiable" },
[ADVICE_PUSH_REPO_LOOKS_LIKE_REF] = { "pushRepoLooksLikeRef" },
[ADVICE_PUSH_UNQUALIFIED_REF_NAME] = { "pushUnqualifiedRefName" },
[ADVICE_PUSH_UPDATE_REJECTED] = { "pushUpdateRejected" },
diff --git a/advice.h b/advice.h
index 66f6cd6a77..933b297d6b 100644
--- a/advice.h
+++ b/advice.h
@@ -36,6 +36,7 @@ enum advice_type {
ADVICE_PUSH_NON_FF_CURRENT,
ADVICE_PUSH_NON_FF_MATCHING,
ADVICE_PUSH_REF_NEEDS_UPDATE,
+ ADVICE_PUSH_REF_UNVERIFIABLE,
ADVICE_PUSH_REPO_LOOKS_LIKE_REF,
ADVICE_PUSH_UNQUALIFIED_REF_NAME,
ADVICE_PUSH_UPDATE_REJECTED,
diff --git a/builtin/push.c b/builtin/push.c
index 2377b5af55..2ea73489d1 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -322,6 +322,13 @@ static const char message_advice_ref_needs_update[] =
"remote changes, use 'git pull' before pushing again.\n"
"See the 'Note about fast-forwards' in 'git push --help' for details.");
+static const char message_advice_ref_unverifiable[] =
+ N_("Updates were rejected because what you are pushing is not a branch,\n"
+ "so there is no reflog to check against the tip of the remote-tracking\n"
+ "branch. If you want to push anyway, specify the expected value with\n"
+ "'--force-with-lease=<ref>:<expect>' or use '--no-force-if-includes'\n"
+ "to skip this check.");
+
static void advise_pull_before_push(void)
{
if (!advice_enabled(ADVICE_PUSH_NON_FF_CURRENT) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
@@ -364,6 +371,14 @@ static void advise_ref_needs_update(void)
advise(_(message_advice_ref_needs_update));
}
+static void advise_ref_unverifiable(void)
+{
+ if (!advice_enabled(ADVICE_PUSH_REF_UNVERIFIABLE) ||
+ !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
+ return;
+ advise(_(message_advice_ref_unverifiable));
+}
+
static int push_with_options(struct transport *transport, struct refspec *rs,
int flags)
{
@@ -415,6 +430,8 @@ static int push_with_options(struct transport *transport, struct refspec *rs,
advise_ref_needs_force();
} else if (reject_reasons & REJECT_REF_NEEDS_UPDATE) {
advise_ref_needs_update();
+ } else if (reject_reasons & REJECT_REF_UNVERIFIABLE) {
+ advise_ref_unverifiable();
}
return 1;
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index d6cdbae472..efedd7dba7 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -76,6 +76,11 @@ static void print_helper_status(struct ref *ref)
msg = "remote ref updated since checkout";
break;
+ case REF_STATUS_REJECT_UNVERIFIABLE:
+ res = "error";
+ msg = "remote ref unverifiable";
+ break;
+
case REF_STATUS_REJECT_ALREADY_EXISTS:
res = "error";
msg = "already exists";
diff --git a/remote.c b/remote.c
index 7cd7b0d6d4..4258d8dabd 100644
--- a/remote.c
+++ b/remote.c
@@ -1719,6 +1719,9 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
else if (ref->check_reachable && ref->unreachable)
reject_reason =
REF_STATUS_REJECT_REMOTE_UPDATED;
+ else if (ref->check_reachable && ref->unverifiable)
+ reject_reason =
+ REF_STATUS_REJECT_UNVERIFIABLE;
else
/*
* If the ref isn't stale, and is reachable
@@ -2919,7 +2922,7 @@ static void check_if_includes_upstream(struct ref *remote)
* then there is no reliable reflog to check
*/
if (!name || !starts_with(name, "refs/heads/")) {
- remote->unreachable = 1;
+ remote->unverifiable = 1;
return;
}
diff --git a/remote.h b/remote.h
index cca02033b9..a453c5c2d2 100644
--- a/remote.h
+++ b/remote.h
@@ -171,10 +171,13 @@ struct ref {
/* Need to check if local reflog reaches the remote tip. */
check_reachable:1,
/*
- * Store the result of the check enabled by "check_reachable";
- * implies the local reflog does not reach the remote tip.
+ * Store the result of the check enabled by "check_reachable".
+ * "unreachable" implies the local reflog does not reach the remote
+ * tip. "unverifiable" implies no local branch reflog to check; i.e.,
+ * detached HEAD.
*/
- unreachable:1;
+ unreachable:1,
+ unverifiable:1;
enum {
REF_NOT_MATCHED = 0, /* initial value */
@@ -205,6 +208,7 @@ struct ref {
REF_STATUS_REJECT_STALE,
REF_STATUS_REJECT_SHALLOW,
REF_STATUS_REJECT_REMOTE_UPDATED,
+ REF_STATUS_REJECT_UNVERIFIABLE,
REF_STATUS_UPTODATE,
REF_STATUS_REMOTE_REJECT,
REF_STATUS_EXPECTING_REPORT,
diff --git a/send-pack.c b/send-pack.c
index f20460fbf4..69921f6b65 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -289,6 +289,7 @@ static int check_to_send_update(const struct ref *ref, const struct send_pack_ar
case REF_STATUS_REJECT_NEEDS_FORCE:
case REF_STATUS_REJECT_STALE:
case REF_STATUS_REJECT_REMOTE_UPDATED:
+ case REF_STATUS_REJECT_UNVERIFIABLE:
case REF_STATUS_REJECT_NODELETE:
return CHECK_REF_STATUS_REJECTED;
case REF_STATUS_UPTODATE:
diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh
index febf16fa7c..957b19f826 100755
--- a/t/t5533-push-cas.sh
+++ b/t/t5533-push-cas.sh
@@ -311,7 +311,8 @@ test_expect_success 'background updates to remote can be mitigated with "--force
git switch main &&
test_commit J &&
git fetch --all &&
- test_must_fail git push --force-with-lease --force-if-includes --all
+ test_must_fail git push --force-with-lease --force-if-includes --all 2>err &&
+ test_grep "remote ref updated since checkout" err
) &&
git ls-remote dst refs/heads/main >actual.main &&
git ls-remote dst refs/heads/branch >actual.branch &&
@@ -458,7 +459,9 @@ test_expect_success '"--force-if-includes" should reject forced update from deta
git reset --hard origin/main &&
git switch -c newbranch origin/main &&
git checkout HEAD^ &&
- test_must_fail git push --force-if-includes --force-with-lease origin HEAD:main
+ test_must_fail git push --force-if-includes --force-with-lease origin HEAD:main 2>err &&
+ test_grep "remote ref unverifiable" err &&
+ test_grep "no-force-if-includes" err
)
'
@@ -473,7 +476,9 @@ test_expect_success '"--force-if-includes" should reject forced update from tag'
git switch -c newbranch origin/main &&
git checkout HEAD^ &&
git tag stable &&
- test_must_fail git push --force-if-includes --force-with-lease origin stable:main
+ test_must_fail git push --force-if-includes --force-with-lease origin stable:main 2>err &&
+ test_grep "remote ref unverifiable" err &&
+ test_grep "no-force-if-includes" err
)
'
diff --git a/transport-helper.c b/transport-helper.c
index d5a064d386..06765febd6 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -907,6 +907,10 @@ static int push_update_ref_status(struct strbuf *buf,
status = REF_STATUS_REJECT_REMOTE_UPDATED;
FREE_AND_NULL(msg);
}
+ else if (!strcmp(msg, "remote ref unverifiable")) {
+ status = REF_STATUS_REJECT_UNVERIFIABLE;
+ FREE_AND_NULL(msg);
+ }
else if (!strcmp(msg, "forced update")) {
forced = 1;
FREE_AND_NULL(msg);
@@ -1060,6 +1064,7 @@ static int push_refs_with_push(struct transport *transport,
case REF_STATUS_REJECT_STALE:
case REF_STATUS_REJECT_ALREADY_EXISTS:
case REF_STATUS_REJECT_REMOTE_UPDATED:
+ case REF_STATUS_REJECT_UNVERIFIABLE:
if (atomic) {
reject_atomic_push(remote_refs, mirror);
string_list_clear(&cas_options, 0);
diff --git a/transport.c b/transport.c
index 25e2c14a7b..cc882ed15f 100644
--- a/transport.c
+++ b/transport.c
@@ -823,6 +823,11 @@ static int print_one_push_report(struct ref *ref, const char *dest, int count,
"remote ref updated since checkout",
report, porcelain, summary_width);
break;
+ case REF_STATUS_REJECT_UNVERIFIABLE:
+ print_ref_status('!', "[rejected]", ref, ref->peer_ref,
+ "remote ref unverifiable",
+ report, porcelain, summary_width);
+ break;
case REF_STATUS_REJECT_SHALLOW:
print_ref_status('!', "[rejected]", ref, ref->peer_ref,
"new shallow roots not allowed",
@@ -937,6 +942,8 @@ void transport_print_push_status(const char *dest, struct ref *refs,
*reject_reasons |= REJECT_NEEDS_FORCE;
} else if (ref->status == REF_STATUS_REJECT_REMOTE_UPDATED) {
*reject_reasons |= REJECT_REF_NEEDS_UPDATE;
+ } else if (ref->status == REF_STATUS_REJECT_UNVERIFIABLE) {
+ *reject_reasons |= REJECT_REF_UNVERIFIABLE;
}
}
free(head);
@@ -1394,6 +1401,7 @@ static int pre_push_hook_feed_stdin(int hook_stdin_fd, void *pp_cb UNUSED, void
switch (r->status) {
case REF_STATUS_REJECT_NONFASTFORWARD:
case REF_STATUS_REJECT_REMOTE_UPDATED:
+ case REF_STATUS_REJECT_UNVERIFIABLE:
case REF_STATUS_REJECT_STALE:
case REF_STATUS_UPTODATE:
return 0; /* skip refs which won't be pushed */
diff --git a/transport.h b/transport.h
index 39193d0077..ba51b65d93 100644
--- a/transport.h
+++ b/transport.h
@@ -258,6 +258,7 @@ void transport_set_verbosity(struct transport *transport, int verbosity,
#define REJECT_FETCH_FIRST 0x08
#define REJECT_NEEDS_FORCE 0x10
#define REJECT_REF_NEEDS_UPDATE 0x20
+#define REJECT_REF_UNVERIFIABLE 0x40
int transport_push(struct repository *repo,
struct transport *connection,
--
2.47.3
[PATCH v7 3/3] push: --force-if-includes should allow fast-forward
Author: Tyler Cipriani
Date: Sun, 18 Oct 2026 20:32
Date: Sun, 18 Oct 2026 20:32
120 lines
12692 bytes
12692 bytes
In set_ref_status_for_push(), we apply --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 reflog rejection for --force-if-includes until after
determining if a force push is needed.
Remember the reflog rejection reason as needs_force_reject_reason. If
the fast-forward rules reject the push for a ref, show the reflog
rejection reason to preserve existing behavior. But if fast-forward
rules allow a push (a fast-forward, deletion, or new ref), then a force
push is unneeded, the reflog rejection reason is discarded, and the push
proceeds.
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 4258d8dabd..0d7fd62a95 100644
--- a/remote.c
+++ b/remote.c
@@ -1687,6 +1687,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 needs_force_reject_reason = 0;
if (ref->peer_ref)
oidcpy(&ref->new_oid, &ref->peer_ref->new_oid);
@@ -1711,16 +1712,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 force push is needed.
*/
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 =
+ needs_force_reject_reason =
REF_STATUS_REJECT_REMOTE_UPDATED;
else if (ref->check_reachable && ref->unverifiable)
- reject_reason =
+ needs_force_reject_reason =
REF_STATUS_REJECT_UNVERIFIABLE;
else
/*
@@ -1764,6 +1766,14 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
reject_reason = REF_STATUS_REJECT_NONFASTFORWARD;
}
+ /*
+ * If fast-forward rules rejected the push and we were
+ * asked to verify the reflog but were unable to, then
+ * reflog verification is the right reject_reason.
+ */
+ if (needs_force_reject_reason && reject_reason)
+ reject_reason = needs_force_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 957b19f826..e99e93e411 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads