git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Clemens Buchacher <drizzd@aon.at>
Cc: git@vger.kernel.org, Thomas Rast <trast@student.ethz.ch>
Subject: Re: [PATCH] disallow branch names that start with a hyphen
Date: Tue, 14 Sep 2010 13:09:20 -0700	[thread overview]
Message-ID: <7vtyls6qa7.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20100823043701.GA11822@localhost> (Clemens Buchacher's message of "Mon\, 23 Aug 2010 06\:37\:01 +0200")

Clemens Buchacher <drizzd@aon.at> writes:

> On Sun, Aug 22, 2010 at 02:20:17PM -0700, Junio C Hamano wrote:
>> 
>> forbid "checkout -b" and "branch" from creating such a branch.
>
> Sounds good to me. I will have limited access to email this week.
> I'll revisit this when I am back.

Heh, it turns out that we have a perfect place to hook this into.

-- >8 --
Subject: disallow branch names that start with a hyphen

The current command line parser overly lax in places and allows a branch
whose name begins with a hyphen e.g. "-foo" to be created, but the
parseopt infrastructure in general do not like to parse anything that
begin with a dash as a short-hand refname.  "git checkout -foo" won't
work, nor "git branch -d -foo" (even though "git branch -d -- -foo" works,
it does so by mistake; we should not be taking anything but pathspecs
after double-dash).

All the codepath that creates a new branch ref, including the destination
of "branch -m src dst", use strbuf_check_branch_ref() to validate if the
given name is suitable as a branch name.  Tighten it to disallow such a
name.

You can still get rid of historical mistake with

  $ git update-ref -d refs/heads/-foo

and third-party Porcelains are free to keep using update-ref to create
refs with path component that begins with "-".

Issue originally raised by Clemens Buchacher.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

diff --git a/strbuf.c b/strbuf.c
index bc3a080..65b4cf4 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -399,6 +399,8 @@ int strbuf_branchname(struct strbuf *sb, const char *name)
 int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
 {
 	strbuf_branchname(sb, name);
+	if (name[0] == '-')
+		return CHECK_REF_FORMAT_ERROR;
 	strbuf_splice(sb, 0, 0, "refs/heads/", 11);
 	return check_ref_format(sb->buf);
 }

  reply	other threads:[~2010-09-14 20:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-22 14:08 [PATCH] disallow branch names that start with a hyphen Clemens Buchacher
2010-08-22 21:20 ` Junio C Hamano
2010-08-23  4:37   ` Clemens Buchacher
2010-09-14 20:09     ` Junio C Hamano [this message]
2010-09-14 20:38       ` Jakub Narebski
2010-09-15  7:34       ` Clemens Buchacher

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vtyls6qa7.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=drizzd@aon.at \
    --cc=git@vger.kernel.org \
    --cc=trast@student.ethz.ch \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).