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
10 git --git-dir=$1/.git rev-parse --verify HEAD &&
11 test_must_fail git --git-dir=$1/.git symbolic-ref HEAD
14 test_expect_success 'setup' '
19 git commit -a -m two &&
22 git commit -a -m three
25 test_expect_success 'clone repo (detached HEAD points to branch)' '
26 git checkout main^0 &&
27 git clone "file://$PWD" detached-branch
29 test_expect_success 'cloned HEAD matches' '
31 git --git-dir=detached-branch/.git log -1 --format=%s >actual &&
32 test_cmp expect actual
34 test_expect_failure 'cloned HEAD is detached' '
35 head_is_detached detached-branch
38 test_expect_success 'clone repo (detached HEAD points to tag)' '
40 git clone "file://$PWD" detached-tag
42 test_expect_success 'cloned HEAD matches' '
44 git --git-dir=detached-tag/.git log -1 --format=%s >actual &&
45 test_cmp expect actual
47 test_expect_success 'cloned HEAD is detached' '
48 head_is_detached detached-tag
51 test_expect_success 'clone repo (detached HEAD points to history)' '
53 git clone "file://$PWD" detached-history
55 test_expect_success 'cloned HEAD matches' '
57 git --git-dir=detached-history/.git log -1 --format=%s >actual &&
58 test_cmp expect actual
60 test_expect_success 'cloned HEAD is detached' '
61 head_is_detached detached-history
64 test_expect_success 'clone repo (orphan detached HEAD)' '
65 git checkout main^0 &&
67 git commit -a -m four &&
68 git clone "file://$PWD" detached-orphan
70 test_expect_success 'cloned HEAD matches' '
72 git --git-dir=detached-orphan/.git log -1 --format=%s >actual &&
73 test_cmp expect actual
75 test_expect_success 'cloned HEAD is detached' '
76 head_is_detached detached-orphan