Git development
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "D. Ben Knoble" <ben.knoble@gmail.com>
Cc: "Bence Csókás" <bence.csokas@arm.com>, git@vger.kernel.org
Subject: Re: [Bug] Porcelain allows creation of '@' branch
Date: Wed, 2 Sep 2026 03:37:53 -0400	[thread overview]
Message-ID: <20260902073753.GC70165@coredump.intra.peff.net> (raw)
In-Reply-To: <CALnO6CCph_xC394v_BetLPyoriYc9dLZY42LsXhjVNdvt2e-cQ@mail.gmail.com>

On Mon, Aug 31, 2026 at 03:59:56PM -0400, D. Ben Knoble wrote:

> But (with git refs list) we should see this creates a ref "refs/heads/@".
> 
> I happen to think that's extremely confusing given that "@" is the
> shorthand for HEAD, but… it's not against the current documented
> rules, I think. (e.g., "git switch @" will fail, since it sees "git
> switch HEAD"; using "refs/heads/@" will also fail.) git-checkout
> doesn't fail but also doesn't change to the "@" branch. Futzing with
> .git/HEAD and restoring the working tree works, but… yikes.
> 
> Of course, --branch mode is allowed to be stricter; maybe we should
> reject this case?

Yeah, sadly bare "@" is allowed in a component (but not "@{") because
we've maintained strict backwards compatibility. So I don't think it's a
_bug_ exactly, but in the past we have restricted the porcelain
interfaces (so git-branch, but not git-update-ref) to avoid such
footguns. The most notable one is HEAD:

  $ git check-ref-format refs/heads/HEAD; echo $?
  0

  $ git check-ref-format --branch HEAD; echo $?
  fatal: 'HEAD' is not a valid branch name
  128

which also shows off that "--branch" is a convenience option for using
those stricter porcelain rules.

I think it would make sense to treat bare "@" the same as HEAD here. We
probably _don't_ want to forbid any "@", though. Branches and tags like
foo@bar are legal (if IMHO somewhat gross), and less likely to be used
accidentally.

So I think there is no bug, in the sense that the system is working as
designed, but it sure would be a nice feature to block this footgun.

> (I don't recall offhand where we describe valid branch names, if at all.)

I don't think we document the magic porcelain-tightening rules anywhere.
That's probably OK in practice; the point of "check-ref-format --branch"
is to check against them programatically.

-Peff

  reply	other threads:[~2026-09-02  7:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 14:22 [Bug] Porcelain allows creation of '@' branch Bence Csókás
2026-08-31 19:59 ` D. Ben Knoble
2026-09-02  7:37   ` Jeff King [this message]
2026-09-03  8:38   ` Kristoffer Haugsbakk
2026-09-03 12:35     ` Bence Csókás
2026-09-03 15:14       ` Ben Knoble
2026-09-03 18:45         ` Junio C Hamano
2026-09-06  7:56           ` Kristoffer Haugsbakk

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=20260902073753.GC70165@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=ben.knoble@gmail.com \
    --cc=bence.csokas@arm.com \
    --cc=git@vger.kernel.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