Skip to content

Commit

Permalink
remote: make guess_remote_head() use exact HEAD lookup if it is avail…
Browse files Browse the repository at this point in the history
…able

Our usual method for determining the ref pointed to by HEAD
is to compare HEAD's sha1 to the sha1 of all refs, trying to
find a unique match.

However, some transports actually get to look at HEAD
directly; we should make use of that information when it is
available.  Currently, only http remotes support this
feature.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Feb 27, 2009
1 parent bc14fac commit fbb074c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,14 @@ struct ref *guess_remote_head(const struct ref *head,
if (!head)
return NULL;

/*
* Some transports support directly peeking at
* where HEAD points; if that is the case, then
* we don't have to guess.
*/
if (head->symref)
return copy_ref(find_ref_by_name(refs, head->symref));

/* If refs/heads/master could be right, it is. */
if (!all) {
r = find_ref_by_name(refs, "refs/heads/master");
Expand Down
11 changes: 11 additions & 0 deletions t/t5550-http-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,16 @@ test_expect_success 'fetch changes via http' '
test_cmp file clone/file
'

test_expect_success 'http remote detects correct HEAD' '
git push public master:other &&
(cd clone &&
git remote set-head origin -d &&
git remote set-head origin -a &&
git symbolic-ref refs/remotes/origin/HEAD > output &&
echo refs/remotes/origin/master > expect &&
test_cmp expect output
)
'

stop_httpd
test_done

0 comments on commit fbb074c

Please sign in to comment.