Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 function test_stage_basic {
20 local testroot=`test_init stage_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "modified file" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta > /dev/null)
31 echo "new file" > $testroot/wt/foo
32 (cd $testroot/wt && got add foo > /dev/null)
34 echo ' M alpha' > $testroot/stdout.expected
35 echo ' D beta' >> $testroot/stdout.expected
36 echo ' A foo' >> $testroot/stdout.expected
37 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
39 cmp -s $testroot/stdout.expected $testroot/stdout
40 ret="$?"
41 if [ "$ret" != "0" ]; then
42 diff -u $testroot/stdout.expected $testroot/stdout
43 fi
44 test_done "$testroot" "$ret"
45 }
47 function test_stage_status {
48 local testroot=`test_init stage_status`
50 got checkout $testroot/repo $testroot/wt > /dev/null
51 ret="$?"
52 if [ "$ret" != "0" ]; then
53 test_done "$testroot" "$ret"
54 return 1
55 fi
57 echo "modified file" > $testroot/wt/alpha
58 (cd $testroot/wt && got rm beta > /dev/null)
59 echo "new file" > $testroot/wt/foo
60 (cd $testroot/wt && got add foo > /dev/null)
61 echo "new file" > $testroot/wt/epsilon/new
62 (cd $testroot/wt && got add epsilon/new > /dev/null)
63 echo "modified file" > $testroot/wt/epsilon/zeta
64 (cd $testroot/wt && got rm gamma/delta > /dev/null)
66 echo ' M alpha' > $testroot/stdout.expected
67 echo ' D beta' >> $testroot/stdout.expected
68 echo 'A epsilon/new' >> $testroot/stdout.expected
69 echo 'M epsilon/zeta' >> $testroot/stdout.expected
70 echo ' A foo' >> $testroot/stdout.expected
71 echo 'D gamma/delta' >> $testroot/stdout.expected
72 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
74 (cd $testroot/wt && got status > $testroot/stdout)
75 cmp -s $testroot/stdout.expected $testroot/stdout
76 ret="$?"
77 if [ "$ret" != "0" ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
80 return 1
81 fi
83 echo "modified file again" >> $testroot/wt/alpha
84 echo "modified added file again" >> $testroot/wt/foo
86 echo 'MM alpha' > $testroot/stdout.expected
87 echo ' D beta' >> $testroot/stdout.expected
88 echo 'A epsilon/new' >> $testroot/stdout.expected
89 echo 'M epsilon/zeta' >> $testroot/stdout.expected
90 echo 'MA foo' >> $testroot/stdout.expected
91 echo 'D gamma/delta' >> $testroot/stdout.expected
93 (cd $testroot/wt && got status > $testroot/stdout)
94 cmp -s $testroot/stdout.expected $testroot/stdout
95 ret="$?"
96 if [ "$ret" != "0" ]; then
97 diff -u $testroot/stdout.expected $testroot/stdout
98 test_done "$testroot" "$ret"
99 return 1
100 fi
102 # test no-op change of added file with new stat(2) timestamp
103 echo "new file" > $testroot/wt/foo
104 echo ' A foo' > $testroot/stdout.expected
105 (cd $testroot/wt && got status foo > $testroot/stdout)
106 cmp -s $testroot/stdout.expected $testroot/stdout
107 ret="$?"
108 if [ "$ret" != "0" ]; then
109 diff -u $testroot/stdout.expected $testroot/stdout
110 test_done "$testroot" "$ret"
111 return 1
112 fi
114 # test staged deleted file which is restored on disk
115 echo "new file" > $testroot/wt/beta
116 echo ' D beta' > $testroot/stdout.expected
117 (cd $testroot/wt && got status beta > $testroot/stdout)
118 cmp -s $testroot/stdout.expected $testroot/stdout
119 ret="$?"
120 if [ "$ret" != "0" ]; then
121 diff -u $testroot/stdout.expected $testroot/stdout
122 fi
123 test_done "$testroot" "$ret"
127 function test_stage_add_already_staged_file {
128 local testroot=`test_init stage_add_already_staged_file`
130 got checkout $testroot/repo $testroot/wt > /dev/null
131 ret="$?"
132 if [ "$ret" != "0" ]; then
133 test_done "$testroot" "$ret"
134 return 1
135 fi
137 echo "modified file" > $testroot/wt/alpha
138 (cd $testroot/wt && got rm beta > /dev/null)
139 echo "new file" > $testroot/wt/foo
140 (cd $testroot/wt && got add foo > /dev/null)
142 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
144 (cd $testroot/wt && got add beta \
145 > $testroot/stdout 2> $testroot/stderr)
146 ret="$?"
147 if [ "$ret" == "0" ]; then
148 echo "got add command succeeded unexpectedly" >&2
149 test_done "$testroot" "1"
150 return 1
151 fi
152 echo "got: realpath: beta: No such file or directory" \
153 > $testroot/stderr.expected
154 cmp -s $testroot/stderr.expected $testroot/stderr
155 ret="$?"
156 if [ "$ret" != "0" ]; then
157 diff -u $testroot/stderr.expected $testroot/stderr
158 test_done "$testroot" "$ret"
159 return 1
160 fi
162 echo -n > $testroot/stdout.expected
163 for f in alpha foo; do
164 (cd $testroot/wt && got add $f \
165 > $testroot/stdout 2> $testroot/stderr)
166 ret="$?"
167 if [ "$ret" != "0" ]; then
168 echo "got add command failed unexpectedly" >&2
169 test_done "$testroot" "1"
170 return 1
171 fi
172 cmp -s $testroot/stdout.expected $testroot/stdout
173 ret="$?"
174 if [ "$ret" != "0" ]; then
175 diff -u $testroot/stdout.expected $testroot/stdout
176 test_done "$testroot" "$ret"
177 return 1
178 fi
179 done
181 echo ' M alpha' > $testroot/stdout.expected
182 echo ' D beta' >> $testroot/stdout.expected
183 echo ' A foo' >> $testroot/stdout.expected
185 (cd $testroot/wt && got status > $testroot/stdout)
186 cmp -s $testroot/stdout.expected $testroot/stdout
187 ret="$?"
188 if [ "$ret" != "0" ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
190 fi
191 test_done "$testroot" "$ret"
194 function test_stage_rm_already_staged_file {
195 local testroot=`test_init stage_rm_already_staged_file`
197 got checkout $testroot/repo $testroot/wt > /dev/null
198 ret="$?"
199 if [ "$ret" != "0" ]; then
200 test_done "$testroot" "$ret"
201 return 1
202 fi
204 echo "modified file" > $testroot/wt/alpha
205 (cd $testroot/wt && got rm beta > /dev/null)
206 echo "new file" > $testroot/wt/foo
207 (cd $testroot/wt && got add foo > /dev/null)
209 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
211 (cd $testroot/wt && got rm beta \
212 > $testroot/stdout 2> $testroot/stderr)
213 ret="$?"
214 if [ "$ret" == "0" ]; then
215 echo "got rm command succeeded unexpectedly" >&2
216 test_done "$testroot" "1"
217 return 1
218 fi
219 echo "got: realpath: beta: No such file or directory" \
220 > $testroot/stderr.expected
221 cmp -s $testroot/stderr.expected $testroot/stderr
222 ret="$?"
223 if [ "$ret" != "0" ]; then
224 diff -u $testroot/stderr.expected $testroot/stderr
225 test_done "$testroot" "$ret"
226 return 1
227 fi
229 for f in alpha foo; do
230 echo "got: $f: file has staged changes" \
231 > $testroot/stderr.expected
232 (cd $testroot/wt && got rm $f \
233 > $testroot/stdout 2> $testroot/stderr)
234 ret="$?"
235 if [ "$ret" == "0" ]; then
236 echo "got rm command succeeded unexpectedly" >&2
237 test_done "$testroot" "1"
238 return 1
239 fi
240 cmp -s $testroot/stderr.expected $testroot/stderr
241 ret="$?"
242 if [ "$ret" != "0" ]; then
243 diff -u $testroot/stderr.expected $testroot/stderr
244 test_done "$testroot" "$ret"
245 return 1
246 fi
247 done
249 echo ' M alpha' > $testroot/stdout.expected
250 echo ' D beta' >> $testroot/stdout.expected
251 echo ' A foo' >> $testroot/stdout.expected
253 (cd $testroot/wt && got status > $testroot/stdout)
254 cmp -s $testroot/stdout.expected $testroot/stdout
255 ret="$?"
256 if [ "$ret" != "0" ]; then
257 diff -u $testroot/stdout.expected $testroot/stdout
258 fi
259 test_done "$testroot" "$ret"
262 run_test test_stage_basic
263 run_test test_stage_status
264 run_test test_stage_add_already_staged_file
265 run_test test_stage_rm_already_staged_file