summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3b36854)
raw | patch | inline | side by side (parent: 3b36854)
author | Jeff King <peff@peff.net> | |
Fri, 3 Jun 2011 05:11:13 +0000 (01:11 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 6 Jun 2011 00:53:10 +0000 (17:53 -0700) |
The guess_remote_head function tries to figure out where a
remote's HEAD is pointing by comparing the sha1 of the
remote's HEAD with the sha1 of various refs found on the
remote. However, we were too liberal in matching refs, and
would match tags or remote tracking branches, even though
these things could not possibly be referenced by the HEAD
symbolic ref (since git will detach when checking them out).
As a result, a clone of a remote repository with a detached
HEAD might write "refs/tags/*" into our local HEAD, which is
bogus. The resulting HEAD should be detached.
The other related code path is remote.c's get_head_names()
(which is used for, among other things, "set-head -a"). This was
not affected, however, as that function feeds only refs from
refs/heads to guess_remote_head.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote's HEAD is pointing by comparing the sha1 of the
remote's HEAD with the sha1 of various refs found on the
remote. However, we were too liberal in matching refs, and
would match tags or remote tracking branches, even though
these things could not possibly be referenced by the HEAD
symbolic ref (since git will detach when checking them out).
As a result, a clone of a remote repository with a detached
HEAD might write "refs/tags/*" into our local HEAD, which is
bogus. The resulting HEAD should be detached.
The other related code path is remote.c's get_head_names()
(which is used for, among other things, "set-head -a"). This was
not affected, however, as that function feeds only refs from
refs/heads to guess_remote_head.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c | patch | blob | history | |
t/t5707-clone-detached.sh | patch | blob | history |
diff --git a/remote.c b/remote.c
index ca42a126ad04514f0ed8378768ebce98cfc5a659..f073b1ecf56e5549374bcea036474ed987485581 100644 (file)
--- a/remote.c
+++ b/remote.c
/* Look for another ref that points there */
for (r = refs; r; r = r->next) {
- if (r != head && !hashcmp(r->old_sha1, head->old_sha1)) {
+ if (r != head &&
+ !prefixcmp(r->name, "refs/heads/") &&
+ !hashcmp(r->old_sha1, head->old_sha1)) {
*tail = copy_ref(r);
tail = &((*tail)->next);
if (!all)
index 6cecd4cd3c46e7c5bc1e04fc3d05304d2d644e1d..d63b1e390e3b30ea30f9e5b37b5b4dd0c63fff02 100755 (executable)
git --git-dir=detached-tag/.git log -1 --format=%s >actual &&
test_cmp expect actual
'
-test_expect_failure 'cloned HEAD is detached' '
+test_expect_success 'cloned HEAD is detached' '
head_is_detached detached-tag
'