commit-graph: factor out chain opening function
[git.git] / t / t5610-clone-detached.sh
blob022ed3d87c37159f758b349f6604b781a29b9327
1 #!/bin/sh
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
8 . ./test-lib.sh
10 head_is_detached() {
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' '
16 echo one >file &&
17 git add file &&
18 git commit -m one &&
19 echo two >file &&
20 git commit -a -m two &&
21 git tag two &&
22 echo three >file &&
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' '
31 echo three >expect &&
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)' '
40 git checkout two^0 &&
41 git clone "file://$PWD" detached-tag
43 test_expect_success 'cloned HEAD matches' '
44 echo two >expect &&
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)' '
53 git checkout two^ &&
54 git clone "file://$PWD" detached-history
56 test_expect_success 'cloned HEAD matches' '
57 echo one >expect &&
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 &&
67 echo four >file &&
68 git commit -a -m four &&
69 git clone "file://$PWD" detached-orphan
71 test_expect_success 'cloned HEAD matches' '
72 echo four >expect &&
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
80 test_done