3 95adcdca 2019-03-27 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 95adcdca 2019-03-27 stsp . ./common.sh
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`
23 95adcdca 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
25 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
26 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
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)
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
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
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"
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)
73 2a06fe5f 2019-08-24 stsp echo -n > $testroot/stdout.expected
74 2a06fe5f 2019-08-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
86 2a06fe5f 2019-08-24 stsp if [ "$ret" != "0" ]; then
87 2a06fe5f 2019-08-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
89 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
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`
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`
107 95adcdca 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
109 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
110 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
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`
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
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
127 95adcdca 2019-03-27 stsp (cd $testroot/wt && got update > $testroot/stdout)
129 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
170 95adcdca 2019-03-27 stsp (cd $testroot/wt && got diff > $testroot/stdout)
172 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
174 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
175 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
177 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
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
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`
190 d24820bf 2019-08-11 stsp (cd $testroot/repo && git tag -m "test" $tag1)
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`
197 d24820bf 2019-08-11 stsp (cd $testroot/repo && git tag -m "test" $tag2)
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
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
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"
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
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
235 d24820bf 2019-08-11 stsp if [ "$ret" != "0" ]; then
236 d24820bf 2019-08-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
238 d24820bf 2019-08-11 stsp test_done "$testroot" "$ret"
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`
245 63035f9f 2019-10-06 stsp got checkout $testroot/repo $testroot/wt > /dev/null
247 63035f9f 2019-10-06 stsp if [ "$ret" != "0" ]; then
248 63035f9f 2019-10-06 stsp test_done "$testroot" "$ret"
252 63035f9f 2019-10-06 stsp echo "alpha " > $testroot/wt/alpha
254 63035f9f 2019-10-06 stsp (cd $testroot/wt && got diff -w > $testroot/stdout)
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
262 63035f9f 2019-10-06 stsp cmp -s $testroot/stdout.expected $testroot/stdout
264 63035f9f 2019-10-06 stsp if [ "$ret" != "0" ]; then
265 63035f9f 2019-10-06 stsp diff -u $testroot/stdout.expected $testroot/stdout
267 63035f9f 2019-10-06 stsp test_done "$testroot" "$ret"
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