Tests redirect to err file when grepping stderr
[stgit.git] / t / t3400-pick.sh
bloba3943a58d018bc6dcbc3704a47ea9235c0f98cb8
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" && 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 &&
22 stg new E -m "e" &&
23 echo AA >> a && echo BB >> b && echo CC >> c &&
24 stg refresh &&
25 stg new AAA -m "aaa" &&
26 echo "A" > a && echo "AAA" >> a && echo "AA" >> a && stg refresh &&
27 stg branch master
30 test_expect_success \
31 'No pick args' \
33 command_error stg pick 2>err &&
34 grep "incorrect number of arguments" err
37 test_expect_success \
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
44 test_expect_success \
45 'Pick remote patch' \
47 stg pick foo:C &&
48 test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
49 test "$(echo $(cat c))" = "C"
52 test_expect_success \
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"
60 test_expect_success \
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 &&
65 rm err
68 test_expect_success \
69 'Pick local unapplied patch' \
71 stg pick D &&
72 test "$(echo $(stg series --applied --noprefix))" = "A B C D-1" &&
73 test "$(echo $(stg series --unapplied --noprefix))" = "D"
76 test_expect_success \
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"
85 test_expect_success \
86 'Pick --fold without applied patches' \
88 stg pop --all &&
89 stg pick --fold D &&
90 test "$(echo $(stg series --unapplied --noprefix))" = "A B C D" &&
91 test "$(echo $(stg status))" = "A d" &&
92 stg reset --hard
95 test_expect_success \
96 'Pick --fold --file' \
98 stg push --all &&
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" &&
103 stg reset --hard
106 test_expect_success \
107 'Pick --revert' \
109 stg pick --revert C &&
110 test "$(stg top)" = "revert-C" &&
111 stg show | grep -E "Revert \"c\"" &&
112 stg delete revert-C
115 test_expect_success \
116 'Pick with empty result' \
118 stg pick -B foo A &&
119 stg series -e | grep -E "0> A-1" &&
120 stg delete 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 \
138 'Pick --update' \
140 stg goto C &&
141 stg pick --update -B foo E &&
142 test "$(stg status)" = "M c" &&
143 test "$(echo $(cat c))" = "C CC" &&
144 stg reset --hard
147 test_expect_success \
148 'Pick --update without applied patches' \
150 stg pop -a &&
151 command_error stg pick --update -B foo E 2>err &&
152 grep "No patches applied" err &&
153 rm err
156 test_expect_success \
157 'Pick commit with expose' \
159 stg branch foo &&
160 stg goto C &&
161 stg id > C-id &&
162 stg commit -a &&
163 stg branch master &&
164 test_write_lines \
165 "c" \
166 "" \
167 "(imported from commit $(cat C-id))" \
168 > C2-expected.txt &&
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 &&
181 rm err
184 test_expect_success \
185 'Pick with conflict' \
187 rm C-id &&
188 stg push A &&
189 conflict stg pick foo:AAA 2>err &&
190 grep "1 merge conflict(s)" err &&
191 rm err &&
192 test "$(stg top)" = "AAA" &&
193 test "$(echo $(stg series -A --noprefix))" = "C2 A AAA" &&
194 test "$(echo $(stg status))" = "UU a" &&
195 stg reset --hard &&
196 stg undo
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 &&
204 stg reset --hard
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 &&
212 stg reset --hard
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 &&
220 stg reset --hard
223 test_done