]>
Commit | Line | Data |
---|---|---|
9db5ebf4 EM |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010 Erick Mattos | |
4 | # | |
5 | ||
6 | test_description='git checkout --orphan | |
7 | ||
8 | Main Tests for --orphan functionality.' | |
9 | ||
883b98ef | 10 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
11 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
12 | ||
9db5ebf4 EM |
13 | . ./test-lib.sh |
14 | ||
15 | TEST_FILE=foo | |
16 | ||
17 | test_expect_success 'Setup' ' | |
18 | echo "Initial" >"$TEST_FILE" && | |
19 | git add "$TEST_FILE" && | |
a48fcd83 | 20 | git commit -m "First Commit" && |
9db5ebf4 EM |
21 | test_tick && |
22 | echo "State 1" >>"$TEST_FILE" && | |
23 | git add "$TEST_FILE" && | |
24 | test_tick && | |
25 | git commit -m "Second Commit" | |
26 | ' | |
27 | ||
28 | test_expect_success '--orphan creates a new orphan branch from HEAD' ' | |
29 | git checkout --orphan alpha && | |
30 | test_must_fail git rev-parse --verify HEAD && | |
31 | test "refs/heads/alpha" = "$(git symbolic-ref HEAD)" && | |
32 | test_tick && | |
33 | git commit -m "Third Commit" && | |
34 | test_must_fail git rev-parse --verify HEAD^ && | |
883b98ef | 35 | git diff-tree --quiet main alpha |
9db5ebf4 EM |
36 | ' |
37 | ||
38 | test_expect_success '--orphan creates a new orphan branch from <start_point>' ' | |
883b98ef JS |
39 | git checkout main && |
40 | git checkout --orphan beta main^ && | |
9db5ebf4 EM |
41 | test_must_fail git rev-parse --verify HEAD && |
42 | test "refs/heads/beta" = "$(git symbolic-ref HEAD)" && | |
43 | test_tick && | |
44 | git commit -m "Fourth Commit" && | |
45 | test_must_fail git rev-parse --verify HEAD^ && | |
883b98ef | 46 | git diff-tree --quiet main^ beta |
9db5ebf4 EM |
47 | ' |
48 | ||
49 | test_expect_success '--orphan must be rejected with -b' ' | |
883b98ef | 50 | git checkout main && |
9db5ebf4 | 51 | test_must_fail git checkout --orphan new -b newer && |
883b98ef | 52 | test refs/heads/main = "$(git symbolic-ref HEAD)" |
9db5ebf4 EM |
53 | ' |
54 | ||
3631bf77 | 55 | test_expect_success '--orphan must be rejected with -t' ' |
883b98ef JS |
56 | git checkout main && |
57 | test_must_fail git checkout --orphan new -t main && | |
58 | test refs/heads/main = "$(git symbolic-ref HEAD)" | |
3631bf77 EM |
59 | ' |
60 | ||
61 | test_expect_success '--orphan ignores branch.autosetupmerge' ' | |
883b98ef | 62 | git checkout main && |
3631bf77 EM |
63 | git config branch.autosetupmerge always && |
64 | git checkout --orphan gamma && | |
65 | test -z "$(git config branch.gamma.merge)" && | |
66 | test refs/heads/gamma = "$(git symbolic-ref HEAD)" && | |
67 | test_must_fail git rev-parse --verify HEAD^ | |
68 | ' | |
69 | ||
70 | test_expect_success '--orphan makes reflog by default' ' | |
883b98ef | 71 | git checkout main && |
3631bf77 EM |
72 | git config --unset core.logAllRefUpdates && |
73 | git checkout --orphan delta && | |
6e6842e3 | 74 | test_must_fail git rev-parse --verify delta@{0} && |
3631bf77 | 75 | git commit -m Delta && |
6e6842e3 | 76 | git rev-parse --verify delta@{0} |
3631bf77 EM |
77 | ' |
78 | ||
a5709636 | 79 | test_expect_success REFFILES '--orphan does not make reflog when core.logAllRefUpdates = false' ' |
883b98ef | 80 | git checkout main && |
3631bf77 EM |
81 | git config core.logAllRefUpdates false && |
82 | git checkout --orphan epsilon && | |
6e6842e3 | 83 | test_must_fail git rev-parse --verify epsilon@{0} && |
3631bf77 | 84 | git commit -m Epsilon && |
6e6842e3 | 85 | test_must_fail git rev-parse --verify epsilon@{0} |
3631bf77 EM |
86 | ' |
87 | ||
88 | test_expect_success '--orphan with -l makes reflog when core.logAllRefUpdates = false' ' | |
883b98ef | 89 | git checkout main && |
3631bf77 | 90 | git checkout -l --orphan zeta && |
6e6842e3 | 91 | test_must_fail git rev-parse --verify zeta@{0} && |
3631bf77 | 92 | git commit -m Zeta && |
6e6842e3 | 93 | git rev-parse --verify zeta@{0} |
3631bf77 EM |
94 | ' |
95 | ||
96 | test_expect_success 'giving up --orphan not committed when -l and core.logAllRefUpdates = false deletes reflog' ' | |
883b98ef | 97 | git checkout main && |
3631bf77 | 98 | git checkout -l --orphan eta && |
6e6842e3 | 99 | test_must_fail git rev-parse --verify eta@{0} && |
883b98ef | 100 | git checkout main && |
6e6842e3 | 101 | test_must_fail git rev-parse --verify eta@{0} |
3631bf77 EM |
102 | ' |
103 | ||
9db5ebf4 | 104 | test_expect_success '--orphan is rejected with an existing name' ' |
883b98ef JS |
105 | git checkout main && |
106 | test_must_fail git checkout --orphan main && | |
107 | test refs/heads/main = "$(git symbolic-ref HEAD)" | |
9db5ebf4 EM |
108 | ' |
109 | ||
110 | test_expect_success '--orphan refuses to switch if a merge is needed' ' | |
883b98ef | 111 | git checkout main && |
9db5ebf4 EM |
112 | git reset --hard && |
113 | echo local >>"$TEST_FILE" && | |
114 | cat "$TEST_FILE" >"$TEST_FILE.saved" && | |
883b98ef JS |
115 | test_must_fail git checkout --orphan new main^ && |
116 | test refs/heads/main = "$(git symbolic-ref HEAD)" && | |
9db5ebf4 EM |
117 | test_cmp "$TEST_FILE" "$TEST_FILE.saved" && |
118 | git diff-index --quiet --cached HEAD && | |
119 | git reset --hard | |
120 | ' | |
121 | ||
8ced1aa0 | 122 | test_expect_success 'cannot --detach on an unborn branch' ' |
883b98ef | 123 | git checkout main && |
8ced1aa0 CW |
124 | git checkout --orphan new && |
125 | test_must_fail git checkout --detach | |
126 | ' | |
127 | ||
9db5ebf4 | 128 | test_done |