git am: ignore dirty submodules
[git/mingw/4msysgit/kblees.git] / t / t2017-checkout-orphan.sh
blobbe88d4b5ee86b75eb0e5654404064f712192d0a9
1 #!/bin/sh
3 # Copyright (c) 2010 Erick Mattos
6 test_description='git checkout --orphan
8 Main Tests for --orphan functionality.'
10 . ./test-lib.sh
12 TEST_FILE=foo
14 test_expect_success 'Setup' '
15 echo "Initial" >"$TEST_FILE" &&
16 git add "$TEST_FILE" &&
17 git commit -m "First Commit"
18 test_tick &&
19 echo "State 1" >>"$TEST_FILE" &&
20 git add "$TEST_FILE" &&
21 test_tick &&
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)" &&
29 test_tick &&
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)" &&
40 test_tick &&
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 &&
72 test_must_fail PAGER= git reflog show delta &&
73 git commit -m Delta &&
74 test -f .git/logs/refs/heads/delta &&
75 PAGER= git reflog show delta
78 test_expect_success '--orphan does not make reflog when core.logAllRefUpdates = false' '
79 git checkout master &&
80 git config core.logAllRefUpdates false &&
81 git checkout --orphan epsilon &&
82 ! test -f .git/logs/refs/heads/epsilon &&
83 test_must_fail PAGER= git reflog show epsilon &&
84 git commit -m Epsilon &&
85 ! test -f .git/logs/refs/heads/epsilon &&
86 test_must_fail PAGER= git reflog show epsilon
89 test_expect_success '--orphan with -l makes reflog when core.logAllRefUpdates = false' '
90 git checkout master &&
91 git checkout -l --orphan zeta &&
92 test -f .git/logs/refs/heads/zeta &&
93 test_must_fail PAGER= git reflog show zeta &&
94 git commit -m Zeta &&
95 PAGER= git reflog show zeta
98 test_expect_success 'giving up --orphan not committed when -l and core.logAllRefUpdates = false deletes reflog' '
99 git checkout master &&
100 git checkout -l --orphan eta &&
101 test -f .git/logs/refs/heads/eta &&
102 test_must_fail PAGER= git reflog show eta &&
103 git checkout master &&
104 ! test -f .git/logs/refs/heads/eta &&
105 test_must_fail PAGER= git reflog show eta
108 test_expect_success '--orphan is rejected with an existing name' '
109 git checkout master &&
110 test_must_fail git checkout --orphan master &&
111 test refs/heads/master = "$(git symbolic-ref HEAD)"
114 test_expect_success '--orphan refuses to switch if a merge is needed' '
115 git checkout master &&
116 git reset --hard &&
117 echo local >>"$TEST_FILE" &&
118 cat "$TEST_FILE" >"$TEST_FILE.saved" &&
119 test_must_fail git checkout --orphan new master^ &&
120 test refs/heads/master = "$(git symbolic-ref HEAD)" &&
121 test_cmp "$TEST_FILE" "$TEST_FILE.saved" &&
122 git diff-index --quiet --cached HEAD &&
123 git reset --hard
126 test_done