Re: [PATCH] We do not like "HEAD" as a new branch name
Johannes Schindelin wrote:
> This makes git-check-ref-format fail for "HEAD". Since the check is only
> executed when creating refs, the existing symbolic ref is safe.
Show 15 quoted lines
> diff --git a/refs.c b/refs.c
> index bda45f7..293bfe7 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -332,6 +332,11 @@ int check_ref_format(const char *ref)
> if (ch == '.' || bad_ref_char(ch))
> return -1;
>
> + /* do not allow "HEAD" as ref name */
> + if (ch == 'H' && (!strcmp(cp, "EAD") ||
> + !strncmp(cp, "EAD/", 4)))
> + return -1;
> +
> /* scan the rest of the path component */
> while ((ch = *cp++) != 0) {If you're have to open-code it, you might want to just do it all the way:
if (ch == 'H' && cp[0] == 'E' && cp[1] == 'A' && cp[2] == 'D' &&
(cp[3] == '\0' || cp[3] == '/')) -hpa