The second batch
[git] / t / t5610-clone-detached.sh
1 #!/bin/sh
2
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
6
7 . ./test-lib.sh
8
9 head_is_detached() {
10         git --git-dir=$1/.git rev-parse --verify HEAD &&
11         test_must_fail git --git-dir=$1/.git symbolic-ref HEAD
12 }
13
14 test_expect_success 'setup' '
15         echo one >file &&
16         git add file &&
17         git commit -m one &&
18         echo two >file &&
19         git commit -a -m two &&
20         git tag two &&
21         echo three >file &&
22         git commit -a -m three
23 '
24
25 test_expect_success 'clone repo (detached HEAD points to branch)' '
26         git checkout main^0 &&
27         git clone "file://$PWD" detached-branch
28 '
29 test_expect_success 'cloned HEAD matches' '
30         echo three >expect &&
31         git --git-dir=detached-branch/.git log -1 --format=%s >actual &&
32         test_cmp expect actual
33 '
34 test_expect_failure 'cloned HEAD is detached' '
35         head_is_detached detached-branch
36 '
37
38 test_expect_success 'clone repo (detached HEAD points to tag)' '
39         git checkout two^0 &&
40         git clone "file://$PWD" detached-tag
41 '
42 test_expect_success 'cloned HEAD matches' '
43         echo two >expect &&
44         git --git-dir=detached-tag/.git log -1 --format=%s >actual &&
45         test_cmp expect actual
46 '
47 test_expect_success 'cloned HEAD is detached' '
48         head_is_detached detached-tag
49 '
50
51 test_expect_success 'clone repo (detached HEAD points to history)' '
52         git checkout two^ &&
53         git clone "file://$PWD" detached-history
54 '
55 test_expect_success 'cloned HEAD matches' '
56         echo one >expect &&
57         git --git-dir=detached-history/.git log -1 --format=%s >actual &&
58         test_cmp expect actual
59 '
60 test_expect_success 'cloned HEAD is detached' '
61         head_is_detached detached-history
62 '
63
64 test_expect_success 'clone repo (orphan detached HEAD)' '
65         git checkout main^0 &&
66         echo four >file &&
67         git commit -a -m four &&
68         git clone "file://$PWD" detached-orphan
69 '
70 test_expect_success 'cloned HEAD matches' '
71         echo four >expect &&
72         git --git-dir=detached-orphan/.git log -1 --format=%s >actual &&
73         test_cmp expect actual
74 '
75 test_expect_success 'cloned HEAD is detached' '
76         head_is_detached detached-orphan
77 '
78
79 test_done