Skip to content

Commit

Permalink
normalize_name: allow more references under refs/
Browse files Browse the repository at this point in the history
Allow any well-formed reference name to live under refs/ removing the
condition that they be under refs/{heads,tags,remotes}/ as was the
design of git.

An exception is made for HEAD which is allowed to contain an OID
reference in detached HEAD state.

Signed-off-by: Carlos Martín Nieto <[email protected]>
  • Loading branch information
carlosmn authored and vmg committed Mar 29, 2011
1 parent 9a53df7 commit 83c9512
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1680,8 +1680,9 @@ static int normalize_name(char *buffer_out, const char *name, int is_oid_ref)
*buffer_out++ = *current++;
}

/* Object id refname have to contain at least one slash */
if (is_oid_ref && !contains_a_slash)
/* Object id refname have to contain at least one slash, except
* for HEAD in a detached state */
if (is_oid_ref && !contains_a_slash && strcmp(name, GIT_HEAD_FILE))
return GIT_EINVALIDREFNAME;

/* A refname can not end with ".lock" */
Expand All @@ -1690,9 +1691,13 @@ static int normalize_name(char *buffer_out, const char *name, int is_oid_ref)

*buffer_out = '\0';

/* For object id references, name has to start with refs/(heads|tags|remotes) */
if (is_oid_ref && !(!git__prefixcmp(buffer_out_start, GIT_REFS_HEADS_DIR) ||
!git__prefixcmp(buffer_out_start, GIT_REFS_TAGS_DIR) || !git__prefixcmp(buffer_out_start, GIT_REFS_REMOTES_DIR)))
/*
* For object id references, name has to start with refs/. Again,
* we need to allow HEAD to be in a detached state.
*/
if (is_oid_ref &&
!(git__prefixcmp(buffer_out_start, GIT_REFS_DIR) ||
strcmp(buffer_out_start, GIT_HEAD_FILE)))
return GIT_EINVALIDREFNAME;

return error;
Expand Down

0 comments on commit 83c9512

Please sign in to comment.