builtin/gc.c: ignore cruft packs with `--keep-largest-pack`
[alt-git.git] / t / t2011-checkout-invalid-head.sh
blobd9997e7b6b41a19537eed0bd512be1e8c78dc3d6
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success 'setup' '
12 echo hello >world &&
13 git add world &&
14 git commit -m initial
17 test_expect_success 'checkout should not start branch from a tree' '
18 test_must_fail git checkout -b newbranch main^{tree}
21 test_expect_success 'checkout main from invalid HEAD' '
22 echo $ZERO_OID >.git/HEAD &&
23 git checkout main --
26 test_expect_success 'checkout notices failure to lock HEAD' '
27 test_when_finished "rm -f .git/HEAD.lock" &&
28 >.git/HEAD.lock &&
29 test_must_fail git checkout -b other
32 test_expect_success 'create ref directory/file conflict scenario' '
33 git update-ref refs/heads/outer/inner main &&
35 # do not rely on symbolic-ref to get a known state,
36 # as it may use the same code we are testing
37 reset_to_df () {
38 echo "ref: refs/heads/outer" >.git/HEAD
42 test_expect_success 'checkout away from d/f HEAD (unpacked, to branch)' '
43 reset_to_df &&
44 git checkout main
47 test_expect_success 'checkout away from d/f HEAD (unpacked, to detached)' '
48 reset_to_df &&
49 git checkout --detach main
52 test_expect_success 'pack refs' '
53 git pack-refs --all --prune
56 test_expect_success 'checkout away from d/f HEAD (packed, to branch)' '
57 reset_to_df &&
58 git checkout main
61 test_expect_success 'checkout away from d/f HEAD (packed, to detached)' '
62 reset_to_df &&
63 git checkout --detach main
65 test_done