@matheusbsbs / matheus-bagliano / commits / b229d18a80
Fork 0

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>

Jeff King committed Jan 29, 2009 at 03:30 UTC b229d18a809c169314b7f0d048dc5a7632e8f916
1 file changed +2 -2
path.c
+2 -2
@@ -154,7 +154,7 @@ int validate_headref(const char *path)
154 /* Make sure it is a "refs/.." symlink */
155 if (S_ISLNK(st.st_mode)) {
156 len = readlink(path, buffer, sizeof(buffer)-1);
157 - if (len >= 5 && !memcmp("refs/", buffer, 5))
157 + if (len >= 11 && !memcmp("refs/heads/", buffer, 11))
158 return 0;
159 return -1;
160 }
@@ -178,7 +178,7 @@ int validate_headref(const char *path)
178 len -= 4;
179 while (len && isspace(*buf))
180 buf++, len--;
181 - if (len >= 5 && !memcmp("refs/", buf, 5))
181 + if (len >= 11 && !memcmp("refs/heads/", buf, 11))
182 return 0;
183 }
184