Blame


1 ad493afc 2019-08-03 stsp #!/bin/sh
2 ad493afc 2019-08-03 stsp #
3 ad493afc 2019-08-03 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 ad493afc 2019-08-03 stsp #
5 ad493afc 2019-08-03 stsp # Permission to use, copy, modify, and distribute this software for any
6 ad493afc 2019-08-03 stsp # purpose with or without fee is hereby granted, provided that the above
7 ad493afc 2019-08-03 stsp # copyright notice and this permission notice appear in all copies.
8 ad493afc 2019-08-03 stsp #
9 ad493afc 2019-08-03 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 ad493afc 2019-08-03 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 ad493afc 2019-08-03 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 ad493afc 2019-08-03 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 ad493afc 2019-08-03 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 ad493afc 2019-08-03 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 ad493afc 2019-08-03 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 ad493afc 2019-08-03 stsp
17 ad493afc 2019-08-03 stsp . ./common.sh
18 ad493afc 2019-08-03 stsp
19 ad493afc 2019-08-03 stsp function test_unstage_basic {
20 ad493afc 2019-08-03 stsp local testroot=`test_init unstage_basic`
21 ad493afc 2019-08-03 stsp
22 ad493afc 2019-08-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 ad493afc 2019-08-03 stsp ret="$?"
24 ad493afc 2019-08-03 stsp if [ "$ret" != "0" ]; then
25 ad493afc 2019-08-03 stsp test_done "$testroot" "$ret"
26 ad493afc 2019-08-03 stsp return 1
27 ad493afc 2019-08-03 stsp fi
28 ad493afc 2019-08-03 stsp
29 ad493afc 2019-08-03 stsp echo "modified file" > $testroot/wt/alpha
30 ad493afc 2019-08-03 stsp (cd $testroot/wt && got rm beta > /dev/null)
31 ad493afc 2019-08-03 stsp echo "new file" > $testroot/wt/foo
32 ad493afc 2019-08-03 stsp (cd $testroot/wt && got add foo > /dev/null)
33 ad493afc 2019-08-03 stsp
34 ad493afc 2019-08-03 stsp echo ' M alpha' > $testroot/stdout.expected
35 ad493afc 2019-08-03 stsp echo ' D beta' >> $testroot/stdout.expected
36 ad493afc 2019-08-03 stsp echo ' A foo' >> $testroot/stdout.expected
37 ad493afc 2019-08-03 stsp (cd $testroot/wt && got stage alpha beta foo > /dev/null)
38 ad493afc 2019-08-03 stsp
39 ad493afc 2019-08-03 stsp (cd $testroot/wt && got unstage > $testroot/stdout)
40 ad493afc 2019-08-03 stsp ret="$?"
41 ad493afc 2019-08-03 stsp if [ "$ret" != "0" ]; then
42 ad493afc 2019-08-03 stsp echo "got stage command succeeded unexpectedly" >&2
43 ad493afc 2019-08-03 stsp test_done "$testroot" "1"
44 ad493afc 2019-08-03 stsp return 1
45 ad493afc 2019-08-03 stsp fi
46 ad493afc 2019-08-03 stsp
47 ad493afc 2019-08-03 stsp echo 'G alpha' > $testroot/stdout.expected
48 ad493afc 2019-08-03 stsp echo 'D beta' >> $testroot/stdout.expected
49 ad493afc 2019-08-03 stsp echo 'G foo' >> $testroot/stdout.expected
50 ad493afc 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
51 ad493afc 2019-08-03 stsp ret="$?"
52 ad493afc 2019-08-03 stsp if [ "$ret" != "0" ]; then
53 ad493afc 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
54 ad493afc 2019-08-03 stsp test_done "$testroot" "$ret"
55 ad493afc 2019-08-03 stsp return 1
56 ad493afc 2019-08-03 stsp fi
57 ad493afc 2019-08-03 stsp
58 ad493afc 2019-08-03 stsp echo 'M alpha' > $testroot/stdout.expected
59 ad493afc 2019-08-03 stsp echo 'D beta' >> $testroot/stdout.expected
60 ad493afc 2019-08-03 stsp echo 'A foo' >> $testroot/stdout.expected
61 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
62 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
63 2e1f37b0 2019-08-08 stsp ret="$?"
64 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
65 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
66 2e1f37b0 2019-08-08 stsp fi
67 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
68 2e1f37b0 2019-08-08 stsp }
69 2e1f37b0 2019-08-08 stsp
70 8b13ce36 2019-08-08 stsp function test_unstage_unversioned {
71 8b13ce36 2019-08-08 stsp local testroot=`test_init unstage_unversioned`
72 8b13ce36 2019-08-08 stsp
73 8b13ce36 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
74 8b13ce36 2019-08-08 stsp ret="$?"
75 8b13ce36 2019-08-08 stsp if [ "$ret" != "0" ]; then
76 8b13ce36 2019-08-08 stsp test_done "$testroot" "$ret"
77 8b13ce36 2019-08-08 stsp return 1
78 8b13ce36 2019-08-08 stsp fi
79 8b13ce36 2019-08-08 stsp
80 8b13ce36 2019-08-08 stsp echo "modified file" > $testroot/wt/alpha
81 8b13ce36 2019-08-08 stsp (cd $testroot/wt && got rm beta > /dev/null)
82 8b13ce36 2019-08-08 stsp echo "new file" > $testroot/wt/foo
83 8b13ce36 2019-08-08 stsp (cd $testroot/wt && got add foo > /dev/null)
84 8b13ce36 2019-08-08 stsp
85 8b13ce36 2019-08-08 stsp echo ' M alpha' > $testroot/stdout.expected
86 8b13ce36 2019-08-08 stsp echo ' D beta' >> $testroot/stdout.expected
87 8b13ce36 2019-08-08 stsp echo ' A foo' >> $testroot/stdout.expected
88 8b13ce36 2019-08-08 stsp (cd $testroot/wt && got stage > /dev/null)
89 8b13ce36 2019-08-08 stsp
90 8b13ce36 2019-08-08 stsp touch $testroot/wt/unversioned-file
91 8b13ce36 2019-08-08 stsp
92 8b13ce36 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
93 8b13ce36 2019-08-08 stsp echo ' M alpha' > $testroot/stdout.expected
94 8b13ce36 2019-08-08 stsp echo ' D beta' >> $testroot/stdout.expected
95 8b13ce36 2019-08-08 stsp echo ' A foo' >> $testroot/stdout.expected
96 8b13ce36 2019-08-08 stsp echo "? unversioned-file" >> $testroot/stdout.expected
97 8b13ce36 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
98 8b13ce36 2019-08-08 stsp ret="$?"
99 8b13ce36 2019-08-08 stsp if [ "$ret" != "0" ]; then
100 8b13ce36 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
101 8b13ce36 2019-08-08 stsp test_done "$testroot" "$ret"
102 8b13ce36 2019-08-08 stsp return 1
103 8b13ce36 2019-08-08 stsp fi
104 8b13ce36 2019-08-08 stsp
105 8b13ce36 2019-08-08 stsp (cd $testroot/wt && got unstage > $testroot/stdout)
106 8b13ce36 2019-08-08 stsp ret="$?"
107 8b13ce36 2019-08-08 stsp if [ "$ret" != "0" ]; then
108 8b13ce36 2019-08-08 stsp echo "got unstage command failed unexpectedly" >&2
109 8b13ce36 2019-08-08 stsp test_done "$testroot" "1"
110 8b13ce36 2019-08-08 stsp return 1
111 8b13ce36 2019-08-08 stsp fi
112 8b13ce36 2019-08-08 stsp
113 8b13ce36 2019-08-08 stsp echo 'G alpha' > $testroot/stdout.expected
114 8b13ce36 2019-08-08 stsp echo 'D beta' >> $testroot/stdout.expected
115 8b13ce36 2019-08-08 stsp echo 'G foo' >> $testroot/stdout.expected
116 8b13ce36 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
117 8b13ce36 2019-08-08 stsp ret="$?"
118 8b13ce36 2019-08-08 stsp if [ "$ret" != "0" ]; then
119 8b13ce36 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
120 8b13ce36 2019-08-08 stsp test_done "$testroot" "$ret"
121 8b13ce36 2019-08-08 stsp return 1
122 8b13ce36 2019-08-08 stsp fi
123 8b13ce36 2019-08-08 stsp
124 8b13ce36 2019-08-08 stsp (cd $testroot/wt && got stage > /dev/null)
125 8b13ce36 2019-08-08 stsp
126 8b13ce36 2019-08-08 stsp # unstaging an unversioned path is a no-op
127 8b13ce36 2019-08-08 stsp (cd $testroot/wt && got unstage unversioned > $testroot/stdout)
128 8b13ce36 2019-08-08 stsp ret="$?"
129 8b13ce36 2019-08-08 stsp if [ "$ret" != "0" ]; then
130 8b13ce36 2019-08-08 stsp echo "got unstage command failed unexpectedly" >&2
131 8b13ce36 2019-08-08 stsp test_done "$testroot" "$ret"
132 8b13ce36 2019-08-08 stsp return 1
133 8b13ce36 2019-08-08 stsp fi
134 8b13ce36 2019-08-08 stsp
135 8b13ce36 2019-08-08 stsp echo ' M alpha' > $testroot/stdout.expected
136 8b13ce36 2019-08-08 stsp echo ' D beta' >> $testroot/stdout.expected
137 8b13ce36 2019-08-08 stsp echo ' A foo' >> $testroot/stdout.expected
138 8b13ce36 2019-08-08 stsp echo "? unversioned-file" >> $testroot/stdout.expected
139 8b13ce36 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
140 8b13ce36 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
141 8b13ce36 2019-08-08 stsp ret="$?"
142 8b13ce36 2019-08-08 stsp if [ "$ret" != "0" ]; then
143 8b13ce36 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
144 8b13ce36 2019-08-08 stsp fi
145 8b13ce36 2019-08-08 stsp test_done "$testroot" "$ret"
146 8b13ce36 2019-08-08 stsp }
147 8b13ce36 2019-08-08 stsp
148 2e1f37b0 2019-08-08 stsp function test_unstage_patch {
149 2e1f37b0 2019-08-08 stsp local testroot=`test_init unstage_patch`
150 2e1f37b0 2019-08-08 stsp
151 2e1f37b0 2019-08-08 stsp jot 16 > $testroot/repo/numbers
152 2e1f37b0 2019-08-08 stsp (cd $testroot/repo && git add numbers)
153 2e1f37b0 2019-08-08 stsp git_commit $testroot/repo -m "added numbers file"
154 2e1f37b0 2019-08-08 stsp local commit_id=`git_show_head $testroot/repo`
155 2e1f37b0 2019-08-08 stsp
156 2e1f37b0 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
157 2e1f37b0 2019-08-08 stsp ret="$?"
158 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
159 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
160 2e1f37b0 2019-08-08 stsp return 1
161 2e1f37b0 2019-08-08 stsp fi
162 2e1f37b0 2019-08-08 stsp
163 2e1f37b0 2019-08-08 stsp sed -i -e 's/^2$/a/' $testroot/wt/numbers
164 2e1f37b0 2019-08-08 stsp sed -i -e 's/^7$/b/' $testroot/wt/numbers
165 2e1f37b0 2019-08-08 stsp sed -i -e 's/^16$/c/' $testroot/wt/numbers
166 2e1f37b0 2019-08-08 stsp
167 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got stage > /dev/null)
168 2e1f37b0 2019-08-08 stsp ret="$?"
169 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
170 2e1f37b0 2019-08-08 stsp echo "got stage command failed unexpectedly" >&2
171 2e1f37b0 2019-08-08 stsp test_done "$testroot" "1"
172 2e1f37b0 2019-08-08 stsp return 1
173 2e1f37b0 2019-08-08 stsp fi
174 2e1f37b0 2019-08-08 stsp
175 2e1f37b0 2019-08-08 stsp # don't unstage any hunks
176 2e1f37b0 2019-08-08 stsp printf "n\nn\nn\n" > $testroot/patchscript
177 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
178 2e1f37b0 2019-08-08 stsp numbers > $testroot/stdout)
179 2e1f37b0 2019-08-08 stsp ret="$?"
180 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
181 2e1f37b0 2019-08-08 stsp echo "got stage command failed unexpectedly" >&2
182 2e1f37b0 2019-08-08 stsp test_done "$testroot" "1"
183 2e1f37b0 2019-08-08 stsp return 1
184 2e1f37b0 2019-08-08 stsp fi
185 2e1f37b0 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
186 2e1f37b0 2019-08-08 stsp -----------------------------------------------
187 2e1f37b0 2019-08-08 stsp @@ -1,5 +1,5 @@
188 2e1f37b0 2019-08-08 stsp 1
189 2e1f37b0 2019-08-08 stsp -2
190 2e1f37b0 2019-08-08 stsp +a
191 2e1f37b0 2019-08-08 stsp 3
192 2e1f37b0 2019-08-08 stsp 4
193 2e1f37b0 2019-08-08 stsp 5
194 2e1f37b0 2019-08-08 stsp -----------------------------------------------
195 2e1f37b0 2019-08-08 stsp M numbers (change 1 of 3)
196 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] n
197 2e1f37b0 2019-08-08 stsp -----------------------------------------------
198 2e1f37b0 2019-08-08 stsp @@ -4,7 +4,7 @@
199 2e1f37b0 2019-08-08 stsp 4
200 2e1f37b0 2019-08-08 stsp 5
201 2e1f37b0 2019-08-08 stsp 6
202 2e1f37b0 2019-08-08 stsp -7
203 2e1f37b0 2019-08-08 stsp +b
204 2e1f37b0 2019-08-08 stsp 8
205 2e1f37b0 2019-08-08 stsp 9
206 2e1f37b0 2019-08-08 stsp 10
207 2e1f37b0 2019-08-08 stsp -----------------------------------------------
208 2e1f37b0 2019-08-08 stsp M numbers (change 2 of 3)
209 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] n
210 2e1f37b0 2019-08-08 stsp -----------------------------------------------
211 2e1f37b0 2019-08-08 stsp @@ -13,4 +13,4 @@
212 2e1f37b0 2019-08-08 stsp 13
213 2e1f37b0 2019-08-08 stsp 14
214 2e1f37b0 2019-08-08 stsp 15
215 2e1f37b0 2019-08-08 stsp -16
216 2e1f37b0 2019-08-08 stsp +c
217 2e1f37b0 2019-08-08 stsp -----------------------------------------------
218 2e1f37b0 2019-08-08 stsp M numbers (change 3 of 3)
219 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] n
220 2e1f37b0 2019-08-08 stsp EOF
221 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
222 2e1f37b0 2019-08-08 stsp ret="$?"
223 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
224 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
225 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
226 2e1f37b0 2019-08-08 stsp return 1
227 2e1f37b0 2019-08-08 stsp fi
228 2e1f37b0 2019-08-08 stsp
229 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
230 2e1f37b0 2019-08-08 stsp echo " M numbers" > $testroot/stdout.expected
231 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
232 2e1f37b0 2019-08-08 stsp ret="$?"
233 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
234 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
235 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
236 2e1f37b0 2019-08-08 stsp return 1
237 2e1f37b0 2019-08-08 stsp fi
238 2e1f37b0 2019-08-08 stsp
239 2e1f37b0 2019-08-08 stsp # unstage middle hunk
240 2e1f37b0 2019-08-08 stsp printf "n\ny\nn\n" > $testroot/patchscript
241 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
242 2e1f37b0 2019-08-08 stsp numbers > $testroot/stdout)
243 2e1f37b0 2019-08-08 stsp
244 2e1f37b0 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
245 2e1f37b0 2019-08-08 stsp -----------------------------------------------
246 2e1f37b0 2019-08-08 stsp @@ -1,5 +1,5 @@
247 2e1f37b0 2019-08-08 stsp 1
248 2e1f37b0 2019-08-08 stsp -2
249 2e1f37b0 2019-08-08 stsp +a
250 2e1f37b0 2019-08-08 stsp 3
251 2e1f37b0 2019-08-08 stsp 4
252 2e1f37b0 2019-08-08 stsp 5
253 2e1f37b0 2019-08-08 stsp -----------------------------------------------
254 2e1f37b0 2019-08-08 stsp M numbers (change 1 of 3)
255 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] n
256 2e1f37b0 2019-08-08 stsp -----------------------------------------------
257 2e1f37b0 2019-08-08 stsp @@ -4,7 +4,7 @@
258 2e1f37b0 2019-08-08 stsp 4
259 2e1f37b0 2019-08-08 stsp 5
260 2e1f37b0 2019-08-08 stsp 6
261 2e1f37b0 2019-08-08 stsp -7
262 2e1f37b0 2019-08-08 stsp +b
263 2e1f37b0 2019-08-08 stsp 8
264 2e1f37b0 2019-08-08 stsp 9
265 2e1f37b0 2019-08-08 stsp 10
266 2e1f37b0 2019-08-08 stsp -----------------------------------------------
267 2e1f37b0 2019-08-08 stsp M numbers (change 2 of 3)
268 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] y
269 2e1f37b0 2019-08-08 stsp -----------------------------------------------
270 2e1f37b0 2019-08-08 stsp @@ -13,4 +13,4 @@
271 2e1f37b0 2019-08-08 stsp 13
272 2e1f37b0 2019-08-08 stsp 14
273 2e1f37b0 2019-08-08 stsp 15
274 2e1f37b0 2019-08-08 stsp -16
275 2e1f37b0 2019-08-08 stsp +c
276 2e1f37b0 2019-08-08 stsp -----------------------------------------------
277 2e1f37b0 2019-08-08 stsp M numbers (change 3 of 3)
278 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] n
279 2e1f37b0 2019-08-08 stsp G numbers
280 2e1f37b0 2019-08-08 stsp EOF
281 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
282 2e1f37b0 2019-08-08 stsp ret="$?"
283 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
284 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
285 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
286 2e1f37b0 2019-08-08 stsp return 1
287 2e1f37b0 2019-08-08 stsp fi
288 2e1f37b0 2019-08-08 stsp
289 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
290 2e1f37b0 2019-08-08 stsp echo "MM numbers" > $testroot/stdout.expected
291 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
292 2e1f37b0 2019-08-08 stsp ret="$?"
293 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
294 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
295 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
296 2e1f37b0 2019-08-08 stsp return 1
297 2e1f37b0 2019-08-08 stsp fi
298 2e1f37b0 2019-08-08 stsp
299 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got diff -s > $testroot/stdout)
300 2e1f37b0 2019-08-08 stsp
301 2e1f37b0 2019-08-08 stsp echo "diff $commit_id $testroot/wt (staged changes)" \
302 2e1f37b0 2019-08-08 stsp > $testroot/stdout.expected
303 2e1f37b0 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
304 2e1f37b0 2019-08-08 stsp got tree -r $testroot/repo -i -c $commit_id \
305 2e1f37b0 2019-08-08 stsp | grep 'numbers$' | cut -d' ' -f 1 \
306 2e1f37b0 2019-08-08 stsp >> $testroot/stdout.expected
307 2e1f37b0 2019-08-08 stsp echo -n 'blob + ' >> $testroot/stdout.expected
308 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
309 2e1f37b0 2019-08-08 stsp >> $testroot/stdout.expected
310 2e1f37b0 2019-08-08 stsp cat >> $testroot/stdout.expected <<EOF
311 2e1f37b0 2019-08-08 stsp --- numbers
312 2e1f37b0 2019-08-08 stsp +++ numbers
313 2e1f37b0 2019-08-08 stsp @@ -1,5 +1,5 @@
314 2e1f37b0 2019-08-08 stsp 1
315 2e1f37b0 2019-08-08 stsp -2
316 2e1f37b0 2019-08-08 stsp +a
317 2e1f37b0 2019-08-08 stsp 3
318 2e1f37b0 2019-08-08 stsp 4
319 2e1f37b0 2019-08-08 stsp 5
320 2e1f37b0 2019-08-08 stsp @@ -13,4 +13,4 @@
321 2e1f37b0 2019-08-08 stsp 13
322 2e1f37b0 2019-08-08 stsp 14
323 2e1f37b0 2019-08-08 stsp 15
324 2e1f37b0 2019-08-08 stsp -16
325 2e1f37b0 2019-08-08 stsp +c
326 2e1f37b0 2019-08-08 stsp EOF
327 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
328 2e1f37b0 2019-08-08 stsp ret="$?"
329 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
330 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
331 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
332 2e1f37b0 2019-08-08 stsp return 1
333 2e1f37b0 2019-08-08 stsp fi
334 2e1f37b0 2019-08-08 stsp
335 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
336 2e1f37b0 2019-08-08 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
337 2e1f37b0 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
338 4ce46740 2019-08-08 stsp (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
339 4ce46740 2019-08-08 stsp tr -d '\n' >> $testroot/stdout.expected
340 4ce46740 2019-08-08 stsp echo " (staged)" >> $testroot/stdout.expected
341 2e1f37b0 2019-08-08 stsp echo "file + numbers" >> $testroot/stdout.expected
342 2e1f37b0 2019-08-08 stsp cat >> $testroot/stdout.expected <<EOF
343 2e1f37b0 2019-08-08 stsp --- numbers
344 2e1f37b0 2019-08-08 stsp +++ numbers
345 2e1f37b0 2019-08-08 stsp @@ -4,7 +4,7 @@ a
346 2e1f37b0 2019-08-08 stsp 4
347 2e1f37b0 2019-08-08 stsp 5
348 2e1f37b0 2019-08-08 stsp 6
349 2e1f37b0 2019-08-08 stsp -7
350 2e1f37b0 2019-08-08 stsp +b
351 2e1f37b0 2019-08-08 stsp 8
352 2e1f37b0 2019-08-08 stsp 9
353 2e1f37b0 2019-08-08 stsp 10
354 2e1f37b0 2019-08-08 stsp EOF
355 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
356 2e1f37b0 2019-08-08 stsp ret="$?"
357 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
358 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
359 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
360 2e1f37b0 2019-08-08 stsp return 1
361 2e1f37b0 2019-08-08 stsp fi
362 2e1f37b0 2019-08-08 stsp
363 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got stage >/dev/null)
364 2e1f37b0 2019-08-08 stsp ret="$?"
365 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
366 2e1f37b0 2019-08-08 stsp echo "got stage command failed unexpectedly" >&2
367 2e1f37b0 2019-08-08 stsp test_done "$testroot" "1"
368 2e1f37b0 2019-08-08 stsp return 1
369 2e1f37b0 2019-08-08 stsp fi
370 2e1f37b0 2019-08-08 stsp
371 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
372 2e1f37b0 2019-08-08 stsp echo " M numbers" > $testroot/stdout.expected
373 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
374 2e1f37b0 2019-08-08 stsp ret="$?"
375 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
376 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
377 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
378 2e1f37b0 2019-08-08 stsp return 1
379 2e1f37b0 2019-08-08 stsp fi
380 2e1f37b0 2019-08-08 stsp
381 2e1f37b0 2019-08-08 stsp # unstage last hunk
382 2e1f37b0 2019-08-08 stsp printf "n\nn\ny\n" > $testroot/patchscript
383 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
384 2e1f37b0 2019-08-08 stsp numbers > $testroot/stdout)
385 2e1f37b0 2019-08-08 stsp
386 2e1f37b0 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
387 2e1f37b0 2019-08-08 stsp -----------------------------------------------
388 2e1f37b0 2019-08-08 stsp @@ -1,5 +1,5 @@
389 2e1f37b0 2019-08-08 stsp 1
390 2e1f37b0 2019-08-08 stsp -2
391 2e1f37b0 2019-08-08 stsp +a
392 2e1f37b0 2019-08-08 stsp 3
393 2e1f37b0 2019-08-08 stsp 4
394 2e1f37b0 2019-08-08 stsp 5
395 2e1f37b0 2019-08-08 stsp -----------------------------------------------
396 2e1f37b0 2019-08-08 stsp M numbers (change 1 of 3)
397 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] n
398 2e1f37b0 2019-08-08 stsp -----------------------------------------------
399 2e1f37b0 2019-08-08 stsp @@ -4,7 +4,7 @@
400 2e1f37b0 2019-08-08 stsp 4
401 2e1f37b0 2019-08-08 stsp 5
402 2e1f37b0 2019-08-08 stsp 6
403 2e1f37b0 2019-08-08 stsp -7
404 2e1f37b0 2019-08-08 stsp +b
405 2e1f37b0 2019-08-08 stsp 8
406 2e1f37b0 2019-08-08 stsp 9
407 2e1f37b0 2019-08-08 stsp 10
408 2e1f37b0 2019-08-08 stsp -----------------------------------------------
409 2e1f37b0 2019-08-08 stsp M numbers (change 2 of 3)
410 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] n
411 2e1f37b0 2019-08-08 stsp -----------------------------------------------
412 2e1f37b0 2019-08-08 stsp @@ -13,4 +13,4 @@
413 2e1f37b0 2019-08-08 stsp 13
414 2e1f37b0 2019-08-08 stsp 14
415 2e1f37b0 2019-08-08 stsp 15
416 2e1f37b0 2019-08-08 stsp -16
417 2e1f37b0 2019-08-08 stsp +c
418 2e1f37b0 2019-08-08 stsp -----------------------------------------------
419 2e1f37b0 2019-08-08 stsp M numbers (change 3 of 3)
420 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] y
421 2e1f37b0 2019-08-08 stsp G numbers
422 2e1f37b0 2019-08-08 stsp EOF
423 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
424 2e1f37b0 2019-08-08 stsp ret="$?"
425 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
426 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
427 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
428 2e1f37b0 2019-08-08 stsp return 1
429 2e1f37b0 2019-08-08 stsp fi
430 2e1f37b0 2019-08-08 stsp
431 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
432 2e1f37b0 2019-08-08 stsp echo "MM numbers" > $testroot/stdout.expected
433 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
434 2e1f37b0 2019-08-08 stsp ret="$?"
435 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
436 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
437 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
438 2e1f37b0 2019-08-08 stsp return 1
439 2e1f37b0 2019-08-08 stsp fi
440 2e1f37b0 2019-08-08 stsp
441 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got diff -s > $testroot/stdout)
442 2e1f37b0 2019-08-08 stsp
443 2e1f37b0 2019-08-08 stsp echo "diff $commit_id $testroot/wt (staged changes)" \
444 2e1f37b0 2019-08-08 stsp > $testroot/stdout.expected
445 2e1f37b0 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
446 2e1f37b0 2019-08-08 stsp got tree -r $testroot/repo -i -c $commit_id \
447 2e1f37b0 2019-08-08 stsp | grep 'numbers$' | cut -d' ' -f 1 \
448 2e1f37b0 2019-08-08 stsp >> $testroot/stdout.expected
449 2e1f37b0 2019-08-08 stsp echo -n 'blob + ' >> $testroot/stdout.expected
450 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
451 2e1f37b0 2019-08-08 stsp >> $testroot/stdout.expected
452 2e1f37b0 2019-08-08 stsp cat >> $testroot/stdout.expected <<EOF
453 2e1f37b0 2019-08-08 stsp --- numbers
454 2e1f37b0 2019-08-08 stsp +++ numbers
455 2e1f37b0 2019-08-08 stsp @@ -1,10 +1,10 @@
456 2e1f37b0 2019-08-08 stsp 1
457 2e1f37b0 2019-08-08 stsp -2
458 2e1f37b0 2019-08-08 stsp +a
459 2e1f37b0 2019-08-08 stsp 3
460 2e1f37b0 2019-08-08 stsp 4
461 2e1f37b0 2019-08-08 stsp 5
462 2e1f37b0 2019-08-08 stsp 6
463 2e1f37b0 2019-08-08 stsp -7
464 2e1f37b0 2019-08-08 stsp +b
465 2e1f37b0 2019-08-08 stsp 8
466 2e1f37b0 2019-08-08 stsp 9
467 2e1f37b0 2019-08-08 stsp 10
468 2e1f37b0 2019-08-08 stsp EOF
469 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
470 2e1f37b0 2019-08-08 stsp ret="$?"
471 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
472 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
473 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
474 2e1f37b0 2019-08-08 stsp return 1
475 2e1f37b0 2019-08-08 stsp fi
476 2e1f37b0 2019-08-08 stsp
477 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
478 2e1f37b0 2019-08-08 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
479 2e1f37b0 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
480 4ce46740 2019-08-08 stsp (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
481 4ce46740 2019-08-08 stsp tr -d '\n' >> $testroot/stdout.expected
482 4ce46740 2019-08-08 stsp echo " (staged)" >> $testroot/stdout.expected
483 2e1f37b0 2019-08-08 stsp echo "file + numbers" >> $testroot/stdout.expected
484 2e1f37b0 2019-08-08 stsp cat >> $testroot/stdout.expected <<EOF
485 2e1f37b0 2019-08-08 stsp --- numbers
486 2e1f37b0 2019-08-08 stsp +++ numbers
487 2e1f37b0 2019-08-08 stsp @@ -13,4 +13,4 @@ b
488 2e1f37b0 2019-08-08 stsp 13
489 2e1f37b0 2019-08-08 stsp 14
490 2e1f37b0 2019-08-08 stsp 15
491 2e1f37b0 2019-08-08 stsp -16
492 2e1f37b0 2019-08-08 stsp +c
493 2e1f37b0 2019-08-08 stsp EOF
494 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
495 2e1f37b0 2019-08-08 stsp ret="$?"
496 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
497 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
498 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
499 2e1f37b0 2019-08-08 stsp return 1
500 2e1f37b0 2019-08-08 stsp fi
501 2e1f37b0 2019-08-08 stsp
502 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got stage >/dev/null)
503 2e1f37b0 2019-08-08 stsp ret="$?"
504 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
505 2e1f37b0 2019-08-08 stsp echo "got stage command failed unexpectedly" >&2
506 2e1f37b0 2019-08-08 stsp test_done "$testroot" "1"
507 2e1f37b0 2019-08-08 stsp return 1
508 2e1f37b0 2019-08-08 stsp fi
509 2e1f37b0 2019-08-08 stsp
510 ad493afc 2019-08-03 stsp (cd $testroot/wt && got status > $testroot/stdout)
511 2e1f37b0 2019-08-08 stsp echo " M numbers" > $testroot/stdout.expected
512 ad493afc 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
513 ad493afc 2019-08-03 stsp ret="$?"
514 ad493afc 2019-08-03 stsp if [ "$ret" != "0" ]; then
515 ad493afc 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
516 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
517 2e1f37b0 2019-08-08 stsp return 1
518 ad493afc 2019-08-03 stsp fi
519 2e1f37b0 2019-08-08 stsp
520 2e1f37b0 2019-08-08 stsp # unstage all hunks
521 2e1f37b0 2019-08-08 stsp printf "y\ny\ny\n" > $testroot/patchscript
522 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
523 2e1f37b0 2019-08-08 stsp numbers > $testroot/stdout)
524 2e1f37b0 2019-08-08 stsp
525 2e1f37b0 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
526 2e1f37b0 2019-08-08 stsp -----------------------------------------------
527 2e1f37b0 2019-08-08 stsp @@ -1,5 +1,5 @@
528 2e1f37b0 2019-08-08 stsp 1
529 2e1f37b0 2019-08-08 stsp -2
530 2e1f37b0 2019-08-08 stsp +a
531 2e1f37b0 2019-08-08 stsp 3
532 2e1f37b0 2019-08-08 stsp 4
533 2e1f37b0 2019-08-08 stsp 5
534 2e1f37b0 2019-08-08 stsp -----------------------------------------------
535 2e1f37b0 2019-08-08 stsp M numbers (change 1 of 3)
536 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] y
537 2e1f37b0 2019-08-08 stsp -----------------------------------------------
538 2e1f37b0 2019-08-08 stsp @@ -4,7 +4,7 @@
539 2e1f37b0 2019-08-08 stsp 4
540 2e1f37b0 2019-08-08 stsp 5
541 2e1f37b0 2019-08-08 stsp 6
542 2e1f37b0 2019-08-08 stsp -7
543 2e1f37b0 2019-08-08 stsp +b
544 2e1f37b0 2019-08-08 stsp 8
545 2e1f37b0 2019-08-08 stsp 9
546 2e1f37b0 2019-08-08 stsp 10
547 2e1f37b0 2019-08-08 stsp -----------------------------------------------
548 2e1f37b0 2019-08-08 stsp M numbers (change 2 of 3)
549 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] y
550 2e1f37b0 2019-08-08 stsp -----------------------------------------------
551 2e1f37b0 2019-08-08 stsp @@ -13,4 +13,4 @@
552 2e1f37b0 2019-08-08 stsp 13
553 2e1f37b0 2019-08-08 stsp 14
554 2e1f37b0 2019-08-08 stsp 15
555 2e1f37b0 2019-08-08 stsp -16
556 2e1f37b0 2019-08-08 stsp +c
557 2e1f37b0 2019-08-08 stsp -----------------------------------------------
558 2e1f37b0 2019-08-08 stsp M numbers (change 3 of 3)
559 2e1f37b0 2019-08-08 stsp unstage this change? [y/n/q] y
560 2e1f37b0 2019-08-08 stsp G numbers
561 2e1f37b0 2019-08-08 stsp EOF
562 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
563 2e1f37b0 2019-08-08 stsp ret="$?"
564 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
565 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
566 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
567 2e1f37b0 2019-08-08 stsp return 1
568 2e1f37b0 2019-08-08 stsp fi
569 2e1f37b0 2019-08-08 stsp
570 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
571 2e1f37b0 2019-08-08 stsp echo "M numbers" > $testroot/stdout.expected
572 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
573 2e1f37b0 2019-08-08 stsp ret="$?"
574 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
575 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
576 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
577 2e1f37b0 2019-08-08 stsp return 1
578 2e1f37b0 2019-08-08 stsp fi
579 2e1f37b0 2019-08-08 stsp
580 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got diff -s > $testroot/stdout)
581 2e1f37b0 2019-08-08 stsp echo -n > $testroot/stdout.expected
582 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
583 2e1f37b0 2019-08-08 stsp ret="$?"
584 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
585 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
586 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
587 2e1f37b0 2019-08-08 stsp return 1
588 2e1f37b0 2019-08-08 stsp fi
589 2e1f37b0 2019-08-08 stsp
590 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
591 2e1f37b0 2019-08-08 stsp
592 2e1f37b0 2019-08-08 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
593 2e1f37b0 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
594 2e1f37b0 2019-08-08 stsp got tree -r $testroot/repo -i -c $commit_id \
595 2e1f37b0 2019-08-08 stsp | grep 'numbers$' | cut -d' ' -f 1 \
596 2e1f37b0 2019-08-08 stsp >> $testroot/stdout.expected
597 2e1f37b0 2019-08-08 stsp echo 'file + numbers' >> $testroot/stdout.expected
598 2e1f37b0 2019-08-08 stsp cat >> $testroot/stdout.expected <<EOF
599 2e1f37b0 2019-08-08 stsp --- numbers
600 2e1f37b0 2019-08-08 stsp +++ numbers
601 2e1f37b0 2019-08-08 stsp @@ -1,10 +1,10 @@
602 2e1f37b0 2019-08-08 stsp 1
603 2e1f37b0 2019-08-08 stsp -2
604 2e1f37b0 2019-08-08 stsp +a
605 2e1f37b0 2019-08-08 stsp 3
606 2e1f37b0 2019-08-08 stsp 4
607 2e1f37b0 2019-08-08 stsp 5
608 2e1f37b0 2019-08-08 stsp 6
609 2e1f37b0 2019-08-08 stsp -7
610 2e1f37b0 2019-08-08 stsp +b
611 2e1f37b0 2019-08-08 stsp 8
612 2e1f37b0 2019-08-08 stsp 9
613 2e1f37b0 2019-08-08 stsp 10
614 2e1f37b0 2019-08-08 stsp @@ -13,4 +13,4 @@
615 2e1f37b0 2019-08-08 stsp 13
616 2e1f37b0 2019-08-08 stsp 14
617 2e1f37b0 2019-08-08 stsp 15
618 2e1f37b0 2019-08-08 stsp -16
619 2e1f37b0 2019-08-08 stsp +c
620 2e1f37b0 2019-08-08 stsp EOF
621 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
622 2e1f37b0 2019-08-08 stsp ret="$?"
623 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
624 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
625 2e1f37b0 2019-08-08 stsp fi
626 ad493afc 2019-08-03 stsp test_done "$testroot" "$ret"
627 2e1f37b0 2019-08-08 stsp
628 ad493afc 2019-08-03 stsp }
629 ad493afc 2019-08-03 stsp
630 2e1f37b0 2019-08-08 stsp function test_unstage_patch_added {
631 2e1f37b0 2019-08-08 stsp local testroot=`test_init unstage_patch_added`
632 2e1f37b0 2019-08-08 stsp local commit_id=`git_show_head $testroot/repo`
633 2e1f37b0 2019-08-08 stsp
634 2e1f37b0 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
635 2e1f37b0 2019-08-08 stsp ret="$?"
636 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
637 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
638 2e1f37b0 2019-08-08 stsp return 1
639 2e1f37b0 2019-08-08 stsp fi
640 2e1f37b0 2019-08-08 stsp
641 2e1f37b0 2019-08-08 stsp echo "new" > $testroot/wt/epsilon/new
642 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got add epsilon/new > /dev/null)
643 2e1f37b0 2019-08-08 stsp
644 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got stage > /dev/null)
645 2e1f37b0 2019-08-08 stsp
646 2e1f37b0 2019-08-08 stsp printf "y\n" > $testroot/patchscript
647 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
648 2e1f37b0 2019-08-08 stsp epsilon/new > $testroot/stdout)
649 2e1f37b0 2019-08-08 stsp
650 2e1f37b0 2019-08-08 stsp echo "A epsilon/new" > $testroot/stdout.expected
651 2e1f37b0 2019-08-08 stsp echo "unstage this addition? [y/n] y" >> $testroot/stdout.expected
652 2e1f37b0 2019-08-08 stsp echo "G epsilon/new" >> $testroot/stdout.expected
653 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
654 2e1f37b0 2019-08-08 stsp ret="$?"
655 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
656 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
657 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
658 2e1f37b0 2019-08-08 stsp return 1
659 2e1f37b0 2019-08-08 stsp fi
660 2e1f37b0 2019-08-08 stsp
661 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
662 2e1f37b0 2019-08-08 stsp echo "A epsilon/new" > $testroot/stdout.expected
663 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
664 2e1f37b0 2019-08-08 stsp ret="$?"
665 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
666 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
667 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
668 2e1f37b0 2019-08-08 stsp return 1
669 2e1f37b0 2019-08-08 stsp fi
670 2e1f37b0 2019-08-08 stsp
671 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got diff -s > $testroot/stdout)
672 2e1f37b0 2019-08-08 stsp echo -n > $testroot/stdout.expected
673 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
674 2e1f37b0 2019-08-08 stsp ret="$?"
675 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
676 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
677 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
678 2e1f37b0 2019-08-08 stsp return 1
679 2e1f37b0 2019-08-08 stsp fi
680 2e1f37b0 2019-08-08 stsp
681 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
682 2e1f37b0 2019-08-08 stsp
683 2e1f37b0 2019-08-08 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
684 2e1f37b0 2019-08-08 stsp echo 'blob - /dev/null' >> $testroot/stdout.expected
685 2e1f37b0 2019-08-08 stsp echo 'file + epsilon/new' >> $testroot/stdout.expected
686 2e1f37b0 2019-08-08 stsp echo "--- epsilon/new" >> $testroot/stdout.expected
687 2e1f37b0 2019-08-08 stsp echo "+++ epsilon/new" >> $testroot/stdout.expected
688 2e1f37b0 2019-08-08 stsp echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
689 2e1f37b0 2019-08-08 stsp echo "+new" >> $testroot/stdout.expected
690 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
691 2e1f37b0 2019-08-08 stsp ret="$?"
692 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
693 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
694 2e1f37b0 2019-08-08 stsp fi
695 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
696 2e1f37b0 2019-08-08 stsp }
697 2e1f37b0 2019-08-08 stsp
698 2e1f37b0 2019-08-08 stsp function test_unstage_patch_removed {
699 2e1f37b0 2019-08-08 stsp local testroot=`test_init unstage_patch_removed`
700 2e1f37b0 2019-08-08 stsp local commit_id=`git_show_head $testroot/repo`
701 2e1f37b0 2019-08-08 stsp
702 2e1f37b0 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
703 2e1f37b0 2019-08-08 stsp ret="$?"
704 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
705 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
706 2e1f37b0 2019-08-08 stsp return 1
707 2e1f37b0 2019-08-08 stsp fi
708 2e1f37b0 2019-08-08 stsp
709 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got rm beta > /dev/null)
710 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got stage > /dev/null)
711 2e1f37b0 2019-08-08 stsp
712 2e1f37b0 2019-08-08 stsp printf "y\n" > $testroot/patchscript
713 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
714 2e1f37b0 2019-08-08 stsp beta > $testroot/stdout)
715 2e1f37b0 2019-08-08 stsp
716 2e1f37b0 2019-08-08 stsp echo "D beta" > $testroot/stdout.expected
717 2e1f37b0 2019-08-08 stsp echo "unstage this deletion? [y/n] y" >> $testroot/stdout.expected
718 2e1f37b0 2019-08-08 stsp echo "D beta" >> $testroot/stdout.expected
719 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
720 2e1f37b0 2019-08-08 stsp ret="$?"
721 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
722 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
723 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
724 2e1f37b0 2019-08-08 stsp return 1
725 2e1f37b0 2019-08-08 stsp fi
726 2e1f37b0 2019-08-08 stsp
727 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
728 2e1f37b0 2019-08-08 stsp echo "D beta" > $testroot/stdout.expected
729 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
730 2e1f37b0 2019-08-08 stsp ret="$?"
731 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
732 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
733 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
734 2e1f37b0 2019-08-08 stsp return 1
735 2e1f37b0 2019-08-08 stsp fi
736 2e1f37b0 2019-08-08 stsp
737 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got diff -s > $testroot/stdout)
738 2e1f37b0 2019-08-08 stsp echo -n > $testroot/stdout.expected
739 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
740 2e1f37b0 2019-08-08 stsp ret="$?"
741 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
742 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
743 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
744 2e1f37b0 2019-08-08 stsp return 1
745 2e1f37b0 2019-08-08 stsp fi
746 2e1f37b0 2019-08-08 stsp
747 2e1f37b0 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
748 2e1f37b0 2019-08-08 stsp
749 2e1f37b0 2019-08-08 stsp echo "diff $commit_id $testroot/wt" \
750 2e1f37b0 2019-08-08 stsp > $testroot/stdout.expected
751 2e1f37b0 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
752 2e1f37b0 2019-08-08 stsp got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
753 2e1f37b0 2019-08-08 stsp >> $testroot/stdout.expected
754 2e1f37b0 2019-08-08 stsp echo 'file + /dev/null' >> $testroot/stdout.expected
755 2e1f37b0 2019-08-08 stsp echo "--- beta" >> $testroot/stdout.expected
756 2e1f37b0 2019-08-08 stsp echo "+++ beta" >> $testroot/stdout.expected
757 2e1f37b0 2019-08-08 stsp echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
758 2e1f37b0 2019-08-08 stsp echo "-beta" >> $testroot/stdout.expected
759 2e1f37b0 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
760 2e1f37b0 2019-08-08 stsp ret="$?"
761 2e1f37b0 2019-08-08 stsp if [ "$ret" != "0" ]; then
762 2e1f37b0 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
763 2e1f37b0 2019-08-08 stsp fi
764 2e1f37b0 2019-08-08 stsp test_done "$testroot" "$ret"
765 2e1f37b0 2019-08-08 stsp }
766 19e4b907 2019-08-08 stsp
767 19e4b907 2019-08-08 stsp function test_unstage_patch_quit {
768 19e4b907 2019-08-08 stsp local testroot=`test_init unstage_patch_quit`
769 19e4b907 2019-08-08 stsp
770 19e4b907 2019-08-08 stsp jot 16 > $testroot/repo/numbers
771 19e4b907 2019-08-08 stsp echo zzz > $testroot/repo/zzz
772 19e4b907 2019-08-08 stsp (cd $testroot/repo && git add numbers zzz)
773 19e4b907 2019-08-08 stsp git_commit $testroot/repo -m "added files"
774 19e4b907 2019-08-08 stsp local commit_id=`git_show_head $testroot/repo`
775 19e4b907 2019-08-08 stsp
776 19e4b907 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
777 19e4b907 2019-08-08 stsp ret="$?"
778 19e4b907 2019-08-08 stsp if [ "$ret" != "0" ]; then
779 19e4b907 2019-08-08 stsp test_done "$testroot" "$ret"
780 19e4b907 2019-08-08 stsp return 1
781 19e4b907 2019-08-08 stsp fi
782 2e1f37b0 2019-08-08 stsp
783 19e4b907 2019-08-08 stsp sed -i -e 's/^2$/a/' $testroot/wt/numbers
784 19e4b907 2019-08-08 stsp sed -i -e 's/^7$/b/' $testroot/wt/numbers
785 19e4b907 2019-08-08 stsp sed -i -e 's/^16$/c/' $testroot/wt/numbers
786 19e4b907 2019-08-08 stsp (cd $testroot/wt && got rm zzz > /dev/null)
787 19e4b907 2019-08-08 stsp (cd $testroot/wt && got stage > /dev/null)
788 19e4b907 2019-08-08 stsp
789 19e4b907 2019-08-08 stsp # unstage first hunk and quit; and don't pass a path argument to
790 19e4b907 2019-08-08 stsp # ensure that we don't skip asking about the 'zzz' file after 'quit'
791 19e4b907 2019-08-08 stsp printf "y\nq\nn\n" > $testroot/patchscript
792 19e4b907 2019-08-08 stsp (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
793 19e4b907 2019-08-08 stsp > $testroot/stdout)
794 19e4b907 2019-08-08 stsp ret="$?"
795 19e4b907 2019-08-08 stsp if [ "$ret" != "0" ]; then
796 19e4b907 2019-08-08 stsp echo "got stage command failed unexpectedly" >&2
797 19e4b907 2019-08-08 stsp test_done "$testroot" "1"
798 19e4b907 2019-08-08 stsp return 1
799 19e4b907 2019-08-08 stsp fi
800 19e4b907 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
801 19e4b907 2019-08-08 stsp -----------------------------------------------
802 19e4b907 2019-08-08 stsp @@ -1,5 +1,5 @@
803 19e4b907 2019-08-08 stsp 1
804 19e4b907 2019-08-08 stsp -2
805 19e4b907 2019-08-08 stsp +a
806 19e4b907 2019-08-08 stsp 3
807 19e4b907 2019-08-08 stsp 4
808 19e4b907 2019-08-08 stsp 5
809 19e4b907 2019-08-08 stsp -----------------------------------------------
810 19e4b907 2019-08-08 stsp M numbers (change 1 of 3)
811 19e4b907 2019-08-08 stsp unstage this change? [y/n/q] y
812 19e4b907 2019-08-08 stsp -----------------------------------------------
813 19e4b907 2019-08-08 stsp @@ -4,7 +4,7 @@
814 19e4b907 2019-08-08 stsp 4
815 19e4b907 2019-08-08 stsp 5
816 19e4b907 2019-08-08 stsp 6
817 19e4b907 2019-08-08 stsp -7
818 19e4b907 2019-08-08 stsp +b
819 19e4b907 2019-08-08 stsp 8
820 19e4b907 2019-08-08 stsp 9
821 19e4b907 2019-08-08 stsp 10
822 19e4b907 2019-08-08 stsp -----------------------------------------------
823 19e4b907 2019-08-08 stsp M numbers (change 2 of 3)
824 19e4b907 2019-08-08 stsp unstage this change? [y/n/q] q
825 19e4b907 2019-08-08 stsp G numbers
826 19e4b907 2019-08-08 stsp D zzz
827 19e4b907 2019-08-08 stsp unstage this deletion? [y/n] n
828 19e4b907 2019-08-08 stsp EOF
829 19e4b907 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
830 19e4b907 2019-08-08 stsp ret="$?"
831 19e4b907 2019-08-08 stsp if [ "$ret" != "0" ]; then
832 19e4b907 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
833 19e4b907 2019-08-08 stsp test_done "$testroot" "$ret"
834 19e4b907 2019-08-08 stsp return 1
835 19e4b907 2019-08-08 stsp fi
836 19e4b907 2019-08-08 stsp
837 19e4b907 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
838 19e4b907 2019-08-08 stsp echo "MM numbers" > $testroot/stdout.expected
839 19e4b907 2019-08-08 stsp echo " D zzz" >> $testroot/stdout.expected
840 19e4b907 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
841 19e4b907 2019-08-08 stsp ret="$?"
842 19e4b907 2019-08-08 stsp if [ "$ret" != "0" ]; then
843 19e4b907 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
844 19e4b907 2019-08-08 stsp test_done "$testroot" "$ret"
845 19e4b907 2019-08-08 stsp return 1
846 19e4b907 2019-08-08 stsp fi
847 19e4b907 2019-08-08 stsp
848 19e4b907 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
849 19e4b907 2019-08-08 stsp
850 19e4b907 2019-08-08 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
851 19e4b907 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
852 4ce46740 2019-08-08 stsp (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
853 4ce46740 2019-08-08 stsp tr -d '\n' >> $testroot/stdout.expected
854 4ce46740 2019-08-08 stsp echo " (staged)" >> $testroot/stdout.expected
855 19e4b907 2019-08-08 stsp echo "file + numbers" >> $testroot/stdout.expected
856 19e4b907 2019-08-08 stsp echo "--- numbers" >> $testroot/stdout.expected
857 19e4b907 2019-08-08 stsp echo "+++ numbers" >> $testroot/stdout.expected
858 19e4b907 2019-08-08 stsp echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
859 19e4b907 2019-08-08 stsp echo " 1" >> $testroot/stdout.expected
860 19e4b907 2019-08-08 stsp echo "-2" >> $testroot/stdout.expected
861 19e4b907 2019-08-08 stsp echo "+a" >> $testroot/stdout.expected
862 19e4b907 2019-08-08 stsp echo " 3" >> $testroot/stdout.expected
863 19e4b907 2019-08-08 stsp echo " 4" >> $testroot/stdout.expected
864 19e4b907 2019-08-08 stsp echo " 5" >> $testroot/stdout.expected
865 19e4b907 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
866 19e4b907 2019-08-08 stsp ret="$?"
867 19e4b907 2019-08-08 stsp if [ "$ret" != "0" ]; then
868 19e4b907 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
869 19e4b907 2019-08-08 stsp test_done "$testroot" "$ret"
870 19e4b907 2019-08-08 stsp return 1
871 19e4b907 2019-08-08 stsp fi
872 19e4b907 2019-08-08 stsp
873 19e4b907 2019-08-08 stsp (cd $testroot/wt && got diff -s > $testroot/stdout)
874 19e4b907 2019-08-08 stsp echo "diff $commit_id $testroot/wt (staged changes)" \
875 19e4b907 2019-08-08 stsp > $testroot/stdout.expected
876 19e4b907 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
877 19e4b907 2019-08-08 stsp got tree -r $testroot/repo -i -c $commit_id \
878 19e4b907 2019-08-08 stsp | grep 'numbers$' | cut -d' ' -f 1 \
879 19e4b907 2019-08-08 stsp >> $testroot/stdout.expected
880 19e4b907 2019-08-08 stsp echo -n 'blob + ' >> $testroot/stdout.expected
881 19e4b907 2019-08-08 stsp (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
882 19e4b907 2019-08-08 stsp >> $testroot/stdout.expected
883 19e4b907 2019-08-08 stsp cat >> $testroot/stdout.expected <<EOF
884 19e4b907 2019-08-08 stsp --- numbers
885 19e4b907 2019-08-08 stsp +++ numbers
886 19e4b907 2019-08-08 stsp @@ -4,7 +4,7 @@
887 19e4b907 2019-08-08 stsp 4
888 19e4b907 2019-08-08 stsp 5
889 19e4b907 2019-08-08 stsp 6
890 19e4b907 2019-08-08 stsp -7
891 19e4b907 2019-08-08 stsp +b
892 19e4b907 2019-08-08 stsp 8
893 19e4b907 2019-08-08 stsp 9
894 19e4b907 2019-08-08 stsp 10
895 19e4b907 2019-08-08 stsp @@ -13,4 +13,4 @@
896 19e4b907 2019-08-08 stsp 13
897 19e4b907 2019-08-08 stsp 14
898 19e4b907 2019-08-08 stsp 15
899 19e4b907 2019-08-08 stsp -16
900 19e4b907 2019-08-08 stsp +c
901 19e4b907 2019-08-08 stsp EOF
902 19e4b907 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
903 19e4b907 2019-08-08 stsp got tree -r $testroot/repo -i | grep 'zzz$' | cut -d' ' -f 1 \
904 19e4b907 2019-08-08 stsp >> $testroot/stdout.expected
905 19e4b907 2019-08-08 stsp echo 'blob + /dev/null' >> $testroot/stdout.expected
906 19e4b907 2019-08-08 stsp echo "--- zzz" >> $testroot/stdout.expected
907 19e4b907 2019-08-08 stsp echo "+++ /dev/null" >> $testroot/stdout.expected
908 19e4b907 2019-08-08 stsp echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
909 19e4b907 2019-08-08 stsp echo "-zzz" >> $testroot/stdout.expected
910 19e4b907 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
911 19e4b907 2019-08-08 stsp ret="$?"
912 19e4b907 2019-08-08 stsp if [ "$ret" != "0" ]; then
913 19e4b907 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
914 19e4b907 2019-08-08 stsp fi
915 19e4b907 2019-08-08 stsp test_done "$testroot" "$ret"
916 19e4b907 2019-08-08 stsp }
917 19e4b907 2019-08-08 stsp
918 ad493afc 2019-08-03 stsp run_test test_unstage_basic
919 8b13ce36 2019-08-08 stsp run_test test_unstage_unversioned
920 2e1f37b0 2019-08-08 stsp run_test test_unstage_patch
921 2e1f37b0 2019-08-08 stsp run_test test_unstage_patch_added
922 2e1f37b0 2019-08-08 stsp run_test test_unstage_patch_removed
923 19e4b907 2019-08-08 stsp run_test test_unstage_patch_quit