From: Junio C Hamano <gitster@pobox.com>
To: Tyler Cipriani <tyler@tylercipriani.com>
Cc: git@vger.kernel.org,
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>
Subject: Re: [PATCH v3 2/2] push: fix --force-if-includes detached HEAD advice
Date: Fri, 11 Sep 2026 08:40:56 -0700 [thread overview]
Message-ID: <xmqqtsnvdcdz.fsf@gitster.g> (raw)
In-Reply-To: <20260910230506.1631656-3-tyler@tylercipriani.com> (Tyler Cipriani's message of "Thu, 10 Sep 2026 17:05:06 -0600")
Tyler Cipriani <tyler@tylercipriani.com> writes:
> When a --force-if-includes push is rejected due to a detached HEAD
> state where there is no per-branch 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 between a detached HEAD rejection
> vs. a remote update rejection.
Makes sense.
> diff --git a/builtin/push.c b/builtin/push.c
> index 6021b71d66..9676c6241f 100644
> --- a/builtin/push.c
> +++ b/builtin/push.c
> @@ -319,6 +319,12 @@ 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 the tip of the remote-tracking branch\n"
> + "cannot be checked against a detached HEAD. If you want to push anyway,\n"
> + "specify the expected value with '--force-with-lease=<ref>:<expect>'\n"
> + "or use '--no-force-if-includes' to skip this check.");
Good.
> +static void advise_ref_unverifiable(void)
> +{
> + if (!advice_enabled(ADVICE_PUSH_REF_UNVERIFIABLE) || !advice_enabled(ADVICE_PUSH_UPDATE_REJECTED))
> + return;
Line that is over +100 column wide?
> + advise(_(message_advice_ref_unverifiable));
> +}
This is a tangent, but on a separate thread we were talking about
consolidating a sequence
if (advice_enabled(ADVICE_FOO))
advise(_(message for FOO));
into
advise_if_enabled(ADVICE_FOO, _(message for FOO));
This is an example of usage that falls outside of the pattern (not a
bad thing; just what those who advocate more use of advise_if_enabled()
need to be aware of).
> diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh
> index 0c02151747..fe6af3f41c 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 &&
> @@ -457,7 +458,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
> )
> '
Great.
prev parent reply other threads:[~2026-09-11 15:40 UTC|newest]
Thread overview: 22+ 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 [this message]
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=xmqqtsnvdcdz.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=lists@haller-berlin.de \
--cc=phillip.wood123@gmail.com \
--cc=shrinidhi.kaushik@gmail.com \
--cc=tyler@tylercipriani.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