3 # Copyright (c) 2010 Erick Mattos
6 test_description='git checkout --orphan
8 Main Tests for --orphan functionality.'
14 test_expect_success 'Setup' '
15 echo "Initial" >"$TEST_FILE" &&
16 git add "$TEST_FILE" &&
17 git commit -m "First Commit"
19 echo "State 1" >>"$TEST_FILE" &&
20 git add "$TEST_FILE" &&
22 git commit -m "Second Commit"
25 test_expect_success '--orphan creates a new orphan branch from HEAD' '
26 git checkout --orphan alpha &&
27 test_must_fail git rev-parse --verify HEAD &&
28 test "refs/heads/alpha" = "$(git symbolic-ref HEAD)" &&
30 git commit -m "Third Commit" &&
31 test_must_fail git rev-parse --verify HEAD^ &&
32 git diff-tree --quiet master alpha
35 test_expect_success '--orphan creates a new orphan branch from <start_point>' '
36 git checkout master &&
37 git checkout --orphan beta master^ &&
38 test_must_fail git rev-parse --verify HEAD &&
39 test "refs/heads/beta" = "$(git symbolic-ref HEAD)" &&
41 git commit -m "Fourth Commit" &&
42 test_must_fail git rev-parse --verify HEAD^ &&
43 git diff-tree --quiet master^ beta
46 test_expect_success '--orphan must be rejected with -b' '
47 git checkout master &&
48 test_must_fail git checkout --orphan new -b newer &&
49 test refs/heads/master = "$(git symbolic-ref HEAD)"
52 test_expect_success '--orphan must be rejected with -t' '
53 git checkout master &&
54 test_must_fail git checkout --orphan new -t master &&
55 test refs/heads/master = "$(git symbolic-ref HEAD)"
58 test_expect_success '--orphan ignores branch.autosetupmerge' '
59 git checkout master &&
60 git config branch.autosetupmerge always &&
61 git checkout --orphan gamma &&
62 test -z "$(git config branch.gamma.merge)" &&
63 test refs/heads/gamma = "$(git symbolic-ref HEAD)" &&
64 test_must_fail git rev-parse --verify HEAD^
67 test_expect_success '--orphan makes reflog by default' '
68 git checkout master &&
69 git config --unset core.logAllRefUpdates &&
70 git checkout --orphan delta &&
71 ! test -f .git/logs/refs/heads/delta &&
75 test_must_fail git reflog show delta
77 git commit -m Delta &&
78 test -f .git/logs/refs/heads/delta &&
79 PAGER= git reflog show delta
82 test_expect_success '--orphan does not make reflog when core.logAllRefUpdates = false' '
83 git checkout master &&
84 git config core.logAllRefUpdates false &&
85 git checkout --orphan epsilon &&
86 ! test -f .git/logs/refs/heads/epsilon &&
90 test_must_fail git reflog show epsilon
92 git commit -m Epsilon &&
93 ! test -f .git/logs/refs/heads/epsilon &&
97 test_must_fail git reflog show epsilon
101 test_expect_success '--orphan with -l makes reflog when core.logAllRefUpdates = false' '
102 git checkout master &&
103 git checkout -l --orphan zeta &&
104 test -f .git/logs/refs/heads/zeta &&
108 test_must_fail git reflog show zeta
110 git commit -m Zeta &&
111 PAGER= git reflog show zeta
114 test_expect_success 'giving up --orphan not committed when -l and core.logAllRefUpdates = false deletes reflog' '
115 git checkout master &&
116 git checkout -l --orphan eta &&
117 test -f .git/logs/refs/heads/eta &&
121 test_must_fail git reflog show eta
123 git checkout master &&
124 ! test -f .git/logs/refs/heads/eta &&
128 test_must_fail git reflog show eta
132 test_expect_success '--orphan is rejected with an existing name' '
133 git checkout master &&
134 test_must_fail git checkout --orphan master &&
135 test refs/heads/master = "$(git symbolic-ref HEAD)"
138 test_expect_success '--orphan refuses to switch if a merge is needed' '
139 git checkout master &&
141 echo local >>"$TEST_FILE" &&
142 cat "$TEST_FILE" >"$TEST_FILE.saved" &&
143 test_must_fail git checkout --orphan new master^ &&
144 test refs/heads/master = "$(git symbolic-ref HEAD)" &&
145 test_cmp "$TEST_FILE" "$TEST_FILE.saved" &&
146 git diff-index --quiet --cached HEAD &&