]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5610-clone-detached.sh
The third batch
[thirdparty/git.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_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
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
13 }
14
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
24 '
25
26 test_expect_success 'clone repo (detached HEAD points to branch)' '
27 git checkout main^0 &&
28 git clone "file://$PWD" detached-branch
29 '
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
34 '
35 test_expect_failure 'cloned HEAD is detached' '
36 head_is_detached detached-branch
37 '
38
39 test_expect_success 'clone repo (detached HEAD points to tag)' '
40 git checkout two^0 &&
41 git clone "file://$PWD" detached-tag
42 '
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
47 '
48 test_expect_success 'cloned HEAD is detached' '
49 head_is_detached detached-tag
50 '
51
52 test_expect_success 'clone repo (detached HEAD points to history)' '
53 git checkout two^ &&
54 git clone "file://$PWD" detached-history
55 '
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
60 '
61 test_expect_success 'cloned HEAD is detached' '
62 head_is_detached detached-history
63 '
64
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
70 '
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
75 '
76 test_expect_success 'cloned HEAD is detached' '
77 head_is_detached detached-orphan
78 '
79
80 test_done