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