Skip to content

Commit

Permalink
clone: write detached HEAD in bare repositories
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Jan 17, 2012
1 parent bafe763 commit 7f08c68
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
9 changes: 3 additions & 6 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
}
} else if (remote_head) {
/* Source had detached HEAD pointing somewhere. */
if (!option_bare) {
update_ref(reflog_msg.buf, "HEAD",
remote_head->old_sha1,
NULL, REF_NODEREF, DIE_ON_ERR);
our_head_points_at = remote_head;
}
update_ref(reflog_msg.buf, "HEAD", remote_head->old_sha1,
NULL, REF_NODEREF, DIE_ON_ERR);
our_head_points_at = remote_head;
} else {
/* Nothing to checkout out */
if (!option_no_checkout)
Expand Down
25 changes: 24 additions & 1 deletion t/t5601-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ test_expect_success setup '
cd src &&
>file &&
git add file &&
git commit -m initial
git commit -m initial &&
echo 1 >file &&
git add file &&
git commit -m updated
)
'
Expand Down Expand Up @@ -88,6 +91,26 @@ test_expect_success 'clone --mirror' '
'

test_expect_success 'clone --mirror with detached HEAD' '
( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
git clone --mirror src mirror.detached &&
( cd src && git checkout - ) &&
GIT_DIR=mirror.detached git rev-parse HEAD >actual &&
test_cmp expected actual
'

test_expect_success 'clone --bare with detached HEAD' '
( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
git clone --bare src bare.detached &&
( cd src && git checkout - ) &&
GIT_DIR=bare.detached git rev-parse HEAD >actual &&
test_cmp expected actual
'

test_expect_success 'clone --bare names the local repository <name>.git' '
git clone --bare src &&
Expand Down

0 comments on commit 7f08c68

Please sign in to comment.