git.vger.kernel.org archive mirror
 help / color / mirror / 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: Sun, 22 Aug 2010 14:20:17 -0700	[thread overview]
Message-ID: <7vsk262vla.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: 20100822140801.GA6574@localhost

Clemens Buchacher <drizzd@aon.at> writes:

> Branch names such as "-", "--" or even "---" do
> not work with git checkout. Anything that starts
> with a hyphen is also potentially ambiguous with a
> command option.
>
> In order to avoid mistakes, do not allow such
> branch names.
>
> Signed-off-by: Clemens Buchacher <drizzd@aon.at>
> ---
>  refs.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)

While the inconsistency between "git branch -- -foo" (which succeeds and
creates refs/heads/-foo) and "git checkout -foo" (whcih does not work) is
a valid issue to address, I think this patch does so at a wrong level of
abstraction.  The abstractions implemented by refs.c and friends are at
the plumbing layer that is accessible by Porcelain scripts other people
write, and we should try not to break them with policy decisions the
Porcelains (e.g. "git checkout") we ship as part of the core git (e.g. we
do not like a branch whose name begins with a dash).

Currently these succeed:

    git update-ref refs/mine/-foo HEAD
    git update-ref -d refs/mine/-foo

so it is reasonable to expect that somebody has a Porcelain that uses a
convention to use its own refs namespace "mine" with leading dash to mean
something to it.  Your patch would break such a Porcelain rather badly,
but I do not think we have to break this to fix your problem.

Two valid approaches would be: (1) teach a syntax to checkout to allow
checking out such a branch; or (2) forbid "checkout -b" and "branch" from
creating such a branch.

I do not think in the context of the core git Porcelain it is necessary
to start allowing checking out "-foo" which we didn't before, so how about
fixing this by tightening the command line parsing rules for Porcelain
commands that create a new branch?

Note that either way update-ref should be kept as is, to allow third party
Porcelains to keep doing what they have been doing, _and_ to allow
unfortunate users who ran a broken "git branch" command with "-- -foo" as
its arguments to recover from it.

Hmm?

  reply	other threads:[~2010-08-22 21:20 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 [this message]
2010-08-23  4:37   ` Clemens Buchacher
2010-09-14 20:09     ` Junio C Hamano
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

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

  git send-email \
    --in-reply-to=7vsk262vla.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.
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).