3 test_description
='test cloning a repository with detached HEAD'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
11 git
--git-dir=$1/.git rev-parse
--verify HEAD
&&
12 test_must_fail git
--git-dir=$1/.git symbolic-ref HEAD
15 test_expect_success
'setup' '
20 git commit -a -m two &&
23 git commit -a -m three
26 test_expect_success
'clone repo (detached HEAD points to branch)' '
27 git checkout main^0 &&
28 git clone "file://$PWD" detached-branch
30 test_expect_success
'cloned HEAD matches' '
32 git --git-dir=detached-branch/.git log -1 --format=%s >actual &&
33 test_cmp expect actual
35 test_expect_failure
'cloned HEAD is detached' '
36 head_is_detached detached-branch
39 test_expect_success
'clone repo (detached HEAD points to tag)' '
41 git clone "file://$PWD" detached-tag
43 test_expect_success
'cloned HEAD matches' '
45 git --git-dir=detached-tag/.git log -1 --format=%s >actual &&
46 test_cmp expect actual
48 test_expect_success
'cloned HEAD is detached' '
49 head_is_detached detached-tag
52 test_expect_success
'clone repo (detached HEAD points to history)' '
54 git clone "file://$PWD" detached-history
56 test_expect_success
'cloned HEAD matches' '
58 git --git-dir=detached-history/.git log -1 --format=%s >actual &&
59 test_cmp expect actual
61 test_expect_success
'cloned HEAD is detached' '
62 head_is_detached detached-history
65 test_expect_success
'clone repo (orphan detached HEAD)' '
66 git checkout main^0 &&
68 git commit -a -m four &&
69 git clone "file://$PWD" detached-orphan
71 test_expect_success
'cloned HEAD matches' '
73 git --git-dir=detached-orphan/.git log -1 --format=%s >actual &&
74 test_cmp expect actual
76 test_expect_success
'cloned HEAD is detached' '
77 head_is_detached detached-orphan