Restore `stg sink --nopush` capability
[stgit.git] / t / t3400-pick.sh
blob87e77e733c5ab398655659d7cc591883dfe55966
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>&1 |
10 grep "master: branch not initialized"
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>&1 |
34 grep "incorrect number of arguments"
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>&1 |
41 grep "name can only be specified with one patch"
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>&1 |
64 grep "file can only be specified with --fold"
67 test_expect_success \
68 'Pick local unapplied patch' \
70 stg pick D &&
71 test "$(echo $(stg series --applied --noprefix))" = "A B C D-1" &&
72 test "$(echo $(stg series --unapplied --noprefix))" = "D"
75 test_expect_success \
76 'Pick --fold --revert local patch' \
78 stg pick --fold --revert D &&
79 stg refresh && stg clean &&
80 test "$(echo $(stg series --applied --noprefix))" = "A B C" &&
81 test "$(echo $(stg series --unapplied --noprefix))" = "D"
84 test_expect_success \
85 'Pick --fold without applied patches' \
87 stg pop --all &&
88 stg pick --fold D &&
89 test "$(echo $(stg series --unapplied --noprefix))" = "A B C D" &&
90 test "$(echo $(stg status))" = "A d" &&
91 stg reset --hard
94 test_expect_success \
95 'Pick --fold --file' \
97 stg push --all &&
98 stg pick --fold --file a --file c foo:E &&
99 test "$(echo $(cat a))" = "A AA" &&
100 test "$(echo $(cat b))" = "B" &&
101 test "$(echo $(cat c))" = "C CC" &&
102 stg reset --hard
105 test_expect_success \
106 'Pick --revert' \
108 stg pick --revert C &&
109 test "$(stg top)" = "revert-C" &&
110 stg show | grep -E "Revert \"c\"" &&
111 stg delete revert-C
114 test_expect_success \
115 'Pick with empty result' \
117 stg pick -B foo A &&
118 stg series -e | grep -E "0> A-1" &&
119 stg delete A-1
122 test_expect_success \
123 'Pick --fold with empty result' \
125 stg pick --fold -B foo A &&
126 test -z "$(stg status)"
129 test_expect_success \
130 'Pick --fold --files empty result' \
132 stg pick --fold -B foo A --file c &&
133 test -z "$(stg status)"
136 test_expect_success \
137 'Pick --update' \
139 stg goto C &&
140 stg pick --update -B foo E &&
141 test "$(stg status)" = "M c" &&
142 test "$(echo $(cat c))" = "C CC" &&
143 stg reset --hard
146 test_expect_success \
147 'Pick --update without applied patches' \
149 stg pop -a &&
150 command_error stg pick --update -B foo E 2>&1 |
151 grep "No patches applied"
154 test_expect_success \
155 'Pick commit with expose' \
157 stg branch foo &&
158 stg goto C &&
159 stg id > C-id &&
160 stg commit -a &&
161 stg branch master &&
162 test_write_lines \
163 "c" \
164 "" \
165 "(imported from commit $(cat C-id))" \
166 > C2-expected.txt &&
167 test_when_finished rm -f C2-expected.txt C2-message.txt &&
168 stg pick --expose --name C2 $(cat C-id) &&
169 test "$(stg top)" = "C2" &&
170 git show --no-patch --pretty=format:%B > C2-message.txt &&
171 test_cmp C2-expected.txt C2-message.txt
174 test_expect_success \
175 'Pick too many commits' \
177 command_error stg pick --ref-branch foo $(cat C-id) D-foo 2>&1 |
178 grep "Unknown patch name"
181 test_expect_success \
182 'Pick with conflict' \
184 rm C-id &&
185 stg push A &&
186 conflict stg pick foo:AAA 2>&1 |
187 grep "1 merge conflict(s)" &&
188 test "$(stg top)" = "AAA" &&
189 test "$(echo $(stg series -A --noprefix))" = "C2 A AAA" &&
190 test "$(echo $(stg status))" = "UU a" &&
191 stg reset --hard &&
192 stg undo
195 test_expect_success \
196 'Pick --fold with conflict' \
198 conflict stg pick --fold --ref-branch=foo AAA 2>&1 |
199 grep "Merge conflict in a" &&
200 stg reset --hard
203 test_expect_success \
204 'Pick --fold --file with conflict' \
206 conflict stg pick --fold --file a -Bfoo AAA 2>&1 |
207 grep "AAA does not apply cleanly" &&
208 stg reset --hard
211 test_expect_success \
212 'Pick --update with conflict' \
214 conflict stg pick --update foo:AAA 2>&1 |
215 grep "AAA does not apply cleanly" &&
216 stg reset --hard
219 test_done