]>
Commit | Line | Data |
---|---|---|
323e00fd AJ |
1 | #!/bin/sh |
2 | ||
3 | test_description='checkout switching away from an invalid branch' | |
4 | ||
883b98ef | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
9081a421 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
323e00fd AJ |
9 | . ./test-lib.sh |
10 | ||
11 | test_expect_success 'setup' ' | |
12 | echo hello >world && | |
13 | git add world && | |
14 | git commit -m initial | |
15 | ' | |
16 | ||
3442ea4a | 17 | test_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 | ||
a6f43364 | 21 | test_expect_success REFFILES 'checkout main from invalid HEAD' ' |
8125a58b | 22 | echo $ZERO_OID >.git/HEAD && |
883b98ef | 23 | git checkout main -- |
323e00fd AJ |
24 | ' |
25 | ||
a6f43364 | 26 | test_expect_success REFFILES 'checkout notices failure to lock HEAD' ' |
4be49d75 JK |
27 | test_when_finished "rm -f .git/HEAD.lock" && |
28 | >.git/HEAD.lock && | |
29 | test_must_fail git checkout -b other | |
30 | ' | |
31 | ||
f85a032c | 32 | test_expect_success 'create ref directory/file conflict scenario' ' |
883b98ef | 33 | git update-ref refs/heads/outer/inner main && |
2859dcd4 | 34 | reset_to_df () { |
f85a032c | 35 | git symbolic-ref HEAD refs/heads/outer |
2859dcd4 JK |
36 | } |
37 | ' | |
38 | ||
f85a032c | 39 | test_expect_success 'checkout away from d/f HEAD (unpacked, to branch)' ' |
2859dcd4 | 40 | reset_to_df && |
883b98ef | 41 | git checkout main |
2859dcd4 JK |
42 | ' |
43 | ||
f85a032c | 44 | test_expect_success 'checkout away from d/f HEAD (unpacked, to detached)' ' |
2859dcd4 | 45 | reset_to_df && |
883b98ef | 46 | git checkout --detach main |
2859dcd4 JK |
47 | ' |
48 | ||
f85a032c | 49 | test_expect_success 'pack refs' ' |
2859dcd4 JK |
50 | git pack-refs --all --prune |
51 | ' | |
52 | ||
f85a032c | 53 | test_expect_success 'checkout away from d/f HEAD (packed, to branch)' ' |
2859dcd4 | 54 | reset_to_df && |
883b98ef | 55 | git checkout main |
2859dcd4 JK |
56 | ' |
57 | ||
f85a032c | 58 | test_expect_success 'checkout away from d/f HEAD (packed, to detached)' ' |
2859dcd4 | 59 | reset_to_df && |
883b98ef | 60 | git checkout --detach main |
2859dcd4 | 61 | ' |
323e00fd | 62 | test_done |