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 <peff@peff.net> Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 27, 2009 at 14:10 UTC
fbb074c25352627f650d2ea528ed694e77bece0f
2 files changed
+19
remote.c
+8
@@ -1476,6 +1476,14 @@ struct ref *guess_remote_head(const struct ref *head,
1476
if (!head)
1477
return NULL;
1478
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
+
1487
/* If refs/heads/master could be right, it is. */
1488
if (!all) {
1489
r = find_ref_by_name(refs, "refs/heads/master");
t/t5550-http-fetch.sh
+11
@@ -42,5 +42,16 @@ test_expect_success 'fetch changes via http' '
42
test_cmp file clone/file
43
'
44
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
+
56
stop_httpd
57
test_done