Skip to content

Commit

Permalink
consider only branches in guess_remote_head
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 6, 2011
1 parent 3b36854 commit 61adfd3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,9 @@ struct ref *guess_remote_head(const struct ref *head,

/* 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)
Expand Down
2 changes: 1 addition & 1 deletion t/t5707-clone-detached.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test_expect_success 'cloned HEAD matches' '
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
'

Expand Down

0 comments on commit 61adfd3

Please sign in to comment.