Merge branch 'maint'
[git/fastimport.git] / t / t7201-co.sh
blob5fa6a45577894e05446351fc5076a27accb1fa9f
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='git-checkout tests.
8 Creates master, forks renamer and side branches from it.
9 Test switching across them.
11 ! [master] Initial A one, A two
12 * [renamer] Renamer R one->uno, M two
13 ! [side] Side M one, D two, A three
14 ---
15 + [side] Side M one, D two, A three
16 * [renamer] Renamer R one->uno, M two
17 +*+ [master] Initial A one, A two
21 . ./test-lib.sh
23 fill () {
24 for i
26 echo "$i"
27 done
31 test_expect_success setup '
33 fill 1 2 3 4 5 6 7 8 >one &&
34 fill a b c d e >two &&
35 git add one two &&
36 git commit -m "Initial A one, A two" &&
38 git checkout -b renamer &&
39 rm -f one &&
40 fill 1 3 4 5 6 7 8 >uno &&
41 git add uno &&
42 fill a b c d e f >two &&
43 git commit -a -m "Renamer R one->uno, M two" &&
45 git checkout -b side master &&
46 fill 1 2 3 4 5 6 7 >one &&
47 fill A B C D E >three &&
48 rm -f two &&
49 git update-index --add --remove one two three &&
50 git commit -m "Side M one, D two, A three" &&
52 git checkout master
55 test_expect_success "checkout from non-existing branch" '
57 git checkout -b delete-me master &&
58 rm .git/refs/heads/delete-me &&
59 test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
60 git checkout master &&
61 test refs/heads/master = "$(git symbolic-ref HEAD)"
64 test_expect_success "checkout with dirty tree without -m" '
66 fill 0 1 2 3 4 5 6 7 8 >one &&
67 if git checkout side
68 then
69 echo Not happy
70 false
71 else
72 echo "happy - failed correctly"
77 test_expect_success "checkout -m with dirty tree" '
79 git checkout -f master &&
80 git clean &&
82 fill 0 1 2 3 4 5 6 7 8 >one &&
83 git checkout -m side &&
85 test "$(git symbolic-ref HEAD)" = "refs/heads/side" &&
87 fill "M one" "A three" "D two" >expect.master &&
88 git diff --name-status master >current.master &&
89 diff expect.master current.master &&
91 fill "M one" >expect.side &&
92 git diff --name-status side >current.side &&
93 diff expect.side current.side &&
95 : >expect.index &&
96 git diff --cached >current.index &&
97 diff expect.index current.index
100 test_expect_success "checkout -m with dirty tree, renamed" '
102 git checkout -f master && git clean &&
104 fill 1 2 3 4 5 7 8 >one &&
105 if git checkout renamer
106 then
107 echo Not happy
108 false
109 else
110 echo "happy - failed correctly"
111 fi &&
113 git checkout -m renamer &&
114 fill 1 3 4 5 7 8 >expect &&
115 diff expect uno &&
116 ! test -f one &&
117 git diff --cached >current &&
118 ! test -s current
122 test_expect_success 'checkout -m with merge conflict' '
124 git checkout -f master && git clean &&
126 fill 1 T 3 4 5 6 S 8 >one &&
127 if git checkout renamer
128 then
129 echo Not happy
130 false
131 else
132 echo "happy - failed correctly"
133 fi &&
135 git checkout -m renamer &&
137 git diff master:one :3:uno |
138 sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current &&
139 fill d2 aT d7 aS >expect &&
140 diff current expect &&
141 git diff --cached two >current &&
142 ! test -s current
145 test_expect_success 'checkout to detach HEAD' '
147 git checkout -f renamer && git clean &&
148 git checkout renamer^ &&
149 H=$(git rev-parse --verify HEAD) &&
150 M=$(git show-ref -s --verify refs/heads/master) &&
151 test "z$H" = "z$M" &&
152 if git symbolic-ref HEAD >/dev/null 2>&1
153 then
154 echo "OOPS, HEAD is still symbolic???"
155 false
156 else
157 : happy
161 test_expect_success 'checkout to detach HEAD with branchname^' '
163 git checkout -f master && git clean &&
164 git checkout renamer^ &&
165 H=$(git rev-parse --verify HEAD) &&
166 M=$(git show-ref -s --verify refs/heads/master) &&
167 test "z$H" = "z$M" &&
168 if git symbolic-ref HEAD >/dev/null 2>&1
169 then
170 echo "OOPS, HEAD is still symbolic???"
171 false
172 else
173 : happy
177 test_expect_success 'checkout to detach HEAD with HEAD^0' '
179 git checkout -f master && git clean &&
180 git checkout HEAD^0 &&
181 H=$(git rev-parse --verify HEAD) &&
182 M=$(git show-ref -s --verify refs/heads/master) &&
183 test "z$H" = "z$M" &&
184 if git symbolic-ref HEAD >/dev/null 2>&1
185 then
186 echo "OOPS, HEAD is still symbolic???"
187 false
188 else
189 : happy
193 test_done