Git 1.7.2.5
[git/jnareb-git/bp-gitweb.git] / t / t2017-checkout-orphan.sh
blob2d2f63f22ee59d8dc24dafaa5224928ad62dea0c
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_must_fail git rev-parse --verify delta@{0} &&
72 git commit -m Delta &&
73 git rev-parse --verify delta@{0}
76 test_expect_success '--orphan does not make reflog when core.logAllRefUpdates = false' '
77 git checkout master &&
78 git config core.logAllRefUpdates false &&
79 git checkout --orphan epsilon &&
80 test_must_fail git rev-parse --verify epsilon@{0} &&
81 git commit -m Epsilon &&
82 test_must_fail git rev-parse --verify epsilon@{0}
85 test_expect_success '--orphan with -l makes reflog when core.logAllRefUpdates = false' '
86 git checkout master &&
87 git checkout -l --orphan zeta &&
88 test_must_fail git rev-parse --verify zeta@{0} &&
89 git commit -m Zeta &&
90 git rev-parse --verify zeta@{0}
93 test_expect_success 'giving up --orphan not committed when -l and core.logAllRefUpdates = false deletes reflog' '
94 git checkout master &&
95 git checkout -l --orphan eta &&
96 test_must_fail git rev-parse --verify eta@{0} &&
97 git checkout master &&
98 test_must_fail git rev-parse --verify eta@{0}
101 test_expect_success '--orphan is rejected with an existing name' '
102 git checkout master &&
103 test_must_fail git checkout --orphan master &&
104 test refs/heads/master = "$(git symbolic-ref HEAD)"
107 test_expect_success '--orphan refuses to switch if a merge is needed' '
108 git checkout master &&
109 git reset --hard &&
110 echo local >>"$TEST_FILE" &&
111 cat "$TEST_FILE" >"$TEST_FILE.saved" &&
112 test_must_fail git checkout --orphan new master^ &&
113 test refs/heads/master = "$(git symbolic-ref HEAD)" &&
114 test_cmp "$TEST_FILE" "$TEST_FILE.saved" &&
115 git diff-index --quiet --cached HEAD &&
116 git reset --hard
119 test_done