Blame


1 95adcdca 2019-03-27 stsp #!/bin/sh
2 95adcdca 2019-03-27 stsp #
3 95adcdca 2019-03-27 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 95adcdca 2019-03-27 stsp #
5 95adcdca 2019-03-27 stsp # Permission to use, copy, modify, and distribute this software for any
6 95adcdca 2019-03-27 stsp # purpose with or without fee is hereby granted, provided that the above
7 95adcdca 2019-03-27 stsp # copyright notice and this permission notice appear in all copies.
8 95adcdca 2019-03-27 stsp #
9 95adcdca 2019-03-27 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 95adcdca 2019-03-27 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 95adcdca 2019-03-27 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 95adcdca 2019-03-27 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 95adcdca 2019-03-27 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 95adcdca 2019-03-27 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 95adcdca 2019-03-27 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 95adcdca 2019-03-27 stsp
17 95adcdca 2019-03-27 stsp . ./common.sh
18 95adcdca 2019-03-27 stsp
19 95adcdca 2019-03-27 stsp function test_diff_basic {
20 95adcdca 2019-03-27 stsp local testroot=`test_init diff_basic`
21 95adcdca 2019-03-27 stsp local head_rev=`git_show_head $testroot/repo`
22 95adcdca 2019-03-27 stsp
23 95adcdca 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
24 95adcdca 2019-03-27 stsp ret="$?"
25 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
26 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
27 95adcdca 2019-03-27 stsp return 1
28 95adcdca 2019-03-27 stsp fi
29 95adcdca 2019-03-27 stsp
30 95adcdca 2019-03-27 stsp echo "modified alpha" > $testroot/wt/alpha
31 95adcdca 2019-03-27 stsp (cd $testroot/wt && got rm beta >/dev/null)
32 95adcdca 2019-03-27 stsp echo "new file" > $testroot/wt/new
33 95adcdca 2019-03-27 stsp (cd $testroot/wt && got add new >/dev/null)
34 95adcdca 2019-03-27 stsp
35 95adcdca 2019-03-27 stsp echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
36 95adcdca 2019-03-27 stsp echo -n 'blob - ' >> $testroot/stdout.expected
37 95adcdca 2019-03-27 stsp got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
38 95adcdca 2019-03-27 stsp >> $testroot/stdout.expected
39 95adcdca 2019-03-27 stsp echo 'file + alpha' >> $testroot/stdout.expected
40 95adcdca 2019-03-27 stsp echo '--- alpha' >> $testroot/stdout.expected
41 95adcdca 2019-03-27 stsp echo '+++ alpha' >> $testroot/stdout.expected
42 95adcdca 2019-03-27 stsp echo '@@ -1 +1 @@' >> $testroot/stdout.expected
43 95adcdca 2019-03-27 stsp echo '-alpha' >> $testroot/stdout.expected
44 95adcdca 2019-03-27 stsp echo '+modified alpha' >> $testroot/stdout.expected
45 95adcdca 2019-03-27 stsp echo -n 'blob - ' >> $testroot/stdout.expected
46 95adcdca 2019-03-27 stsp got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
47 95adcdca 2019-03-27 stsp >> $testroot/stdout.expected
48 95adcdca 2019-03-27 stsp echo 'file + /dev/null' >> $testroot/stdout.expected
49 95adcdca 2019-03-27 stsp echo '--- beta' >> $testroot/stdout.expected
50 95adcdca 2019-03-27 stsp echo '+++ beta' >> $testroot/stdout.expected
51 95adcdca 2019-03-27 stsp echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
52 95adcdca 2019-03-27 stsp echo '-beta' >> $testroot/stdout.expected
53 95adcdca 2019-03-27 stsp echo 'blob - /dev/null' >> $testroot/stdout.expected
54 95adcdca 2019-03-27 stsp echo 'file + new' >> $testroot/stdout.expected
55 95adcdca 2019-03-27 stsp echo '--- new' >> $testroot/stdout.expected
56 95adcdca 2019-03-27 stsp echo '+++ new' >> $testroot/stdout.expected
57 95adcdca 2019-03-27 stsp echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
58 95adcdca 2019-03-27 stsp echo '+new file' >> $testroot/stdout.expected
59 95adcdca 2019-03-27 stsp
60 95adcdca 2019-03-27 stsp (cd $testroot/wt && got diff > $testroot/stdout)
61 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
62 95adcdca 2019-03-27 stsp ret="$?"
63 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
64 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
65 2a06fe5f 2019-08-24 stsp test_done "$testroot" "$ret"
66 2a06fe5f 2019-08-24 stsp return 1
67 95adcdca 2019-03-27 stsp fi
68 2a06fe5f 2019-08-24 stsp
69 2a06fe5f 2019-08-24 stsp # diff non-existent path
70 2a06fe5f 2019-08-24 stsp (cd $testroot/wt && got diff nonexistent > $testroot/stdout \
71 2a06fe5f 2019-08-24 stsp 2> $testroot/stderr)
72 2a06fe5f 2019-08-24 stsp
73 2a06fe5f 2019-08-24 stsp echo -n > $testroot/stdout.expected
74 2a06fe5f 2019-08-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
75 2a06fe5f 2019-08-24 stsp ret="$?"
76 2a06fe5f 2019-08-24 stsp if [ "$ret" != "0" ]; then
77 2a06fe5f 2019-08-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
78 2a06fe5f 2019-08-24 stsp test_done "$testroot" "$ret"
79 2a06fe5f 2019-08-24 stsp return 1
80 2a06fe5f 2019-08-24 stsp fi
81 2a06fe5f 2019-08-24 stsp
82 2a06fe5f 2019-08-24 stsp echo "got: nonexistent: No such file or directory" \
83 2a06fe5f 2019-08-24 stsp > $testroot/stderr.expected
84 2a06fe5f 2019-08-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
85 2a06fe5f 2019-08-24 stsp ret="$?"
86 2a06fe5f 2019-08-24 stsp if [ "$ret" != "0" ]; then
87 2a06fe5f 2019-08-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
88 2a06fe5f 2019-08-24 stsp fi
89 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
90 95adcdca 2019-03-27 stsp }
91 95adcdca 2019-03-27 stsp
92 95adcdca 2019-03-27 stsp function test_diff_shows_conflict {
93 95adcdca 2019-03-27 stsp local testroot=`test_init diff_shows_conflict 1`
94 95adcdca 2019-03-27 stsp
95 95adcdca 2019-03-27 stsp echo "1" > $testroot/repo/numbers
96 95adcdca 2019-03-27 stsp echo "2" >> $testroot/repo/numbers
97 95adcdca 2019-03-27 stsp echo "3" >> $testroot/repo/numbers
98 95adcdca 2019-03-27 stsp echo "4" >> $testroot/repo/numbers
99 95adcdca 2019-03-27 stsp echo "5" >> $testroot/repo/numbers
100 95adcdca 2019-03-27 stsp echo "6" >> $testroot/repo/numbers
101 95adcdca 2019-03-27 stsp echo "7" >> $testroot/repo/numbers
102 95adcdca 2019-03-27 stsp echo "8" >> $testroot/repo/numbers
103 95adcdca 2019-03-27 stsp (cd $testroot/repo && git add numbers)
104 95adcdca 2019-03-27 stsp git_commit $testroot/repo -m "added numbers file"
105 f69721c3 2019-10-21 stsp local base_commit=`git_show_head $testroot/repo`
106 95adcdca 2019-03-27 stsp
107 95adcdca 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
108 95adcdca 2019-03-27 stsp ret="$?"
109 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
110 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
111 95adcdca 2019-03-27 stsp return 1
112 95adcdca 2019-03-27 stsp fi
113 95adcdca 2019-03-27 stsp
114 95adcdca 2019-03-27 stsp sed -i 's/2/22/' $testroot/repo/numbers
115 d136cfcb 2019-10-12 stsp sed -i 's/8/33/' $testroot/repo/numbers
116 95adcdca 2019-03-27 stsp git_commit $testroot/repo -m "modified line 2"
117 95adcdca 2019-03-27 stsp local head_rev=`git_show_head $testroot/repo`
118 95adcdca 2019-03-27 stsp
119 d136cfcb 2019-10-12 stsp # modify lines 2 and 8 in conflicting ways
120 95adcdca 2019-03-27 stsp sed -i 's/2/77/' $testroot/wt/numbers
121 d136cfcb 2019-10-12 stsp sed -i 's/8/88/' $testroot/wt/numbers
122 95adcdca 2019-03-27 stsp
123 95adcdca 2019-03-27 stsp echo "C numbers" > $testroot/stdout.expected
124 95adcdca 2019-03-27 stsp echo -n "Updated to commit $head_rev" >> $testroot/stdout.expected
125 95adcdca 2019-03-27 stsp echo >> $testroot/stdout.expected
126 95adcdca 2019-03-27 stsp
127 95adcdca 2019-03-27 stsp (cd $testroot/wt && got update > $testroot/stdout)
128 95adcdca 2019-03-27 stsp
129 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
130 95adcdca 2019-03-27 stsp ret="$?"
131 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
132 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
133 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
134 95adcdca 2019-03-27 stsp return 1
135 95adcdca 2019-03-27 stsp fi
136 95adcdca 2019-03-27 stsp
137 95adcdca 2019-03-27 stsp echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
138 95adcdca 2019-03-27 stsp echo -n 'blob - ' >> $testroot/stdout.expected
139 95adcdca 2019-03-27 stsp got tree -r $testroot/repo -i | grep 'numbers$' | cut -d' ' -f 1 \
140 95adcdca 2019-03-27 stsp >> $testroot/stdout.expected
141 95adcdca 2019-03-27 stsp echo 'file + numbers' >> $testroot/stdout.expected
142 95adcdca 2019-03-27 stsp echo '--- numbers' >> $testroot/stdout.expected
143 95adcdca 2019-03-27 stsp echo '+++ numbers' >> $testroot/stdout.expected
144 d136cfcb 2019-10-12 stsp echo '@@ -1,8 +1,20 @@' >> $testroot/stdout.expected
145 95adcdca 2019-03-27 stsp echo ' 1' >> $testroot/stdout.expected
146 f69721c3 2019-10-21 stsp echo "+<<<<<<< merged change: commit $head_rev" \
147 f69721c3 2019-10-21 stsp >> $testroot/stdout.expected
148 95adcdca 2019-03-27 stsp echo ' 22' >> $testroot/stdout.expected
149 f69721c3 2019-10-21 stsp echo "+||||||| 3-way merge base: commit $base_commit" \
150 f69721c3 2019-10-21 stsp >> $testroot/stdout.expected
151 d136cfcb 2019-10-12 stsp echo '+2' >> $testroot/stdout.expected
152 95adcdca 2019-03-27 stsp echo '+=======' >> $testroot/stdout.expected
153 95adcdca 2019-03-27 stsp echo '+77' >> $testroot/stdout.expected
154 f69721c3 2019-10-21 stsp echo '+>>>>>>>' >> $testroot/stdout.expected
155 95adcdca 2019-03-27 stsp echo ' 3' >> $testroot/stdout.expected
156 95adcdca 2019-03-27 stsp echo ' 4' >> $testroot/stdout.expected
157 95adcdca 2019-03-27 stsp echo ' 5' >> $testroot/stdout.expected
158 d136cfcb 2019-10-12 stsp echo ' 6' >> $testroot/stdout.expected
159 d136cfcb 2019-10-12 stsp echo ' 7' >> $testroot/stdout.expected
160 f69721c3 2019-10-21 stsp echo "+<<<<<<< merged change: commit $head_rev" \
161 f69721c3 2019-10-21 stsp >> $testroot/stdout.expected
162 d136cfcb 2019-10-12 stsp echo ' 33' >> $testroot/stdout.expected
163 f69721c3 2019-10-21 stsp echo "+||||||| 3-way merge base: commit $base_commit" \
164 f69721c3 2019-10-21 stsp >> $testroot/stdout.expected
165 d136cfcb 2019-10-12 stsp echo '+8' >> $testroot/stdout.expected
166 d136cfcb 2019-10-12 stsp echo '+=======' >> $testroot/stdout.expected
167 d136cfcb 2019-10-12 stsp echo '+88' >> $testroot/stdout.expected
168 f69721c3 2019-10-21 stsp echo '+>>>>>>>' >> $testroot/stdout.expected
169 95adcdca 2019-03-27 stsp
170 95adcdca 2019-03-27 stsp (cd $testroot/wt && got diff > $testroot/stdout)
171 95adcdca 2019-03-27 stsp
172 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
173 95adcdca 2019-03-27 stsp ret="$?"
174 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
175 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
176 95adcdca 2019-03-27 stsp fi
177 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
178 95adcdca 2019-03-27 stsp }
179 95adcdca 2019-03-27 stsp
180 d24820bf 2019-08-11 stsp function test_diff_tag {
181 d24820bf 2019-08-11 stsp local testroot=`test_init diff_tag`
182 d24820bf 2019-08-11 stsp local commit_id0=`git_show_head $testroot/repo`
183 d24820bf 2019-08-11 stsp local tag1=1.0.0
184 d24820bf 2019-08-11 stsp local tag2=2.0.0
185 d24820bf 2019-08-11 stsp
186 d24820bf 2019-08-11 stsp echo "modified alpha" > $testroot/repo/alpha
187 d24820bf 2019-08-11 stsp git_commit $testroot/repo -m "changed alpha"
188 d24820bf 2019-08-11 stsp local commit_id1=`git_show_head $testroot/repo`
189 d24820bf 2019-08-11 stsp
190 d24820bf 2019-08-11 stsp (cd $testroot/repo && git tag -m "test" $tag1)
191 d24820bf 2019-08-11 stsp
192 d24820bf 2019-08-11 stsp echo "new file" > $testroot/repo/new
193 d24820bf 2019-08-11 stsp (cd $testroot/repo && git add new)
194 d24820bf 2019-08-11 stsp git_commit $testroot/repo -m "new file"
195 d24820bf 2019-08-11 stsp local commit_id2=`git_show_head $testroot/repo`
196 d24820bf 2019-08-11 stsp
197 d24820bf 2019-08-11 stsp (cd $testroot/repo && git tag -m "test" $tag2)
198 d24820bf 2019-08-11 stsp
199 d24820bf 2019-08-11 stsp echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
200 d24820bf 2019-08-11 stsp echo -n 'blob - ' >> $testroot/stdout.expected
201 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
202 d24820bf 2019-08-11 stsp cut -d' ' -f 1 >> $testroot/stdout.expected
203 d24820bf 2019-08-11 stsp echo -n 'blob + ' >> $testroot/stdout.expected
204 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
205 d24820bf 2019-08-11 stsp >> $testroot/stdout.expected
206 d24820bf 2019-08-11 stsp echo '--- alpha' >> $testroot/stdout.expected
207 d24820bf 2019-08-11 stsp echo '+++ alpha' >> $testroot/stdout.expected
208 d24820bf 2019-08-11 stsp echo '@@ -1 +1 @@' >> $testroot/stdout.expected
209 d24820bf 2019-08-11 stsp echo '-alpha' >> $testroot/stdout.expected
210 d24820bf 2019-08-11 stsp echo '+modified alpha' >> $testroot/stdout.expected
211 d24820bf 2019-08-11 stsp
212 d24820bf 2019-08-11 stsp got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
213 d24820bf 2019-08-11 stsp cmp -s $testroot/stdout.expected $testroot/stdout
214 d24820bf 2019-08-11 stsp ret="$?"
215 d24820bf 2019-08-11 stsp if [ "$ret" != "0" ]; then
216 d24820bf 2019-08-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
217 d24820bf 2019-08-11 stsp test_done "$testroot" "$ret"
218 d24820bf 2019-08-11 stsp return 1
219 d24820bf 2019-08-11 stsp fi
220 d24820bf 2019-08-11 stsp
221 d24820bf 2019-08-11 stsp echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
222 d24820bf 2019-08-11 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
223 d24820bf 2019-08-11 stsp echo -n 'blob + ' >> $testroot/stdout.expected
224 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
225 46f68b20 2019-10-19 stsp cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
226 46f68b20 2019-10-19 stsp echo " (mode 644)" >> $testroot/stdout.expected
227 d24820bf 2019-08-11 stsp echo '--- /dev/null' >> $testroot/stdout.expected
228 d24820bf 2019-08-11 stsp echo '+++ new' >> $testroot/stdout.expected
229 d24820bf 2019-08-11 stsp echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
230 d24820bf 2019-08-11 stsp echo '+new file' >> $testroot/stdout.expected
231 d24820bf 2019-08-11 stsp
232 d24820bf 2019-08-11 stsp got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
233 d24820bf 2019-08-11 stsp cmp -s $testroot/stdout.expected $testroot/stdout
234 d24820bf 2019-08-11 stsp ret="$?"
235 d24820bf 2019-08-11 stsp if [ "$ret" != "0" ]; then
236 d24820bf 2019-08-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
237 d24820bf 2019-08-11 stsp fi
238 d24820bf 2019-08-11 stsp test_done "$testroot" "$ret"
239 d24820bf 2019-08-11 stsp }
240 d24820bf 2019-08-11 stsp
241 63035f9f 2019-10-06 stsp function test_diff_ignore_whitespace {
242 63035f9f 2019-10-06 stsp local testroot=`test_init diff_ignore_whitespace`
243 63035f9f 2019-10-06 stsp local commit_id0=`git_show_head $testroot/repo`
244 63035f9f 2019-10-06 stsp
245 63035f9f 2019-10-06 stsp got checkout $testroot/repo $testroot/wt > /dev/null
246 63035f9f 2019-10-06 stsp ret="$?"
247 63035f9f 2019-10-06 stsp if [ "$ret" != "0" ]; then
248 63035f9f 2019-10-06 stsp test_done "$testroot" "$ret"
249 63035f9f 2019-10-06 stsp return 1
250 63035f9f 2019-10-06 stsp fi
251 63035f9f 2019-10-06 stsp
252 63035f9f 2019-10-06 stsp echo "alpha " > $testroot/wt/alpha
253 63035f9f 2019-10-06 stsp
254 63035f9f 2019-10-06 stsp (cd $testroot/wt && got diff -w > $testroot/stdout)
255 63035f9f 2019-10-06 stsp
256 63035f9f 2019-10-06 stsp echo "diff $commit_id0 $testroot/wt" > $testroot/stdout.expected
257 63035f9f 2019-10-06 stsp echo -n 'blob - ' >> $testroot/stdout.expected
258 63035f9f 2019-10-06 stsp got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
259 63035f9f 2019-10-06 stsp cut -d' ' -f 1 >> $testroot/stdout.expected
260 63035f9f 2019-10-06 stsp echo 'file + alpha' >> $testroot/stdout.expected
261 63035f9f 2019-10-06 stsp
262 63035f9f 2019-10-06 stsp cmp -s $testroot/stdout.expected $testroot/stdout
263 63035f9f 2019-10-06 stsp ret="$?"
264 63035f9f 2019-10-06 stsp if [ "$ret" != "0" ]; then
265 63035f9f 2019-10-06 stsp diff -u $testroot/stdout.expected $testroot/stdout
266 63035f9f 2019-10-06 stsp fi
267 63035f9f 2019-10-06 stsp test_done "$testroot" "$ret"
268 63035f9f 2019-10-06 stsp }
269 63035f9f 2019-10-06 stsp
270 95adcdca 2019-03-27 stsp run_test test_diff_basic
271 95adcdca 2019-03-27 stsp run_test test_diff_shows_conflict
272 d24820bf 2019-08-11 stsp run_test test_diff_tag
273 63035f9f 2019-10-06 stsp run_test test_diff_ignore_whitespace