git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Johannes Sixt <j6t@kdbg.org>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: The case of `git update-ref MERGE_HEAD`
Date: Mon, 15 Sep 2025 14:16:32 +0200	[thread overview]
Message-ID: <aMgDoGFy84EenCHF@pks.im> (raw)
In-Reply-To: <c9794ca2-0822-485f-a10f-6ecefa7275d1@kdbg.org>

On Fri, Sep 12, 2025 at 06:19:52PM +0200, Johannes Sixt wrote:
> When I commit a merge, the commit message shows this advice:
> 
> # It looks like you may be committing a merge.
> # If this is not correct, please run
> #       git update-ref -d MERGE_HEAD
> # and try again.
> 
> However, when I follow the advice, I get this error:
> 
> $ git update-ref -d MERGE_HEAD
> error: refusing to update pseudoref 'MERGE_HEAD'
> 
> Also, I found a use case to set MERGE_HEAD to a particular commit, but I
> can't do that, either:
> 
> $ git update-ref MERGE_HEAD e9c115e666fd6a3faaf187f5d145b32861a45cc8
> fatal: update_ref failed for ref 'MERGE_HEAD': refusing to update pseudoref 'MERGE_HEAD'
> 
> I know I can do
> 
> $ echo e9c115e666fd6a3faaf187f5d145b32861a45cc8 > .git/MERGE_HEAD
> 
> in the primary worktree. But I needed to do this in a secondary
> worktree, where this is more like
> 
> $ echo e9c115e666fd6a3faaf187f5d145b32861a45cc8 \
>      > "$(git rev-parse --git-dir)"/MERGE_HEAD
> 
> which is a bit unwieldy...
> 
> 8e4f5c2dc26e ("refs: refuse to write pseudorefs", 2024-05-15) removed
> the ability to wrangle pseudo-refs with `git update-ref`. Much earlier,
> b6d2558c9ea3 ("builtin/commit: suggest update-ref for pseudoref
> removal", 2020-08-21) changed the commit message template with the
> justification:
> 
> > [S]uggest a "update-ref -d" command, which will work regardless of
> > ref storage backend.
> 
> Looks like we couldn't uphold the promise. Any suggestions?

The best we can do is to special-case pseudorefs in relevant code paths.
But we have to be very careful with how exactly we do that. Pseudorefs
aren't real refs, so we for example do not want to add logic to update
them in the same transaction as normal references.

But for something like git-update-ref(1) we may specifically carve out a
way to delete and update a single pseudoref and then handle this outside
of the normal ref transaction logic.

Patrick

      reply	other threads:[~2025-09-15 12:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-12 16:19 The case of `git update-ref MERGE_HEAD` Johannes Sixt
2025-09-15 12:16 ` Patrick Steinhardt [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=aMgDoGFy84EenCHF@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    /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;
as well as URLs for NNTP newsgroup(s).