Skip to content

Commit b229d18

Browse files
peffgitster
authored andcommitted
validate_headref: tighten ref-matching to just branches
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>
1 parent b296e8f commit b229d18

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

path.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ int validate_headref(const char *path)
154154
/* Make sure it is a "refs/.." symlink */
155155
if (S_ISLNK(st.st_mode)) {
156156
len = readlink(path, buffer, sizeof(buffer)-1);
157-
if (len >= 5 && !memcmp("refs/", buffer, 5))
157+
if (len >= 11 && !memcmp("refs/heads/", buffer, 11))
158158
return 0;
159159
return -1;
160160
}
@@ -178,7 +178,7 @@ int validate_headref(const char *path)
178178
len -= 4;
179179
while (len && isspace(*buf))
180180
buf++, len--;
181-
if (len >= 5 && !memcmp("refs/", buf, 5))
181+
if (len >= 11 && !memcmp("refs/heads/", buf, 11))
182182
return 0;
183183
}
184184

0 commit comments

Comments
 (0)