Preserve picked patch name when possible
[stgit.git] / t / t3400-pick.sh
blobde519677c8b372b47d6ea8eea5dd25714b19f23f
1 #!/bin/sh
2 test_description='Test the pick command'
4 . ./test-lib.sh
6 test_expect_success \
7 'Attempt pick with uninitialized stack' \
9 command_error stg pick foo 2>err &&
10 grep "master: branch not initialized" err
13 test_expect_success \
14 'Initialize the StGit repository' \
16 stg init &&
17 stg new A -m "a" &&
18 echo A > a &&
19 stg add a &&
20 stg refresh &&
21 stg new B -m "b" &&
22 echo B > b &&
23 stg add b &&
24 stg refresh &&
25 stg branch --clone foo &&
26 stg new C -m "c" &&
27 echo C > c &&
28 stg add c &&
29 stg refresh &&
30 stg new D-foo -m "d" &&
31 echo D > d &&
32 stg add d &&
33 stg refresh &&
34 stg new E -m "e" &&
35 echo AA >> a &&
36 echo BB >> b &&
37 echo CC >> c &&
38 stg refresh &&
39 stg new AAA -m "aaa" &&
40 echo "A" > a &&
41 echo "AAA" >> a &&
42 echo "AA" >> a &&
43 stg refresh &&
44 stg new -m "fancy patchname" Fancy@name &&
45 stg branch master
48 test_expect_success \
49 'No pick args' \
51 command_error stg pick 2>err &&
52 grep "incorrect number of arguments" err
55 test_expect_success \
56 'Pick --name with multiple patches' \
58 command_error stg pick --ref-branch foo --name C_and_E C E 2>err &&
59 grep "name can only be specified with one patch" err
62 test_expect_success \
63 'Pick preserves fancy patch name' \
65 stg pick -B foo Fancy@name &&
66 test "$(echo $(stg series --applied --noprefix))" = "A B Fancy@name" &&
67 stg delete --top
70 test_expect_success \
71 'Pick fancy patch name conflict' \
73 stg new -m "also fancy name" Fancy@name &&
74 stg pick -B foo Fancy@name &&
75 test "$(echo $(stg series --applied --noprefix))" = "A B Fancy@name Fancy-name" &&
76 stg delete Fancy@name Fancy-name
79 test_expect_success \
80 'Pick remote patch' \
82 stg pick foo:C &&
83 test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
84 test "$(echo $(cat c))" = "C"
87 test_expect_success \
88 'Pick --noapply remote patch' \
90 stg pick --noapply --ref-branch foo --name D D-foo &&
91 test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
92 test "$(echo $(stg series --unapplied --noprefix))" = "D"
95 test_expect_success \
96 'Pick --noapply several patches' \
98 stg delete C..D &&
99 stg pick -B foo --noapply C E AAA &&
100 test "$(echo $(stg series --applied --noprefix))" = "A B" &&
101 test "$(echo $(stg series --unapplied --noprefix))" = "C E AAA" &&
102 stg goto AAA &&
103 test "$(echo $(cat a))" = "A AAA AA" &&
104 stg goto C &&
105 stg delete E AAA &&
106 stg pick --noapply --name D foo:D-foo &&
107 test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
108 test "$(echo $(stg series --unapplied --noprefix))" = "D"
111 test_expect_success \
112 'Pick --file without --fold' \
114 command_error stg pick --file d D 2>err &&
115 grep "file can only be specified with --fold" err &&
116 rm err
119 test_expect_success \
120 'Pick local unapplied patch' \
122 stg pick D &&
123 test "$(echo $(stg series --applied --noprefix))" = "A B C D-1" &&
124 test "$(echo $(stg series --unapplied --noprefix))" = "D"
127 test_expect_success \
128 'Pick --fold --revert local patch' \
130 stg pick --fold --revert D &&
131 stg refresh && stg clean &&
132 test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
133 test "$(echo $(stg series --unapplied --noprefix))" = "D"
136 test_expect_success \
137 'Pick --fold without applied patches' \
139 stg pop --all &&
140 stg pick --fold D &&
141 test "$(echo $(stg series --unapplied --noprefix))" = "A B C D" &&
142 test "$(echo $(stg status))" = "A d" &&
143 stg reset --hard
146 test_expect_success \
147 'Pick --fold --file' \
149 stg push --all &&
150 stg pick --fold --file a --file c foo:E &&
151 test "$(echo $(cat a))" = "A AA" &&
152 test "$(echo $(cat b))" = "B" &&
153 test "$(echo $(cat c))" = "C CC" &&
154 stg reset --hard
157 test_expect_success \
158 'Pick --revert' \
160 stg pick --revert C &&
161 test "$(stg top)" = "revert-C" &&
162 stg show | grep -E "Revert \"c\"" &&
163 stg delete revert-C
166 test_expect_success \
167 'Pick with empty result' \
169 stg pick -B foo A &&
170 stg series -e | grep -E "0> A-1" &&
171 stg delete A-1
174 test_expect_success \
175 'Pick --fold with empty result' \
177 stg pick --fold -B foo A &&
178 test -z "$(stg status)"
181 test_expect_success \
182 'Pick --fold --files empty result' \
184 stg pick --fold -B foo A --file c &&
185 test -z "$(stg status)"
188 test_expect_success \
189 'Pick --update' \
191 stg goto C &&
192 stg pick --update -B foo E &&
193 test "$(stg status)" = "M c" &&
194 test "$(echo $(cat c))" = "C CC" &&
195 stg reset --hard
198 test_expect_success \
199 'Pick --update without applied patches' \
201 stg pop -a &&
202 command_error stg pick --update -B foo E 2>err &&
203 grep "No patches applied" err &&
204 rm err
207 test_expect_success \
208 'Pick commit with expose' \
210 stg branch foo &&
211 stg goto C &&
212 stg id > C-id &&
213 stg commit -a &&
214 stg branch master &&
215 test_write_lines \
216 "c" \
217 "" \
218 "(imported from commit $(cat C-id))" \
219 > C2-expected.txt &&
220 test_when_finished rm -f C2-expected.txt C2-message.txt &&
221 stg pick --expose --name C2 $(cat C-id) &&
222 test "$(stg top)" = "C2" &&
223 git show --no-patch --pretty=format:%B > C2-message.txt &&
224 test_cmp C2-expected.txt C2-message.txt
227 test_expect_success \
228 'Pick too many commits' \
230 command_error stg pick --ref-branch foo $(cat C-id) D-foo 2>err &&
231 grep "Unknown patch name" err &&
232 rm err
235 test_expect_success \
236 'Pick with conflict' \
238 rm C-id &&
239 stg push A &&
240 conflict stg pick foo:AAA 2>err &&
241 grep "1 merge conflict(s)" err &&
242 rm err &&
243 test "$(stg top)" = "AAA" &&
244 test "$(echo $(stg series -A --noprefix))" = "C2 A AAA" &&
245 test "$(echo $(stg status))" = "UU a" &&
246 stg reset --hard &&
247 stg undo
250 test_expect_success \
251 'Pick --fold with conflict' \
253 conflict stg pick --fold --ref-branch=foo AAA 2>err &&
254 grep "Merge conflict in a" err &&
255 stg reset --hard
258 test_expect_success \
259 'Pick --fold --file with conflict' \
261 conflict stg pick --fold --file a -Bfoo AAA 2>err &&
262 grep "AAA does not apply cleanly" err &&
263 stg reset --hard
266 test_expect_success \
267 'Pick --update with conflict' \
269 conflict stg pick --update foo:AAA 2>err &&
270 grep "AAA does not apply cleanly" err &&
271 stg reset --hard
274 test_done