From: Kristoffer Haugsbakk <code@khaugsbakk.name>
To: git@vger.kernel.org
Cc: Kristoffer Haugsbakk <code@khaugsbakk.name>, peff@peff.net
Subject: [PATCH 2/3] object-name: don't allow @ as a branch name
Date: Mon, 7 Oct 2024 22:15:18 +0200 [thread overview]
Message-ID: <b88c2430f88b641d69e5f161d3a18cce113a81c9.1728331771.git.code@khaugsbakk.name> (raw)
In-Reply-To: <cover.1728331771.git.code@khaugsbakk.name>
`HEAD` is an invalid branch name.[1] But the `@` synonym is allowed.
This is just as inconvenient since commands like `git checkout @` will,
quite sensibly, do `git checkout HEAD` instead of checking out that
branch; in turn there is no practical reason to use this as a branch
name since you cannot even check out the branch itself (only check out
the commit which `refs/heads/@` points to).
† 1: a625b092cc5 (branch: correctly reject refs/heads/{-dash,HEAD},
2017-11-14)
Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---
object-name.c | 3 ++-
t/t3204-branch-name-interpretation.sh | 9 ++-------
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/object-name.c b/object-name.c
index 42e3ba4a77a..56b288ff4c3 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1763,7 +1763,8 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
strbuf_splice(sb, 0, 0, "refs/heads/", 11);
if (*name == '-' ||
- !strcmp(sb->buf, "refs/heads/HEAD"))
+ !strcmp(sb->buf, "refs/heads/HEAD") ||
+ !strcmp(sb->buf, "refs/heads/@"))
return -1;
return check_refname_format(sb->buf, 0);
diff --git a/t/t3204-branch-name-interpretation.sh b/t/t3204-branch-name-interpretation.sh
index 594e3e43e12..7dcd1308f8c 100755
--- a/t/t3204-branch-name-interpretation.sh
+++ b/t/t3204-branch-name-interpretation.sh
@@ -119,13 +119,8 @@ test_expect_success 'disallow deleting remote branch via @{-1}' '
expect_branch refs/heads/origin/previous two
'
-# The thing we are testing here is that "@" is the real branch refs/heads/@,
-# and not refs/heads/HEAD. These tests should not imply that refs/heads/@ is a
-# sane thing, but it _is_ technically allowed for now. If we disallow it, these
-# can be switched to test_must_fail.
-test_expect_success 'create branch named "@"' '
- git branch -f @ one &&
- expect_branch refs/heads/@ one
+test_expect_success 'disallow branch named "@"' '
+ test_must_fail git branch -f @ one
'
test_expect_success 'delete branch named "@"' '
--
2.46.1.641.g54e7913fcb6
next prev parent reply other threads:[~2024-10-07 20:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-07 20:15 [PATCH 0/3] object-name: don't allow @ as a branch name Kristoffer Haugsbakk
2024-10-07 20:15 ` [PATCH 1/3] object-name: fix whitespace Kristoffer Haugsbakk
2024-10-07 20:15 ` Kristoffer Haugsbakk [this message]
2024-10-07 20:44 ` [PATCH 2/3] object-name: don't allow @ as a branch name Jeff King
2024-10-07 20:56 ` Kristoffer Haugsbakk
2024-10-08 6:52 ` Jeff King
2024-10-08 20:37 ` Rubén Justo
2024-10-07 22:01 ` Junio C Hamano
2024-10-08 6:54 ` Jeff King
2024-10-07 20:15 ` [PATCH 3/3] t1402: exercise disallowed branch names Kristoffer Haugsbakk
2024-10-07 20:47 ` Jeff King
2024-10-07 20:37 ` [PATCH 0/3] object-name: don't allow @ as a branch name Jeff King
2024-10-07 20:40 ` Kristoffer Haugsbakk
2024-10-08 13:19 ` shejialuo
2024-10-08 14:19 ` Kristoffer Haugsbakk
2024-10-18 14:21 ` shejialuo
2024-10-08 18:17 ` Junio C Hamano
2024-10-09 12:00 ` shejialuo
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=b88c2430f88b641d69e5f161d3a18cce113a81c9.1728331771.git.code@khaugsbakk.name \
--to=code@khaugsbakk.name \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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).