| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='checkout switching away from an invalid branch' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success 'setup' ' |
| 11 | echo hello >world && |
| 12 | git add world && |
| 13 | git commit -m initial |
| 14 | ' |
| 15 | |
| 16 | test_expect_success 'checkout should not start branch from a tree' ' |
| 17 | test_must_fail git checkout -b newbranch main^{tree} |
| 18 | ' |
| 19 | |
| 20 | test_expect_success REFFILES 'checkout main from invalid HEAD' ' |
| 21 | echo $ZERO_OID >.git/HEAD && |
| 22 | git checkout main -- |
| 23 | ' |
| 24 | |
| 25 | test_expect_success REFFILES '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 | |
| 31 | test_expect_success 'create ref directory/file conflict scenario' ' |
| 32 | git update-ref refs/heads/outer/inner main && |
| 33 | reset_to_df () { |
| 34 | git symbolic-ref HEAD refs/heads/outer |
| 35 | } |
| 36 | ' |
| 37 | |
| 38 | test_expect_success 'checkout away from d/f HEAD (unpacked, to branch)' ' |
| 39 | reset_to_df && |
| 40 | git checkout main |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'checkout away from d/f HEAD (unpacked, to detached)' ' |
| 44 | reset_to_df && |
| 45 | git checkout --detach main |
| 46 | ' |
| 47 | |
| 48 | test_expect_success 'pack refs' ' |
| 49 | git pack-refs --all --prune |
| 50 | ' |
| 51 | |
| 52 | test_expect_success 'checkout away from d/f HEAD (packed, to branch)' ' |
| 53 | reset_to_df && |
| 54 | git checkout main |
| 55 | ' |
| 56 | |
| 57 | test_expect_success 'checkout away from d/f HEAD (packed, to detached)' ' |
| 58 | reset_to_df && |
| 59 | git checkout --detach main |
| 60 | ' |
| 61 | test_done |