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

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

 



Junio C Hamano <gitster@xxxxxxxxx> writes:

> 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@xxxxxxxxx>
> ---
> 
> 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);
>  }

Shouldn't it include update to Documentation/git-check-ref-format.txt?

-- 
Jakub Narebski
Poland
ShadeHawk on #git
--
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]