Commit | Line | Data |
---|---|---|
323e00fd AJ |
1 | #!/bin/sh |
2 | ||
3 | test_description='checkout switching away from an invalid branch' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup' ' | |
8 | echo hello >world && | |
9 | git add world && | |
10 | git commit -m initial | |
11 | ' | |
12 | ||
3442ea4a JH |
13 | test_expect_success 'checkout should not start branch from a tree' ' |
14 | test_must_fail git checkout -b newbranch master^{tree} | |
15 | ' | |
16 | ||
323e00fd | 17 | test_expect_success 'checkout master from invalid HEAD' ' |
3749fde5 | 18 | echo $_z40 >.git/HEAD && |
323e00fd AJ |
19 | git checkout master -- |
20 | ' | |
21 | ||
4be49d75 JK |
22 | test_expect_success 'checkout notices failure to lock HEAD' ' |
23 | test_when_finished "rm -f .git/HEAD.lock" && | |
24 | >.git/HEAD.lock && | |
25 | test_must_fail git checkout -b other | |
26 | ' | |
27 | ||
2859dcd4 JK |
28 | test_expect_success 'create ref directory/file conflict scenario' ' |
29 | git update-ref refs/heads/outer/inner master && | |
30 | ||
31 | # do not rely on symbolic-ref to get a known state, | |
32 | # as it may use the same code we are testing | |
33 | reset_to_df () { | |
34 | echo "ref: refs/heads/outer" >.git/HEAD | |
35 | } | |
36 | ' | |
37 | ||
38 | test_expect_success 'checkout away from d/f HEAD (unpacked, to branch)' ' | |
39 | reset_to_df && | |
40 | git checkout master | |
41 | ' | |
42 | ||
43 | test_expect_success 'checkout away from d/f HEAD (unpacked, to detached)' ' | |
44 | reset_to_df && | |
45 | git checkout --detach master | |
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 master | |
55 | ' | |
56 | ||
57 | test_expect_success 'checkout away from d/f HEAD (packed, to detached)' ' | |
58 | reset_to_df && | |
59 | git checkout --detach master | |
60 | ' | |
323e00fd | 61 | test_done |