submodule-config.h: remove unused SUBMODULE_INIT macro
[git/debian.git] / t / t2011-checkout-invalid-head.sh
blobe52022e152290b4e31ee837effc6e468c76f1eda
1 #!/bin/sh
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
8 . ./test-lib.sh
10 test_expect_success 'setup' '
11 echo hello >world &&
12 git add world &&
13 git commit -m initial
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 &&
22 git checkout main --
25 test_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
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
36 reset_to_df () {
37 echo "ref: refs/heads/outer" >.git/HEAD
41 test_expect_success 'checkout away from d/f HEAD (unpacked, to branch)' '
42 reset_to_df &&
43 git checkout main
46 test_expect_success 'checkout away from d/f HEAD (unpacked, to detached)' '
47 reset_to_df &&
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)' '
56 reset_to_df &&
57 git checkout main
60 test_expect_success 'checkout away from d/f HEAD (packed, to detached)' '
61 reset_to_df &&
62 git checkout --detach main
64 test_done