init: remove git_init_db_config() while fixing leaks
[git/debian.git] / t / t5610-clone-detached.sh
bloba7ec21eda5aabf16144f79a7f348e6f6be9b7507
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-lib.sh
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
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
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' '
30 echo three >expect &&
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)' '
39 git checkout two^0 &&
40 git clone "file://$PWD" detached-tag
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
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)' '
52 git checkout two^ &&
53 git clone "file://$PWD" detached-history
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
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 &&
66 echo four >file &&
67 git commit -a -m four &&
68 git clone "file://$PWD" detached-orphan
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
75 test_expect_success 'cloned HEAD is detached' '
76 head_is_detached detached-orphan
79 test_done