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 95adcdca 2019-03-27 stsp
106 95adcdca 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
107 95adcdca 2019-03-27 stsp ret="$?"
108 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
109 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
110 95adcdca 2019-03-27 stsp return 1
111 95adcdca 2019-03-27 stsp fi
112 95adcdca 2019-03-27 stsp
113 95adcdca 2019-03-27 stsp sed -i 's/2/22/' $testroot/repo/numbers
114 95adcdca 2019-03-27 stsp git_commit $testroot/repo -m "modified line 2"
115 95adcdca 2019-03-27 stsp local head_rev=`git_show_head $testroot/repo`
116 95adcdca 2019-03-27 stsp
117 95adcdca 2019-03-27 stsp # modify line 2 in a conflicting way
118 95adcdca 2019-03-27 stsp sed -i 's/2/77/' $testroot/wt/numbers
119 95adcdca 2019-03-27 stsp
120 95adcdca 2019-03-27 stsp echo "C numbers" > $testroot/stdout.expected
121 95adcdca 2019-03-27 stsp echo -n "Updated to commit $head_rev" >> $testroot/stdout.expected
122 95adcdca 2019-03-27 stsp echo >> $testroot/stdout.expected
123 95adcdca 2019-03-27 stsp
124 95adcdca 2019-03-27 stsp (cd $testroot/wt && got update > $testroot/stdout)
125 95adcdca 2019-03-27 stsp
126 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
127 95adcdca 2019-03-27 stsp ret="$?"
128 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
129 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
130 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
131 95adcdca 2019-03-27 stsp return 1
132 95adcdca 2019-03-27 stsp fi
133 95adcdca 2019-03-27 stsp
134 95adcdca 2019-03-27 stsp echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
135 95adcdca 2019-03-27 stsp echo -n 'blob - ' >> $testroot/stdout.expected
136 95adcdca 2019-03-27 stsp got tree -r $testroot/repo -i | grep 'numbers$' | cut -d' ' -f 1 \
137 95adcdca 2019-03-27 stsp >> $testroot/stdout.expected
138 95adcdca 2019-03-27 stsp echo 'file + numbers' >> $testroot/stdout.expected
139 95adcdca 2019-03-27 stsp echo '--- numbers' >> $testroot/stdout.expected
140 95adcdca 2019-03-27 stsp echo '+++ numbers' >> $testroot/stdout.expected
141 95adcdca 2019-03-27 stsp echo '@@ -1,5 +1,9 @@' >> $testroot/stdout.expected
142 95adcdca 2019-03-27 stsp echo ' 1' >> $testroot/stdout.expected
143 95adcdca 2019-03-27 stsp echo "+<<<<<<< commit $head_rev" >> $testroot/stdout.expected
144 95adcdca 2019-03-27 stsp echo ' 22' >> $testroot/stdout.expected
145 95adcdca 2019-03-27 stsp echo '+=======' >> $testroot/stdout.expected
146 95adcdca 2019-03-27 stsp echo '+77' >> $testroot/stdout.expected
147 95adcdca 2019-03-27 stsp echo '+>>>>>>> numbers' >> $testroot/stdout.expected
148 95adcdca 2019-03-27 stsp echo ' 3' >> $testroot/stdout.expected
149 95adcdca 2019-03-27 stsp echo ' 4' >> $testroot/stdout.expected
150 95adcdca 2019-03-27 stsp echo ' 5' >> $testroot/stdout.expected
151 95adcdca 2019-03-27 stsp
152 95adcdca 2019-03-27 stsp (cd $testroot/wt && got diff > $testroot/stdout)
153 95adcdca 2019-03-27 stsp
154 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
155 95adcdca 2019-03-27 stsp ret="$?"
156 95adcdca 2019-03-27 stsp if [ "$ret" != "0" ]; then
157 95adcdca 2019-03-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
158 95adcdca 2019-03-27 stsp fi
159 95adcdca 2019-03-27 stsp test_done "$testroot" "$ret"
160 95adcdca 2019-03-27 stsp }
161 95adcdca 2019-03-27 stsp
162 d24820bf 2019-08-11 stsp function test_diff_tag {
163 d24820bf 2019-08-11 stsp local testroot=`test_init diff_tag`
164 d24820bf 2019-08-11 stsp local commit_id0=`git_show_head $testroot/repo`
165 d24820bf 2019-08-11 stsp local tag1=1.0.0
166 d24820bf 2019-08-11 stsp local tag2=2.0.0
167 d24820bf 2019-08-11 stsp
168 d24820bf 2019-08-11 stsp echo "modified alpha" > $testroot/repo/alpha
169 d24820bf 2019-08-11 stsp git_commit $testroot/repo -m "changed alpha"
170 d24820bf 2019-08-11 stsp local commit_id1=`git_show_head $testroot/repo`
171 d24820bf 2019-08-11 stsp
172 d24820bf 2019-08-11 stsp (cd $testroot/repo && git tag -m "test" $tag1)
173 d24820bf 2019-08-11 stsp
174 d24820bf 2019-08-11 stsp echo "new file" > $testroot/repo/new
175 d24820bf 2019-08-11 stsp (cd $testroot/repo && git add new)
176 d24820bf 2019-08-11 stsp git_commit $testroot/repo -m "new file"
177 d24820bf 2019-08-11 stsp local commit_id2=`git_show_head $testroot/repo`
178 d24820bf 2019-08-11 stsp
179 d24820bf 2019-08-11 stsp (cd $testroot/repo && git tag -m "test" $tag2)
180 d24820bf 2019-08-11 stsp
181 d24820bf 2019-08-11 stsp echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
182 d24820bf 2019-08-11 stsp echo -n 'blob - ' >> $testroot/stdout.expected
183 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
184 d24820bf 2019-08-11 stsp cut -d' ' -f 1 >> $testroot/stdout.expected
185 d24820bf 2019-08-11 stsp echo -n 'blob + ' >> $testroot/stdout.expected
186 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
187 d24820bf 2019-08-11 stsp >> $testroot/stdout.expected
188 d24820bf 2019-08-11 stsp echo '--- alpha' >> $testroot/stdout.expected
189 d24820bf 2019-08-11 stsp echo '+++ alpha' >> $testroot/stdout.expected
190 d24820bf 2019-08-11 stsp echo '@@ -1 +1 @@' >> $testroot/stdout.expected
191 d24820bf 2019-08-11 stsp echo '-alpha' >> $testroot/stdout.expected
192 d24820bf 2019-08-11 stsp echo '+modified alpha' >> $testroot/stdout.expected
193 d24820bf 2019-08-11 stsp
194 d24820bf 2019-08-11 stsp got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
195 d24820bf 2019-08-11 stsp cmp -s $testroot/stdout.expected $testroot/stdout
196 d24820bf 2019-08-11 stsp ret="$?"
197 d24820bf 2019-08-11 stsp if [ "$ret" != "0" ]; then
198 d24820bf 2019-08-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
199 d24820bf 2019-08-11 stsp test_done "$testroot" "$ret"
200 d24820bf 2019-08-11 stsp return 1
201 d24820bf 2019-08-11 stsp fi
202 d24820bf 2019-08-11 stsp
203 d24820bf 2019-08-11 stsp echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
204 d24820bf 2019-08-11 stsp echo "blob - /dev/null" >> $testroot/stdout.expected
205 d24820bf 2019-08-11 stsp echo -n 'blob + ' >> $testroot/stdout.expected
206 d24820bf 2019-08-11 stsp got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
207 d24820bf 2019-08-11 stsp cut -d' ' -f 1 >> $testroot/stdout.expected
208 d24820bf 2019-08-11 stsp echo '--- /dev/null' >> $testroot/stdout.expected
209 d24820bf 2019-08-11 stsp echo '+++ new' >> $testroot/stdout.expected
210 d24820bf 2019-08-11 stsp echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
211 d24820bf 2019-08-11 stsp echo '+new file' >> $testroot/stdout.expected
212 d24820bf 2019-08-11 stsp
213 d24820bf 2019-08-11 stsp got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
214 d24820bf 2019-08-11 stsp cmp -s $testroot/stdout.expected $testroot/stdout
215 d24820bf 2019-08-11 stsp ret="$?"
216 d24820bf 2019-08-11 stsp if [ "$ret" != "0" ]; then
217 d24820bf 2019-08-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
218 d24820bf 2019-08-11 stsp fi
219 d24820bf 2019-08-11 stsp test_done "$testroot" "$ret"
220 d24820bf 2019-08-11 stsp }
221 d24820bf 2019-08-11 stsp
222 63035f9f 2019-10-06 stsp function test_diff_ignore_whitespace {
223 63035f9f 2019-10-06 stsp local testroot=`test_init diff_ignore_whitespace`
224 63035f9f 2019-10-06 stsp local commit_id0=`git_show_head $testroot/repo`
225 63035f9f 2019-10-06 stsp
226 63035f9f 2019-10-06 stsp got checkout $testroot/repo $testroot/wt > /dev/null
227 63035f9f 2019-10-06 stsp ret="$?"
228 63035f9f 2019-10-06 stsp if [ "$ret" != "0" ]; then
229 63035f9f 2019-10-06 stsp test_done "$testroot" "$ret"
230 63035f9f 2019-10-06 stsp return 1
231 63035f9f 2019-10-06 stsp fi
232 63035f9f 2019-10-06 stsp
233 63035f9f 2019-10-06 stsp echo "alpha " > $testroot/wt/alpha
234 63035f9f 2019-10-06 stsp
235 63035f9f 2019-10-06 stsp (cd $testroot/wt && got diff -w > $testroot/stdout)
236 63035f9f 2019-10-06 stsp
237 63035f9f 2019-10-06 stsp echo "diff $commit_id0 $testroot/wt" > $testroot/stdout.expected
238 63035f9f 2019-10-06 stsp echo -n 'blob - ' >> $testroot/stdout.expected
239 63035f9f 2019-10-06 stsp got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
240 63035f9f 2019-10-06 stsp cut -d' ' -f 1 >> $testroot/stdout.expected
241 63035f9f 2019-10-06 stsp echo 'file + alpha' >> $testroot/stdout.expected
242 63035f9f 2019-10-06 stsp
243 63035f9f 2019-10-06 stsp cmp -s $testroot/stdout.expected $testroot/stdout
244 63035f9f 2019-10-06 stsp ret="$?"
245 63035f9f 2019-10-06 stsp if [ "$ret" != "0" ]; then
246 63035f9f 2019-10-06 stsp diff -u $testroot/stdout.expected $testroot/stdout
247 63035f9f 2019-10-06 stsp fi
248 63035f9f 2019-10-06 stsp test_done "$testroot" "$ret"
249 63035f9f 2019-10-06 stsp }
250 63035f9f 2019-10-06 stsp
251 95adcdca 2019-03-27 stsp run_test test_diff_basic
252 95adcdca 2019-03-27 stsp run_test test_diff_shows_conflict
253 d24820bf 2019-08-11 stsp run_test test_diff_tag
254 63035f9f 2019-10-06 stsp run_test test_diff_ignore_whitespace