Skip to content

Commit fbb074c

Browse files
peffgitster
authored andcommitted
remote: make guess_remote_head() use exact HEAD lookup if it is available
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 <[email protected]> Signed-off-by: Jay Soffian <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc14fac commit fbb074c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

remote.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,14 @@ struct ref *guess_remote_head(const struct ref *head,
14761476
if (!head)
14771477
return NULL;
14781478

1479+
/*
1480+
* Some transports support directly peeking at
1481+
* where HEAD points; if that is the case, then
1482+
* we don't have to guess.
1483+
*/
1484+
if (head->symref)
1485+
return copy_ref(find_ref_by_name(refs, head->symref));
1486+
14791487
/* If refs/heads/master could be right, it is. */
14801488
if (!all) {
14811489
r = find_ref_by_name(refs, "refs/heads/master");

t/t5550-http-fetch.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,16 @@ test_expect_success 'fetch changes via http' '
4242
test_cmp file clone/file
4343
'
4444

45+
test_expect_success 'http remote detects correct HEAD' '
46+
git push public master:other &&
47+
(cd clone &&
48+
git remote set-head origin -d &&
49+
git remote set-head origin -a &&
50+
git symbolic-ref refs/remotes/origin/HEAD > output &&
51+
echo refs/remotes/origin/master > expect &&
52+
test_cmp expect output
53+
)
54+
'
55+
4556
stop_httpd
4657
test_done

0 commit comments

Comments
 (0)