disallow branch names that start with a hyphen
commit6348624010888bd2353e5cebdc2b5329490b0f6d
authorJunio C Hamano <gitster@pobox.com>
Tue, 14 Sep 2010 20:09:20 +0000 (14 13:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Sep 2010 19:33:09 +0000 (15 12:33 -0700)
treec95e0852ac902097f720315f2ba56aedf4cde096
parent5879b6bbcaba7696e4abfa717748da166f915405
disallow branch names that start with a hyphen

The current command line parser is 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 does not like to parse anything that
begins with a dash as a short-hand refname.  "git checkout -foo" won't
work, nor will "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 codepaths that create 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 a branch
that begins with a hyphen.

You can still get rid of historical mistakes with

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

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

Issue originally raised by Clemens Buchacher.

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