]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5610-clone-detached.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t5610-clone-detached.sh
CommitLineData
3b368546
JK
1#!/bin/sh
2
3test_description='test cloning a repository with detached HEAD'
95cf2c01 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
dd4143e7 7TEST_PASSES_SANITIZE_LEAK=true
3b368546
JK
8. ./test-lib.sh
9
10head_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
15test_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
26test_expect_success 'clone repo (detached HEAD points to branch)' '
95cf2c01 27 git checkout main^0 &&
3b368546
JK
28 git clone "file://$PWD" detached-branch
29'
30test_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'
35test_expect_failure 'cloned HEAD is detached' '
36 head_is_detached detached-branch
37'
38
39test_expect_success 'clone repo (detached HEAD points to tag)' '
40 git checkout two^0 &&
41 git clone "file://$PWD" detached-tag
42'
43test_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'
61adfd30 48test_expect_success 'cloned HEAD is detached' '
3b368546
JK
49 head_is_detached detached-tag
50'
51
52test_expect_success 'clone repo (detached HEAD points to history)' '
53 git checkout two^ &&
54 git clone "file://$PWD" detached-history
55'
56test_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'
61test_expect_success 'cloned HEAD is detached' '
62 head_is_detached detached-history
63'
64
c1921c18 65test_expect_success 'clone repo (orphan detached HEAD)' '
95cf2c01 66 git checkout main^0 &&
3b368546
JK
67 echo four >file &&
68 git commit -a -m four &&
69 git clone "file://$PWD" detached-orphan
70'
c1921c18 71test_expect_success 'cloned HEAD matches' '
3b368546
JK
72 echo four >expect &&
73 git --git-dir=detached-orphan/.git log -1 --format=%s >actual &&
74 test_cmp expect actual
75'
c1921c18 76test_expect_success 'cloned HEAD is detached' '
3b368546
JK
77 head_is_detached detached-orphan
78'
79
80test_done