Re: [PATCH] disallow branch names that start with a hyphen

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Clemens Buchacher <drizzd@xxxxxx> 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@xxxxxx>
> ---
>  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?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]