clone: write detached HEAD in bare repositories
If we don't write, HEAD is still at refs/heads/master as initialized by init-db, which may or may not match remote's HEAD. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jan 16, 2012 at 16:46 UTC
7f08c6858ecfdf29f9713cf3a0b3699192f01a94
2 files changed
+27
-7
builtin/clone.c
+3
-6
@@ -764,12 +764,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
764
}
765
} else if (remote_head) {
766
/* Source had detached HEAD pointing somewhere. */
767
- if (!option_bare) {
768
- update_ref(reflog_msg.buf, "HEAD",
769
- remote_head->old_sha1,
770
- NULL, REF_NODEREF, DIE_ON_ERR);
771
- our_head_points_at = remote_head;
772
- }
767
+ update_ref(reflog_msg.buf, "HEAD", remote_head->old_sha1,
768
+ NULL, REF_NODEREF, DIE_ON_ERR);
769
+ our_head_points_at = remote_head;
770
} else {
771
/* Nothing to checkout out */
772
if (!option_no_checkout)
t/t5601-clone.sh
+24
-1
@@ -12,7 +12,10 @@ test_expect_success setup '
12
cd src &&
13
>file &&
14
git add file &&
15
- git commit -m initial
15
+ git commit -m initial &&
16
+ echo 1 >file &&
17
+ git add file &&
18
+ git commit -m updated
19
)
20
21
'
@@ -88,6 +91,26 @@ test_expect_success 'clone --mirror' '
91
92
'
93
94
+test_expect_success 'clone --mirror with detached HEAD' '
95
+
96
+ ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
97
+ git clone --mirror src mirror.detached &&
98
+ ( cd src && git checkout - ) &&
99
+ GIT_DIR=mirror.detached git rev-parse HEAD >actual &&
100
+ test_cmp expected actual
101
+
102
+'
103
+
104
+test_expect_success 'clone --bare with detached HEAD' '
105
+
106
+ ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
107
+ git clone --bare src bare.detached &&
108
+ ( cd src && git checkout - ) &&
109
+ GIT_DIR=bare.detached git rev-parse HEAD >actual &&
110
+ test_cmp expected actual
111
+
112
+'
113
+
114
test_expect_success 'clone --bare names the local repository <name>.git' '
115
116
git clone --bare src &&