3 test_description='checkout switching away from an invalid branch'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success 'setup' '
16 test_expect_success 'checkout should not start branch from a tree' '
17 test_must_fail git checkout -b newbranch main^{tree}
20 test_expect_success 'checkout main from invalid HEAD' '
21 echo $ZERO_OID >.git/HEAD &&
25 test_expect_success 'checkout notices failure to lock HEAD' '
26 test_when_finished "rm -f .git/HEAD.lock" &&
28 test_must_fail git checkout -b other
31 test_expect_success 'create ref directory/file conflict scenario' '
32 git update-ref refs/heads/outer/inner main &&
34 # do not rely on symbolic-ref to get a known state,
35 # as it may use the same code we are testing
37 echo "ref: refs/heads/outer" >.git/HEAD
41 test_expect_success 'checkout away from d/f HEAD (unpacked, to branch)' '
46 test_expect_success 'checkout away from d/f HEAD (unpacked, to detached)' '
48 git checkout --detach main
51 test_expect_success 'pack refs' '
52 git pack-refs --all --prune
55 test_expect_success 'checkout away from d/f HEAD (packed, to branch)' '
60 test_expect_success 'checkout away from d/f HEAD (packed, to detached)' '
62 git checkout --detach main