Skip to content

Commit

Permalink
validate_headref: tighten ref-matching to just branches
Browse files Browse the repository at this point in the history
When we are trying to determine whether a directory contains
a git repository, one of the tests we do is to check whether
HEAD is either a symlink or a symref into the "refs/"
hierarchy, or a detached HEAD.

We can tighten this a little more, though: a non-detached
HEAD should always point to a branch (since checking out
anything else should result in detachment), so it is safe to
check for "refs/heads/".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jan 29, 2009
1 parent b296e8f commit b229d18
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions path.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ int validate_headref(const char *path)
/* Make sure it is a "refs/.." symlink */
if (S_ISLNK(st.st_mode)) {
len = readlink(path, buffer, sizeof(buffer)-1);
if (len >= 5 && !memcmp("refs/", buffer, 5))
if (len >= 11 && !memcmp("refs/heads/", buffer, 11))
return 0;
return -1;
}
Expand All @@ -178,7 +178,7 @@ int validate_headref(const char *path)
len -= 4;
while (len && isspace(*buf))
buf++, len--;
if (len >= 5 && !memcmp("refs/", buf, 5))
if (len >= 11 && !memcmp("refs/heads/", buf, 11))
return 0;
}

Expand Down

0 comments on commit b229d18

Please sign in to comment.