]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2011-checkout-invalid-head.sh
Sync with 2.36.3
[thirdparty/git.git] / t / t2011-checkout-invalid-head.sh
CommitLineData
323e00fd
AJ
1#!/bin/sh
2
3test_description='checkout switching away from an invalid branch'
4
883b98ef 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
9081a421 8TEST_PASSES_SANITIZE_LEAK=true
323e00fd
AJ
9. ./test-lib.sh
10
11test_expect_success 'setup' '
12 echo hello >world &&
13 git add world &&
14 git commit -m initial
15'
16
3442ea4a 17test_expect_success 'checkout should not start branch from a tree' '
883b98ef 18 test_must_fail git checkout -b newbranch main^{tree}
3442ea4a
JH
19'
20
883b98ef 21test_expect_success 'checkout main from invalid HEAD' '
8125a58b 22 echo $ZERO_OID >.git/HEAD &&
883b98ef 23 git checkout main --
323e00fd
AJ
24'
25
4be49d75
JK
26test_expect_success 'checkout notices failure to lock HEAD' '
27 test_when_finished "rm -f .git/HEAD.lock" &&
28 >.git/HEAD.lock &&
29 test_must_fail git checkout -b other
30'
31
2859dcd4 32test_expect_success 'create ref directory/file conflict scenario' '
883b98ef 33 git update-ref refs/heads/outer/inner main &&
2859dcd4
JK
34
35 # do not rely on symbolic-ref to get a known state,
36 # as it may use the same code we are testing
37 reset_to_df () {
38 echo "ref: refs/heads/outer" >.git/HEAD
39 }
40'
41
42test_expect_success 'checkout away from d/f HEAD (unpacked, to branch)' '
43 reset_to_df &&
883b98ef 44 git checkout main
2859dcd4
JK
45'
46
47test_expect_success 'checkout away from d/f HEAD (unpacked, to detached)' '
48 reset_to_df &&
883b98ef 49 git checkout --detach main
2859dcd4
JK
50'
51
52test_expect_success 'pack refs' '
53 git pack-refs --all --prune
54'
55
56test_expect_success 'checkout away from d/f HEAD (packed, to branch)' '
57 reset_to_df &&
883b98ef 58 git checkout main
2859dcd4
JK
59'
60
61test_expect_success 'checkout away from d/f HEAD (packed, to detached)' '
62 reset_to_df &&
883b98ef 63 git checkout --detach main
2859dcd4 64'
323e00fd 65test_done