2 test_description
='Test the pick command'
7 'Attempt pick with uninitialized stack' \
9 command_error stg pick foo 2>err &&
10 grep "master: branch not initialized" err
14 'Initialize the StGit repository' \
25 stg branch --clone foo &&
30 stg new D-foo -m "d" &&
39 stg new AAA -m "aaa" &&
44 stg new -m "fancy patchname" Fancy@name &&
51 command_error stg pick 2>err &&
52 grep "incorrect number of arguments" err
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
63 'Pick preserves fancy patch name' \
65 stg pick -B foo Fancy@name &&
66 test "$(echo $(stg series --applied --noprefix))" = "A B Fancy@name" &&
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
83 test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
84 test "$(echo $(cat c))" = "C"
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"
96 'Pick --noapply several patches' \
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" &&
103 test "$(echo $(cat a))" = "A AAA AA" &&
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 &&
119 test_expect_success \
120 'Pick local unapplied patch' \
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' \
141 test "$(echo $(stg series --unapplied --noprefix))" = "A B C D" &&
142 test "$(echo $(stg status))" = "A d" &&
146 test_expect_success \
147 'Pick --fold --file' \
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" &&
157 test_expect_success \
160 stg pick --revert C &&
161 test "$(stg top)" = "revert-C" &&
162 stg show | grep -E "Revert \"c\"" &&
166 test_expect_success \
167 'Pick with empty result' \
170 stg series -e | grep -E "0> 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 \
192 stg pick --update -B foo E &&
193 test "$(stg status)" = "M c" &&
194 test "$(echo $(cat c))" = "C CC" &&
198 test_expect_success \
199 'Pick --update without applied patches' \
202 command_error stg pick --update -B foo E 2>err &&
203 grep "No patches applied" err &&
207 test_expect_success \
208 'Pick commit with expose' \
218 "(imported from commit $(cat C-id))" \
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 &&
235 test_expect_success \
236 'Pick with conflict' \
240 conflict stg pick foo:AAA 2>err &&
241 grep "1 merge conflict(s)" err &&
243 test "$(stg top)" = "AAA" &&
244 test "$(echo $(stg series -A --noprefix))" = "C2 A AAA" &&
245 test "$(echo $(stg status))" = "UU a" &&
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 &&
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 &&
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 &&