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' \
17 stg new A -m "a" && echo A > a && stg add a && stg refresh &&
18 stg new B -m "b" && echo B > b && stg add b && stg refresh &&
19 stg branch --clone foo &&
20 stg new C -m "c" && echo C > c && stg add c && stg refresh &&
21 stg new D-foo -m "d" && echo D > d && stg add d && stg refresh &&
23 echo AA >> a && echo BB >> b && echo CC >> c &&
25 stg new AAA -m "aaa" &&
26 echo "A" > a && echo "AAA" >> a && echo "AA" >> a && stg refresh &&
33 command_error stg pick 2>err &&
34 grep "incorrect number of arguments" err
38 'Pick --name with multiple patches' \
40 command_error stg pick --ref-branch foo --name C_and_E C E 2>err &&
41 grep "name can only be specified with one patch" err
48 test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
49 test "$(echo $(cat c))" = "C"
53 'Pick --unapplied remote patch' \
55 stg pick --unapplied --ref-branch foo --name D D-foo &&
56 test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
57 test "$(echo $(stg series --unapplied --noprefix))" = "D"
61 'Pick --file without --fold' \
63 command_error stg pick --file d D 2>err &&
64 grep "file can only be specified with --fold" err &&
69 'Pick local unapplied patch' \
72 test "$(echo $(stg series --applied --noprefix))" = "A B C D-1" &&
73 test "$(echo $(stg series --unapplied --noprefix))" = "D"
77 'Pick --fold --revert local patch' \
79 stg pick --fold --revert D &&
80 stg refresh && stg clean &&
81 test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
82 test "$(echo $(stg series --unapplied --noprefix))" = "D"
86 'Pick --fold without applied patches' \
90 test "$(echo $(stg series --unapplied --noprefix))" = "A B C D" &&
91 test "$(echo $(stg status))" = "A d" &&
96 'Pick --fold --file' \
99 stg pick --fold --file a --file c foo:E &&
100 test "$(echo $(cat a))" = "A AA" &&
101 test "$(echo $(cat b))" = "B" &&
102 test "$(echo $(cat c))" = "C CC" &&
106 test_expect_success \
109 stg pick --revert C &&
110 test "$(stg top)" = "revert-C" &&
111 stg show | grep -E "Revert \"c\"" &&
115 test_expect_success \
116 'Pick with empty result' \
119 stg series -e | grep -E "0> A-1" &&
123 test_expect_success \
124 'Pick --fold with empty result' \
126 stg pick --fold -B foo A &&
127 test -z "$(stg status)"
130 test_expect_success \
131 'Pick --fold --files empty result' \
133 stg pick --fold -B foo A --file c &&
134 test -z "$(stg status)"
137 test_expect_success \
141 stg pick --update -B foo E &&
142 test "$(stg status)" = "M c" &&
143 test "$(echo $(cat c))" = "C CC" &&
147 test_expect_success \
148 'Pick --update without applied patches' \
151 command_error stg pick --update -B foo E 2>err &&
152 grep "No patches applied" err &&
156 test_expect_success \
157 'Pick commit with expose' \
167 "(imported from commit $(cat C-id))" \
169 test_when_finished rm -f C2-expected.txt C2-message.txt &&
170 stg pick --expose --name C2 $(cat C-id) &&
171 test "$(stg top)" = "C2" &&
172 git show --no-patch --pretty=format:%B > C2-message.txt &&
173 test_cmp C2-expected.txt C2-message.txt
176 test_expect_success \
177 'Pick too many commits' \
179 command_error stg pick --ref-branch foo $(cat C-id) D-foo 2>err &&
180 grep "Unknown patch name" err &&
184 test_expect_success \
185 'Pick with conflict' \
189 conflict stg pick foo:AAA 2>err &&
190 grep "1 merge conflict(s)" err &&
192 test "$(stg top)" = "AAA" &&
193 test "$(echo $(stg series -A --noprefix))" = "C2 A AAA" &&
194 test "$(echo $(stg status))" = "UU a" &&
199 test_expect_success \
200 'Pick --fold with conflict' \
202 conflict stg pick --fold --ref-branch=foo AAA 2>err &&
203 grep "Merge conflict in a" err &&
207 test_expect_success \
208 'Pick --fold --file with conflict' \
210 conflict stg pick --fold --file a -Bfoo AAA 2>err &&
211 grep "AAA does not apply cleanly" err &&
215 test_expect_success \
216 'Pick --update with conflict' \
218 conflict stg pick --update foo:AAA 2>err &&
219 grep "AAA does not apply cleanly" err &&