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 test_diff_basic() {
20 local testroot=`test_init diff_basic`
21 local head_rev=`git_show_head $testroot/repo`
22 local alpha_blobid=`get_blob_id $testroot/repo "" alpha`
24 got checkout $testroot/repo $testroot/wt > /dev/null
25 ret=$?
26 if [ $ret -ne 0 ]; then
27 test_done "$testroot" "$ret"
28 return 1
29 fi
31 echo "modified alpha" > $testroot/wt/alpha
32 (cd $testroot/wt && got rm beta >/dev/null)
33 echo "new file" > $testroot/wt/new
34 (cd $testroot/wt && got add new >/dev/null)
36 echo "diff $testroot/wt" > $testroot/stdout.expected
37 echo "commit - $head_rev" >> $testroot/stdout.expected
38 echo "path + $testroot/wt" >> $testroot/stdout.expected
39 echo -n 'blob - ' >> $testroot/stdout.expected
40 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
41 >> $testroot/stdout.expected
42 echo 'file + alpha' >> $testroot/stdout.expected
43 echo '--- alpha' >> $testroot/stdout.expected
44 echo '+++ alpha' >> $testroot/stdout.expected
45 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
46 echo '-alpha' >> $testroot/stdout.expected
47 echo '+modified alpha' >> $testroot/stdout.expected
48 echo -n 'blob - ' >> $testroot/stdout.expected
49 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
50 >> $testroot/stdout.expected
51 echo 'file + /dev/null' >> $testroot/stdout.expected
52 echo '--- beta' >> $testroot/stdout.expected
53 echo '+++ /dev/null' >> $testroot/stdout.expected
54 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
55 echo '-beta' >> $testroot/stdout.expected
56 echo 'blob - /dev/null' >> $testroot/stdout.expected
57 echo 'file + new' >> $testroot/stdout.expected
58 echo '--- /dev/null' >> $testroot/stdout.expected
59 echo '+++ new' >> $testroot/stdout.expected
60 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
61 echo '+new file' >> $testroot/stdout.expected
63 (cd $testroot/wt && got diff > $testroot/stdout)
64 cmp -s $testroot/stdout.expected $testroot/stdout
65 ret=$?
66 if [ $ret -ne 0 ]; then
67 diff -u $testroot/stdout.expected $testroot/stdout
68 test_done "$testroot" "$ret"
69 return 1
70 fi
72 # 'got diff' in a repository without any arguments is an error
73 (cd $testroot/repo && got diff 2> $testroot/stderr)
74 echo "got: no got work tree found" > $testroot/stderr.expected
75 cmp -s $testroot/stderr.expected $testroot/stderr
76 ret=$?
77 if [ $ret -ne 0 ]; then
78 diff -u $testroot/stderr.expected $testroot/stderr
79 test_done "$testroot" "$ret"
80 return 1
81 fi
83 # 'got diff' in a repository with two arguments requires that
84 # both named objects exist
85 (cd $testroot/repo && got diff $head_rev foo 2> $testroot/stderr)
86 echo "got: foo: object not found" > $testroot/stderr.expected
87 cmp -s $testroot/stderr.expected $testroot/stderr
88 ret=$?
89 if [ $ret -ne 0 ]; then
90 diff -u $testroot/stderr.expected $testroot/stderr
91 test_done "$testroot" "$ret"
92 return 1
93 fi
95 # diff non-existent path
96 (cd $testroot/wt && got diff nonexistent > $testroot/stdout \
97 2> $testroot/stderr)
99 echo -n > $testroot/stdout.expected
100 cmp -s $testroot/stdout.expected $testroot/stdout
101 ret=$?
102 if [ $ret -ne 0 ]; then
103 diff -u $testroot/stdout.expected $testroot/stdout
104 test_done "$testroot" "$ret"
105 return 1
106 fi
108 echo "got: nonexistent: No such file or directory" \
109 > $testroot/stderr.expected
110 cmp -s $testroot/stderr.expected $testroot/stderr
111 ret=$?
112 if [ $ret -ne 0 ]; then
113 diff -u $testroot/stderr.expected $testroot/stderr
114 test_done "$testroot" "$ret"
115 return 1
116 fi
118 echo "modified zeta" > $testroot/wt/epsilon/zeta
120 # diff several paths in a work tree
121 echo "diff $testroot/wt" > $testroot/stdout.expected
122 echo "commit - $head_rev" >> $testroot/stdout.expected
123 echo "path + $testroot/wt" >> $testroot/stdout.expected
124 echo -n 'blob - ' >> $testroot/stdout.expected
125 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
126 >> $testroot/stdout.expected
127 echo 'file + alpha' >> $testroot/stdout.expected
128 echo '--- alpha' >> $testroot/stdout.expected
129 echo '+++ alpha' >> $testroot/stdout.expected
130 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
131 echo '-alpha' >> $testroot/stdout.expected
132 echo '+modified alpha' >> $testroot/stdout.expected
133 echo -n 'blob - ' >> $testroot/stdout.expected
134 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
135 >> $testroot/stdout.expected
136 echo 'file + /dev/null' >> $testroot/stdout.expected
137 echo '--- beta' >> $testroot/stdout.expected
138 echo '+++ /dev/null' >> $testroot/stdout.expected
139 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
140 echo '-beta' >> $testroot/stdout.expected
141 echo -n 'blob - ' >> $testroot/stdout.expected
142 got tree -r $testroot/repo -i epsilon | grep 'zeta$' | cut -d' ' -f 1 \
143 >> $testroot/stdout.expected
144 echo 'file + epsilon/zeta' >> $testroot/stdout.expected
145 echo '--- epsilon/zeta' >> $testroot/stdout.expected
146 echo '+++ epsilon/zeta' >> $testroot/stdout.expected
147 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
148 echo '-zeta' >> $testroot/stdout.expected
149 echo '+modified zeta' >> $testroot/stdout.expected
150 echo 'blob - /dev/null' >> $testroot/stdout.expected
151 echo 'file + new' >> $testroot/stdout.expected
152 echo '--- /dev/null' >> $testroot/stdout.expected
153 echo '+++ new' >> $testroot/stdout.expected
154 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
155 echo '+new file' >> $testroot/stdout.expected
157 (cd $testroot/wt && got diff new alpha epsilon beta > $testroot/stdout)
158 cmp -s $testroot/stdout.expected $testroot/stdout
159 ret=$?
160 if [ $ret -ne 0 ]; then
161 diff -u $testroot/stdout.expected $testroot/stdout
162 test_done "$testroot" "$ret"
163 return 1
164 fi
166 # different order of arguments results in same output order
167 (cd $testroot/wt && got diff alpha new epsilon beta \
168 > $testroot/stdout 2> $testroot/stderr)
169 ret=$?
170 if [ $ret -ne 0 ]; then
171 echo "diff failed unexpectedly" >&2
172 test_done "$testroot" "1"
173 return 1
174 fi
175 cmp -s $testroot/stdout.expected $testroot/stdout
176 ret=$?
177 if [ $ret -ne 0 ]; then
178 diff -u $testroot/stdout.expected $testroot/stdout
179 test_done "$testroot" "$ret"
180 return 1
181 fi
183 # a branch 'new' should not collide with path 'new' if more
184 # than two arguments are passed
185 got br -r $testroot/repo -c master new > /dev/null
186 (cd $testroot/wt && got diff new alpha epsilon beta \
187 > $testroot/stdout 2> $testroot/stderr)
188 ret=$?
189 if [ $ret -ne 0 ]; then
190 echo "diff failed unexpectedly" >&2
191 test_done "$testroot" "1"
192 return 1
193 fi
194 cmp -s $testroot/stdout.expected $testroot/stdout
195 ret=$?
196 if [ $ret -ne 0 ]; then
197 diff -u $testroot/stdout.expected $testroot/stdout
198 test_done "$testroot" "$ret"
199 return 1
200 fi
202 # Two arguments are interpreted as objects if a colliding path exists
203 echo master > $testroot/wt/master
204 (cd $testroot/wt && got add master > /dev/null)
205 (cd $testroot/wt && got diff master new > $testroot/stdout)
206 ret=$?
207 if [ $ret -ne 0 ]; then
208 echo "diff failed unexpectedly" >&2
209 test_done "$testroot" "1"
210 return 1
211 fi
212 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
213 echo "commit - $head_rev" >> $testroot/stdout.expected
214 echo "commit + $head_rev" >> $testroot/stdout.expected
215 # diff between the branches is empty
216 cmp -s $testroot/stdout.expected $testroot/stdout
217 ret=$?
218 if [ $ret -ne 0 ]; then
219 diff -u $testroot/stdout.expected $testroot/stdout
220 test_done "$testroot" "$ret"
221 return 1
222 fi
223 # same without a work tree
224 (cd $testroot/repo && got diff master new > $testroot/stdout)
225 ret=$?
226 if [ $ret -ne 0 ]; then
227 echo "diff failed unexpectedly" >&2
228 test_done "$testroot" "1"
229 return 1
230 fi
231 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
232 echo "commit - $head_rev" >> $testroot/stdout.expected
233 echo "commit + $head_rev" >> $testroot/stdout.expected
234 cmp -s $testroot/stdout.expected $testroot/stdout
235 ret=$?
236 if [ $ret -ne 0 ]; then
237 diff -u $testroot/stdout.expected $testroot/stdout
238 test_done "$testroot" "$ret"
239 return 1
240 fi
241 # same with -r argument
242 got diff -r $testroot/repo master new > $testroot/stdout
243 ret=$?
244 if [ $ret -ne 0 ]; then
245 echo "diff failed unexpectedly" >&2
246 test_done "$testroot" "1"
247 return 1
248 fi
249 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
250 echo "commit - $head_rev" >> $testroot/stdout.expected
251 echo "commit + $head_rev" >> $testroot/stdout.expected
252 cmp -s $testroot/stdout.expected $testroot/stdout
253 ret=$?
254 if [ $ret -ne 0 ]; then
255 diff -u $testroot/stdout.expected $testroot/stdout
256 test_done "$testroot" "$ret"
257 return 1
258 fi
260 # -P can be used to force use of paths
261 (cd $testroot/wt && got diff -P new master > $testroot/stdout)
262 ret=$?
263 if [ $ret -ne 0 ]; then
264 echo "diff failed unexpectedly" >&2
265 test_done "$testroot" "1"
266 return 1
267 fi
268 echo "diff $testroot/wt" > $testroot/stdout.expected
269 echo "commit - $head_rev" >> $testroot/stdout.expected
270 echo "path + $testroot/wt" >> $testroot/stdout.expected
271 echo 'blob - /dev/null' >> $testroot/stdout.expected
272 echo 'file + master' >> $testroot/stdout.expected
273 echo '--- /dev/null' >> $testroot/stdout.expected
274 echo '+++ master' >> $testroot/stdout.expected
275 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
276 echo '+master' >> $testroot/stdout.expected
277 echo 'blob - /dev/null' >> $testroot/stdout.expected
278 echo 'file + new' >> $testroot/stdout.expected
279 echo '--- /dev/null' >> $testroot/stdout.expected
280 echo '+++ new' >> $testroot/stdout.expected
281 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
282 echo '+new file' >> $testroot/stdout.expected
283 cmp -s $testroot/stdout.expected $testroot/stdout
284 ret=$?
285 if [ $ret -ne 0 ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
288 return 1
289 fi
291 # -P can only be used in a work tree
292 got diff -r $testroot/repo -P new master 2> $testroot/stderr
293 ret=$?
294 if [ $ret -eq 0 ]; then
295 echo "diff succeeded unexpectedly" >&2
296 test_done "$testroot" "1"
297 return 1
298 fi
299 echo "got: -P option can only be used when diffing a work tree" \
300 > $testroot/stderr.expected
301 cmp -s $testroot/stderr.expected $testroot/stderr
302 ret=$?
303 if [ $ret -ne 0 ]; then
304 diff -u $testroot/stderr.expected $testroot/stderr
305 test_done "$testroot" "$ret"
306 return 1
307 fi
309 # a single argument which can be resolved to a path is not ambiguous
310 echo "diff $testroot/wt" > $testroot/stdout.expected
311 echo "commit - $head_rev" >> $testroot/stdout.expected
312 echo "path + $testroot/wt" >> $testroot/stdout.expected
313 echo 'blob - /dev/null' >> $testroot/stdout.expected
314 echo 'file + new' >> $testroot/stdout.expected
315 echo '--- /dev/null' >> $testroot/stdout.expected
316 echo '+++ new' >> $testroot/stdout.expected
317 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
318 echo '+new file' >> $testroot/stdout.expected
319 (cd $testroot/wt && got diff new > $testroot/stdout)
320 ret=$?
321 if [ $ret -ne 0 ]; then
322 echo "diff failed unexpectedly" >&2
323 test_done "$testroot" "1"
324 return 1
325 fi
326 cmp -s $testroot/stdout.expected $testroot/stdout
327 ret=$?
328 if [ $ret -ne 0 ]; then
329 diff -u $testroot/stdout.expected $testroot/stdout
330 test_done "$testroot" "$ret"
331 return 1
332 fi
334 # diff with just one object ID argument results in
335 # interpretation of argument as a path
336 (cd $testroot/wt && got diff $head_rev 2> $testroot/stderr)
337 ret=$?
338 if [ $ret -eq 0 ]; then
339 echo "diff succeeded unexpectedly" >&2
340 test_done "$testroot" "1"
341 return 1
342 fi
343 echo "got: $head_rev: No such file or directory" \
344 > $testroot/stderr.expected
345 cmp -s $testroot/stderr.expected $testroot/stderr
346 ret=$?
347 if [ $ret -ne 0 ]; then
348 diff -u $testroot/stderr.expected $testroot/stderr
349 test_done "$testroot" "$ret"
350 return 1
351 fi
353 # diff with more than two object arguments results in
354 # interpretation of arguments as paths
355 (cd $testroot/wt && got diff new $head_rev master \
356 > $testroot/stout 2> $testroot/stderr)
357 ret=$?
358 if [ $ret -eq 0 ]; then
359 echo "diff succeeded unexpectedly" >&2
360 test_done "$testroot" "1"
361 return 1
362 fi
364 echo "diff $testroot/wt" > $testroot/stdout.expected
365 echo "commit - $head_rev" >> $testroot/stdout.expected
366 echo "path + $testroot/wt" >> $testroot/stdout.expected
367 echo 'blob - /dev/null' >> $testroot/stdout.expected
368 echo 'file + new' >> $testroot/stdout.expected
369 echo '--- /dev/null' >> $testroot/stdout.expected
370 echo '+++ new' >> $testroot/stdout.expected
371 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
372 echo '+new file' >> $testroot/stdout.expected
373 cmp -s $testroot/stdout.expected $testroot/stdout
374 ret=$?
375 if [ $ret -ne 0 ]; then
376 diff -u $testroot/stdout.expected $testroot/stdout
377 test_done "$testroot" "$ret"
378 return 1
379 fi
381 echo "got: $head_rev: No such file or directory" \
382 > $testroot/stderr.expected
383 cmp -s $testroot/stderr.expected $testroot/stderr
384 ret=$?
385 if [ $ret -ne 0 ]; then
386 diff -u $testroot/stderr.expected $testroot/stderr
387 return 1
388 fi
390 # diff two blob ids
391 (cd $testroot/wt && got commit -m 'edit' alpha >/dev/null)
392 local alpha_new_blobid=`get_blob_id $testroot/repo "" alpha`
393 (cd $testroot/wt && got diff $alpha_blobid $alpha_new_blobid) \
394 > $testroot/diff
395 ret=$?
396 if [ $ret -ne 0 ]; then
397 echo "diff failed unexpectedly" >&2
398 test_done "$testroot" "$ret"
399 return 1
400 fi
402 cat <<EOF >$testroot/diff.expected
403 blob - $alpha_blobid
404 blob + $alpha_new_blobid
405 --- $alpha_blobid
406 +++ $alpha_new_blobid
407 @@ -1 +1 @@
408 -alpha
409 +modified alpha
410 EOF
412 cmp -s $testroot/diff.expected $testroot/diff
413 ret=$?
414 if [ $ret -ne 0 ]; then
415 echo
416 diff -u $testroot/diff.expected $testroot/diff
417 test_done "$testroot" "$ret"
418 return 1
419 fi
421 test_done "$testroot" "$ret"
424 test_diff_shows_conflict() {
425 local testroot=`test_init diff_shows_conflict 1`
427 echo "1" > $testroot/repo/numbers
428 echo "2" >> $testroot/repo/numbers
429 echo "3" >> $testroot/repo/numbers
430 echo "4" >> $testroot/repo/numbers
431 echo "5" >> $testroot/repo/numbers
432 echo "6" >> $testroot/repo/numbers
433 echo "7" >> $testroot/repo/numbers
434 echo "8" >> $testroot/repo/numbers
435 (cd $testroot/repo && git add numbers)
436 git_commit $testroot/repo -m "added numbers file"
437 local base_commit=`git_show_head $testroot/repo`
439 got checkout $testroot/repo $testroot/wt > /dev/null
440 ret=$?
441 if [ $ret -ne 0 ]; then
442 test_done "$testroot" "$ret"
443 return 1
444 fi
446 sed -i 's/2/22/' $testroot/repo/numbers
447 sed -i 's/8/33/' $testroot/repo/numbers
448 git_commit $testroot/repo -m "modified line 2"
449 local head_rev=`git_show_head $testroot/repo`
451 # modify lines 2 and 8 in conflicting ways
452 sed -i 's/2/77/' $testroot/wt/numbers
453 sed -i 's/8/88/' $testroot/wt/numbers
455 echo "C numbers" > $testroot/stdout.expected
456 echo -n "Updated to refs/heads/master: $head_rev" \
457 >> $testroot/stdout.expected
458 echo >> $testroot/stdout.expected
459 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
461 (cd $testroot/wt && got update > $testroot/stdout)
463 cmp -s $testroot/stdout.expected $testroot/stdout
464 ret=$?
465 if [ $ret -ne 0 ]; then
466 diff -u $testroot/stdout.expected $testroot/stdout
467 test_done "$testroot" "$ret"
468 return 1
469 fi
471 echo "diff $testroot/wt" > $testroot/stdout.expected
472 echo "commit - $head_rev" >> $testroot/stdout.expected
473 echo "path + $testroot/wt" >> $testroot/stdout.expected
474 echo -n 'blob - ' >> $testroot/stdout.expected
475 got tree -r $testroot/repo -i | grep 'numbers$' | cut -d' ' -f 1 \
476 >> $testroot/stdout.expected
477 echo 'file + numbers' >> $testroot/stdout.expected
478 echo '--- numbers' >> $testroot/stdout.expected
479 echo '+++ numbers' >> $testroot/stdout.expected
480 echo '@@ -1,8 +1,20 @@' >> $testroot/stdout.expected
481 echo ' 1' >> $testroot/stdout.expected
482 echo "+<<<<<<< merged change: commit $head_rev" \
483 >> $testroot/stdout.expected
484 echo ' 22' >> $testroot/stdout.expected
485 echo "+||||||| 3-way merge base: commit $base_commit" \
486 >> $testroot/stdout.expected
487 echo '+2' >> $testroot/stdout.expected
488 echo '+=======' >> $testroot/stdout.expected
489 echo '+77' >> $testroot/stdout.expected
490 echo '+>>>>>>>' >> $testroot/stdout.expected
491 echo ' 3' >> $testroot/stdout.expected
492 echo ' 4' >> $testroot/stdout.expected
493 echo ' 5' >> $testroot/stdout.expected
494 echo ' 6' >> $testroot/stdout.expected
495 echo ' 7' >> $testroot/stdout.expected
496 echo "+<<<<<<< merged change: commit $head_rev" \
497 >> $testroot/stdout.expected
498 echo ' 33' >> $testroot/stdout.expected
499 echo "+||||||| 3-way merge base: commit $base_commit" \
500 >> $testroot/stdout.expected
501 echo '+8' >> $testroot/stdout.expected
502 echo '+=======' >> $testroot/stdout.expected
503 echo '+88' >> $testroot/stdout.expected
504 echo '+>>>>>>>' >> $testroot/stdout.expected
506 (cd $testroot/wt && got diff > $testroot/stdout)
508 cmp -s $testroot/stdout.expected $testroot/stdout
509 ret=$?
510 if [ $ret -ne 0 ]; then
511 diff -u $testroot/stdout.expected $testroot/stdout
512 fi
513 test_done "$testroot" "$ret"
516 test_diff_tag() {
517 local testroot=`test_init diff_tag`
518 local commit_id0=`git_show_head $testroot/repo`
519 local tag1=1.0.0
520 local tag2=2.0.0
522 echo "modified alpha" > $testroot/repo/alpha
523 git_commit $testroot/repo -m "changed alpha"
524 local commit_id1=`git_show_head $testroot/repo`
526 (cd $testroot/repo && git tag -m "test" $tag1)
528 echo "new file" > $testroot/repo/new
529 (cd $testroot/repo && git add new)
530 git_commit $testroot/repo -m "new file"
531 local commit_id2=`git_show_head $testroot/repo`
533 (cd $testroot/repo && git tag -m "test" $tag2)
535 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
536 echo "commit - $commit_id0" >> $testroot/stdout.expected
537 echo "commit + $commit_id1" >> $testroot/stdout.expected
538 echo -n 'blob - ' >> $testroot/stdout.expected
539 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
540 cut -d' ' -f 1 >> $testroot/stdout.expected
541 echo -n 'blob + ' >> $testroot/stdout.expected
542 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
543 >> $testroot/stdout.expected
544 echo '--- alpha' >> $testroot/stdout.expected
545 echo '+++ alpha' >> $testroot/stdout.expected
546 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
547 echo '-alpha' >> $testroot/stdout.expected
548 echo '+modified alpha' >> $testroot/stdout.expected
550 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
551 cmp -s $testroot/stdout.expected $testroot/stdout
552 ret=$?
553 if [ $ret -ne 0 ]; then
554 diff -u $testroot/stdout.expected $testroot/stdout
555 test_done "$testroot" "$ret"
556 return 1
557 fi
559 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
560 echo "commit - $commit_id1" >> $testroot/stdout.expected
561 echo "commit + $commit_id2" >> $testroot/stdout.expected
562 echo "blob - /dev/null" >> $testroot/stdout.expected
563 echo -n 'blob + ' >> $testroot/stdout.expected
564 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
565 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
566 echo " (mode 644)" >> $testroot/stdout.expected
567 echo '--- /dev/null' >> $testroot/stdout.expected
568 echo '+++ new' >> $testroot/stdout.expected
569 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
570 echo '+new file' >> $testroot/stdout.expected
572 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
573 cmp -s $testroot/stdout.expected $testroot/stdout
574 ret=$?
575 if [ $ret -ne 0 ]; then
576 diff -u $testroot/stdout.expected $testroot/stdout
577 fi
578 test_done "$testroot" "$ret"
581 test_diff_lightweight_tag() {
582 local testroot=`test_init diff_tag`
583 local commit_id0=`git_show_head $testroot/repo`
584 local tag1=1.0.0
585 local tag2=2.0.0
587 echo "modified alpha" > $testroot/repo/alpha
588 git_commit $testroot/repo -m "changed alpha"
589 local commit_id1=`git_show_head $testroot/repo`
591 (cd $testroot/repo && git tag $tag1)
593 echo "new file" > $testroot/repo/new
594 (cd $testroot/repo && git add new)
595 git_commit $testroot/repo -m "new file"
596 local commit_id2=`git_show_head $testroot/repo`
598 (cd $testroot/repo && git tag $tag2)
600 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
601 echo "commit - $commit_id0" >> $testroot/stdout.expected
602 echo "commit + $commit_id1" >> $testroot/stdout.expected
603 echo -n 'blob - ' >> $testroot/stdout.expected
604 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
605 cut -d' ' -f 1 >> $testroot/stdout.expected
606 echo -n 'blob + ' >> $testroot/stdout.expected
607 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
608 >> $testroot/stdout.expected
609 echo '--- alpha' >> $testroot/stdout.expected
610 echo '+++ alpha' >> $testroot/stdout.expected
611 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
612 echo '-alpha' >> $testroot/stdout.expected
613 echo '+modified alpha' >> $testroot/stdout.expected
615 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
616 cmp -s $testroot/stdout.expected $testroot/stdout
617 ret=$?
618 if [ $ret -ne 0 ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
625 echo "commit - $commit_id1" >> $testroot/stdout.expected
626 echo "commit + $commit_id2" >> $testroot/stdout.expected
627 echo "blob - /dev/null" >> $testroot/stdout.expected
628 echo -n 'blob + ' >> $testroot/stdout.expected
629 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
630 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
631 echo " (mode 644)" >> $testroot/stdout.expected
632 echo '--- /dev/null' >> $testroot/stdout.expected
633 echo '+++ new' >> $testroot/stdout.expected
634 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
635 echo '+new file' >> $testroot/stdout.expected
637 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
638 cmp -s $testroot/stdout.expected $testroot/stdout
639 ret=$?
640 if [ $ret -ne 0 ]; then
641 diff -u $testroot/stdout.expected $testroot/stdout
642 fi
643 test_done "$testroot" "$ret"
646 test_diff_ignore_whitespace() {
647 local testroot=`test_init diff_ignore_whitespace`
648 local commit_id0=`git_show_head $testroot/repo`
650 got checkout $testroot/repo $testroot/wt > /dev/null
651 ret=$?
652 if [ $ret -ne 0 ]; then
653 test_done "$testroot" "$ret"
654 return 1
655 fi
657 echo "alpha " > $testroot/wt/alpha
659 (cd $testroot/wt && got diff -w > $testroot/stdout)
661 echo "diff $testroot/wt" > $testroot/stdout.expected
662 echo "commit - $commit_id0" >> $testroot/stdout.expected
663 echo "path + $testroot/wt" >> $testroot/stdout.expected
664 echo -n 'blob - ' >> $testroot/stdout.expected
665 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
666 cut -d' ' -f 1 >> $testroot/stdout.expected
667 echo 'file + alpha' >> $testroot/stdout.expected
669 cmp -s $testroot/stdout.expected $testroot/stdout
670 ret=$?
671 if [ $ret -ne 0 ]; then
672 diff -u $testroot/stdout.expected $testroot/stdout
673 fi
674 test_done "$testroot" "$ret"
677 test_diff_submodule_of_same_repo() {
678 local testroot=`test_init diff_submodule_of_same_repo`
680 (cd $testroot && git clone -q repo repo2 >/dev/null)
681 (cd $testroot/repo && git submodule -q add ../repo2)
682 (cd $testroot/repo && git commit -q -m 'adding submodule')
684 epsilon_id=$(got tree -r $testroot/repo -i | grep 'epsilon/$' | \
685 cut -d ' ' -f 1)
686 submodule_id=$(got tree -r $testroot/repo -i | grep 'repo2\$$' | \
687 cut -d ' ' -f 1)
689 # Attempt a (nonsensical) diff between a tree object and a submodule.
690 # Currently fails with "wrong type of object" error
691 got diff -r $testroot/repo $epsilon_id $submodule_id \
692 > $testroot/stdout 2> $testroot/stderr
693 ret=$?
694 if [ $ret -eq 0 ]; then
695 echo "diff command succeeded unexpectedly" >&2
696 test_done "$testroot" "1"
697 return 1
698 fi
699 echo "got: wrong type of object" > $testroot/stderr.expected
701 cmp -s $testroot/stderr.expected $testroot/stderr
702 ret=$?
703 if [ $ret -ne 0 ]; then
704 diff -u $testroot/stderr.expected $testroot/stderr
705 return 1
706 fi
707 test_done "$testroot" "$ret"
710 test_diff_symlinks_in_work_tree() {
711 local testroot=`test_init diff_symlinks_in_work_tree`
713 (cd $testroot/repo && ln -s alpha alpha.link)
714 (cd $testroot/repo && ln -s epsilon epsilon.link)
715 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
716 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
717 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
718 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
719 (cd $testroot/repo && git add .)
720 git_commit $testroot/repo -m "add symlinks"
721 local commit_id1=`git_show_head $testroot/repo`
723 got checkout $testroot/repo $testroot/wt > /dev/null
724 ret=$?
725 if [ $ret -ne 0 ]; then
726 test_done "$testroot" "$ret"
727 return 1
728 fi
730 (cd $testroot/wt && ln -sf beta alpha.link)
731 (cd $testroot/wt && ln -sfh gamma epsilon.link)
732 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
733 echo -n '.got/bar' > $testroot/wt/dotgotfoo.link
734 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
735 (cd $testroot/wt && ln -sf epsilon/zeta zeta.link)
736 (cd $testroot/wt && got add zeta.link > /dev/null)
737 (cd $testroot/wt && got diff > $testroot/stdout)
739 echo "diff $testroot/wt" > $testroot/stdout.expected
740 echo "commit - $commit_id1" >> $testroot/stdout.expected
741 echo "path + $testroot/wt" >> $testroot/stdout.expected
742 echo -n 'blob - ' >> $testroot/stdout.expected
743 got tree -r $testroot/repo -c $commit_id1 -i | \
744 grep 'alpha.link@ -> alpha$' | \
745 cut -d' ' -f 1 >> $testroot/stdout.expected
746 echo 'file + alpha.link' >> $testroot/stdout.expected
747 echo '--- alpha.link' >> $testroot/stdout.expected
748 echo '+++ alpha.link' >> $testroot/stdout.expected
749 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
750 echo '-alpha' >> $testroot/stdout.expected
751 echo '\ No newline at end of file' >> $testroot/stdout.expected
752 echo '+beta' >> $testroot/stdout.expected
753 echo '\ No newline at end of file' >> $testroot/stdout.expected
754 echo -n 'blob - ' >> $testroot/stdout.expected
755 got tree -r $testroot/repo -c $commit_id1 -i | \
756 grep 'dotgotfoo.link@ -> .got/foo$' | \
757 cut -d' ' -f 1 >> $testroot/stdout.expected
758 echo 'file + dotgotfoo.link' >> $testroot/stdout.expected
759 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
760 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
761 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
762 echo '-.got/foo' >> $testroot/stdout.expected
763 echo '\ No newline at end of file' >> $testroot/stdout.expected
764 echo '+.got/bar' >> $testroot/stdout.expected
765 echo '\ No newline at end of file' >> $testroot/stdout.expected
766 echo -n 'blob - ' >> $testroot/stdout.expected
767 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
768 grep 'beta.link@ -> ../beta$' | \
769 cut -d' ' -f 1 >> $testroot/stdout.expected
770 echo 'file + epsilon/beta.link' >> $testroot/stdout.expected
771 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
772 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
773 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
774 echo '-../beta' >> $testroot/stdout.expected
775 echo '\ No newline at end of file' >> $testroot/stdout.expected
776 echo '+../gamma/delta' >> $testroot/stdout.expected
777 echo '\ No newline at end of file' >> $testroot/stdout.expected
778 echo -n 'blob - ' >> $testroot/stdout.expected
779 got tree -r $testroot/repo -c $commit_id1 -i | \
780 grep 'epsilon.link@ -> epsilon$' | \
781 cut -d' ' -f 1 >> $testroot/stdout.expected
782 echo 'file + epsilon.link' >> $testroot/stdout.expected
783 echo '--- epsilon.link' >> $testroot/stdout.expected
784 echo '+++ epsilon.link' >> $testroot/stdout.expected
785 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
786 echo '-epsilon' >> $testroot/stdout.expected
787 echo '\ No newline at end of file' >> $testroot/stdout.expected
788 echo '+gamma' >> $testroot/stdout.expected
789 echo '\ No newline at end of file' >> $testroot/stdout.expected
790 echo -n 'blob - ' >> $testroot/stdout.expected
791 got tree -r $testroot/repo -c $commit_id1 -i | \
792 grep 'nonexistent.link@ -> nonexistent$' | \
793 cut -d' ' -f 1 >> $testroot/stdout.expected
794 echo 'file + /dev/null' >> $testroot/stdout.expected
795 echo '--- nonexistent.link' >> $testroot/stdout.expected
796 echo '+++ /dev/null' >> $testroot/stdout.expected
797 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
798 echo '-nonexistent' >> $testroot/stdout.expected
799 echo '\ No newline at end of file' >> $testroot/stdout.expected
800 echo 'blob - /dev/null' >> $testroot/stdout.expected
801 echo 'file + zeta.link' >> $testroot/stdout.expected
802 echo '--- /dev/null' >> $testroot/stdout.expected
803 echo '+++ zeta.link' >> $testroot/stdout.expected
804 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
805 echo '+epsilon/zeta' >> $testroot/stdout.expected
806 echo '\ No newline at end of file' >> $testroot/stdout.expected
808 cmp -s $testroot/stdout.expected $testroot/stdout
809 ret=$?
810 if [ $ret -ne 0 ]; then
811 diff -u $testroot/stdout.expected $testroot/stdout
812 fi
813 test_done "$testroot" "$ret"
816 test_diff_symlinks_in_repo() {
817 local testroot=`test_init diff_symlinks_in_repo`
819 (cd $testroot/repo && ln -s alpha alpha.link)
820 (cd $testroot/repo && ln -s epsilon epsilon.link)
821 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
822 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
823 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
824 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
825 (cd $testroot/repo && git add .)
826 git_commit $testroot/repo -m "add symlinks"
827 local commit_id1=`git_show_head $testroot/repo`
829 (cd $testroot/repo && ln -sf beta alpha.link)
830 (cd $testroot/repo && ln -sfh gamma epsilon.link)
831 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
832 (cd $testroot/repo && ln -sf .got/bar $testroot/repo/dotgotfoo.link)
833 (cd $testroot/repo && git rm -q nonexistent.link)
834 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
835 (cd $testroot/repo && git add .)
836 git_commit $testroot/repo -m "change symlinks"
837 local commit_id2=`git_show_head $testroot/repo`
839 got diff -r $testroot/repo $commit_id1 $commit_id2 > $testroot/stdout
841 echo "diff $commit_id1 $commit_id2" > $testroot/stdout.expected
842 echo "commit - $commit_id1" >> $testroot/stdout.expected
843 echo "commit + $commit_id2" >> $testroot/stdout.expected
844 echo -n 'blob - ' >> $testroot/stdout.expected
845 got tree -r $testroot/repo -c $commit_id1 -i | \
846 grep 'alpha.link@ -> alpha$' | \
847 cut -d' ' -f 1 >> $testroot/stdout.expected
848 echo -n 'blob + ' >> $testroot/stdout.expected
849 got tree -r $testroot/repo -c $commit_id2 -i | \
850 grep 'alpha.link@ -> beta$' | \
851 cut -d' ' -f 1 >> $testroot/stdout.expected
852 echo '--- alpha.link' >> $testroot/stdout.expected
853 echo '+++ alpha.link' >> $testroot/stdout.expected
854 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
855 echo '-alpha' >> $testroot/stdout.expected
856 echo '\ No newline at end of file' >> $testroot/stdout.expected
857 echo '+beta' >> $testroot/stdout.expected
858 echo '\ No newline at end of file' >> $testroot/stdout.expected
859 echo -n 'blob - ' >> $testroot/stdout.expected
860 got tree -r $testroot/repo -c $commit_id1 -i | \
861 grep 'dotgotfoo.link@ -> .got/foo$' | \
862 cut -d' ' -f 1 >> $testroot/stdout.expected
863 echo -n 'blob + ' >> $testroot/stdout.expected
864 got tree -r $testroot/repo -c $commit_id2 -i | \
865 grep 'dotgotfoo.link@ -> .got/bar$' | \
866 cut -d' ' -f 1 >> $testroot/stdout.expected
867 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
868 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
869 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
870 echo '-.got/foo' >> $testroot/stdout.expected
871 echo '\ No newline at end of file' >> $testroot/stdout.expected
872 echo '+.got/bar' >> $testroot/stdout.expected
873 echo '\ No newline at end of file' >> $testroot/stdout.expected
874 echo -n 'blob - ' >> $testroot/stdout.expected
875 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
876 grep 'beta.link@ -> ../beta$' | \
877 cut -d' ' -f 1 >> $testroot/stdout.expected
878 echo -n 'blob + ' >> $testroot/stdout.expected
879 got tree -r $testroot/repo -c $commit_id2 -i epsilon | \
880 grep 'beta.link@ -> ../gamma/delta$' | \
881 cut -d' ' -f 1 >> $testroot/stdout.expected
882 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
883 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
884 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
885 echo '-../beta' >> $testroot/stdout.expected
886 echo '\ No newline at end of file' >> $testroot/stdout.expected
887 echo '+../gamma/delta' >> $testroot/stdout.expected
888 echo '\ No newline at end of file' >> $testroot/stdout.expected
889 echo -n 'blob - ' >> $testroot/stdout.expected
890 got tree -r $testroot/repo -c $commit_id1 -i | \
891 grep 'epsilon.link@ -> epsilon$' | \
892 cut -d' ' -f 1 >> $testroot/stdout.expected
893 echo -n 'blob + ' >> $testroot/stdout.expected
894 got tree -r $testroot/repo -c $commit_id2 -i | \
895 grep 'epsilon.link@ -> gamma$' | \
896 cut -d' ' -f 1 >> $testroot/stdout.expected
897 echo '--- epsilon.link' >> $testroot/stdout.expected
898 echo '+++ epsilon.link' >> $testroot/stdout.expected
899 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
900 echo '-epsilon' >> $testroot/stdout.expected
901 echo '\ No newline at end of file' >> $testroot/stdout.expected
902 echo '+gamma' >> $testroot/stdout.expected
903 echo '\ No newline at end of file' >> $testroot/stdout.expected
904 echo -n 'blob - ' >> $testroot/stdout.expected
905 got tree -r $testroot/repo -c $commit_id1 -i | \
906 grep 'nonexistent.link@ -> nonexistent$' | \
907 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
908 >> $testroot/stdout.expected
909 echo 'blob + /dev/null' >> $testroot/stdout.expected
910 echo '--- nonexistent.link' >> $testroot/stdout.expected
911 echo '+++ /dev/null' >> $testroot/stdout.expected
912 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
913 echo '-nonexistent' >> $testroot/stdout.expected
914 echo '\ No newline at end of file' >> $testroot/stdout.expected
915 echo 'blob - /dev/null' >> $testroot/stdout.expected
916 echo -n 'blob + ' >> $testroot/stdout.expected
917 got tree -r $testroot/repo -c $commit_id2 -i | \
918 grep 'zeta.link@ -> epsilon/zeta$' | \
919 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
920 >> $testroot/stdout.expected
921 echo '--- /dev/null' >> $testroot/stdout.expected
922 echo '+++ zeta.link' >> $testroot/stdout.expected
923 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
924 echo '+epsilon/zeta' >> $testroot/stdout.expected
925 echo '\ No newline at end of file' >> $testroot/stdout.expected
927 cmp -s $testroot/stdout.expected $testroot/stdout
928 ret=$?
929 if [ $ret -ne 0 ]; then
930 diff -u $testroot/stdout.expected $testroot/stdout
931 fi
932 test_done "$testroot" "$ret"
935 test_diff_binary_files() {
936 local testroot=`test_init diff_binary_files`
937 local head_rev=`git_show_head $testroot/repo`
939 got checkout $testroot/repo $testroot/wt > /dev/null
940 ret=$?
941 if [ $ret -ne 0 ]; then
942 test_done "$testroot" "$ret"
943 return 1
944 fi
946 printf '\377\377\0\0\377\377\0\0' > $testroot/wt/foo
947 (cd $testroot/wt && got add foo >/dev/null)
949 echo "diff $testroot/wt" > $testroot/stdout.expected
950 echo "commit - $head_rev" >> $testroot/stdout.expected
951 echo "path + $testroot/wt" >> $testroot/stdout.expected
952 echo 'blob - /dev/null' >> $testroot/stdout.expected
953 echo 'file + foo' >> $testroot/stdout.expected
954 echo "Binary files /dev/null and foo differ" \
955 >> $testroot/stdout.expected
957 (cd $testroot/wt && got diff > $testroot/stdout)
958 cmp -s $testroot/stdout.expected $testroot/stdout
959 ret=$?
960 if [ $ret -ne 0 ]; then
961 diff -a -u $testroot/stdout.expected $testroot/stdout
962 test_done "$testroot" "$ret"
963 return 1
964 fi
966 echo "diff $testroot/wt" > $testroot/stdout.expected
967 echo "commit - $head_rev" >> $testroot/stdout.expected
968 echo "path + $testroot/wt" >> $testroot/stdout.expected
969 echo 'blob - /dev/null' >> $testroot/stdout.expected
970 echo 'file + foo' >> $testroot/stdout.expected
971 echo '--- /dev/null' >> $testroot/stdout.expected
972 echo '+++ foo' >> $testroot/stdout.expected
973 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
974 printf '+\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
975 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
977 (cd $testroot/wt && got diff -a > $testroot/stdout)
978 cmp -s $testroot/stdout.expected $testroot/stdout
979 ret=$?
980 if [ $ret -ne 0 ]; then
981 diff -a -u $testroot/stdout.expected $testroot/stdout
982 test_done "$testroot" "$ret"
983 return 1
984 fi
986 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
987 local head_rev=`git_show_head $testroot/repo`
989 printf '\377\200\0\0\377\200\0\0' > $testroot/wt/foo
991 echo "diff $testroot/wt" > $testroot/stdout.expected
992 echo "commit - $head_rev" >> $testroot/stdout.expected
993 echo "path + $testroot/wt" >> $testroot/stdout.expected
994 echo -n 'blob - ' >> $testroot/stdout.expected
995 got tree -r $testroot/repo -i | grep 'foo$' | cut -d' ' -f 1 \
996 >> $testroot/stdout.expected
997 echo 'file + foo' >> $testroot/stdout.expected
998 echo '--- foo' >> $testroot/stdout.expected
999 echo '+++ foo' >> $testroot/stdout.expected
1000 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1001 printf -- '-\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
1002 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
1003 printf '+\377\200\0\0\377\200\0\0\n' >> $testroot/stdout.expected
1004 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
1006 (cd $testroot/wt && got diff -a > $testroot/stdout)
1007 cmp -s $testroot/stdout.expected $testroot/stdout
1008 ret=$?
1009 if [ $ret -ne 0 ]; then
1010 diff -a -u $testroot/stdout.expected $testroot/stdout
1012 test_done "$testroot" "$ret"
1015 test_diff_commits() {
1016 local testroot=`test_init diff_commits`
1017 local commit_id0=`git_show_head $testroot/repo`
1018 alpha_id0=`get_blob_id $testroot/repo "" alpha`
1019 beta_id0=`get_blob_id $testroot/repo "" beta`
1021 got checkout $testroot/repo $testroot/wt > /dev/null
1022 ret=$?
1023 if [ $ret -ne 0 ]; then
1024 test_done "$testroot" "$ret"
1025 return 1
1028 echo "modified alpha" > $testroot/wt/alpha
1029 (cd $testroot/wt && got rm beta >/dev/null)
1030 echo "new file" > $testroot/wt/new
1031 (cd $testroot/wt && got add new >/dev/null)
1032 (cd $testroot/wt && got commit -m 'committing changes' >/dev/null)
1033 local commit_id1=`git_show_head $testroot/repo`
1035 alpha_id1=`get_blob_id $testroot/repo "" alpha`
1036 new_id1=`get_blob_id $testroot/repo "" new`
1038 echo "diff $commit_id0 refs/heads/master" > $testroot/stdout.expected
1039 echo "commit - $commit_id0" >> $testroot/stdout.expected
1040 echo "commit + $commit_id1" >> $testroot/stdout.expected
1041 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1042 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1043 echo '--- alpha' >> $testroot/stdout.expected
1044 echo '+++ alpha' >> $testroot/stdout.expected
1045 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1046 echo '-alpha' >> $testroot/stdout.expected
1047 echo '+modified alpha' >> $testroot/stdout.expected
1048 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1049 echo 'blob + /dev/null' >> $testroot/stdout.expected
1050 echo '--- beta' >> $testroot/stdout.expected
1051 echo '+++ /dev/null' >> $testroot/stdout.expected
1052 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1053 echo '-beta' >> $testroot/stdout.expected
1054 echo 'blob - /dev/null' >> $testroot/stdout.expected
1055 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1056 echo '--- /dev/null' >> $testroot/stdout.expected
1057 echo '+++ new' >> $testroot/stdout.expected
1058 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1059 echo '+new file' >> $testroot/stdout.expected
1061 (cd $testroot/wt && got diff -c master > $testroot/stdout)
1062 cmp -s $testroot/stdout.expected $testroot/stdout
1063 ret=$?
1064 if [ $ret -ne 0 ]; then
1065 diff -u $testroot/stdout.expected $testroot/stdout
1066 test_done "$testroot" "$ret"
1067 return 1
1070 # same diff with explicit parent commit ID
1071 (cd $testroot/wt && got diff -c $commit_id0 -c master \
1072 > $testroot/stdout)
1073 cmp -s $testroot/stdout.expected $testroot/stdout
1074 ret=$?
1075 if [ $ret -ne 0 ]; then
1076 diff -u $testroot/stdout.expected $testroot/stdout
1077 test_done "$testroot" "$ret"
1078 return 1
1081 # same diff with commit object IDs
1082 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1083 echo "commit - $commit_id0" >> $testroot/stdout.expected
1084 echo "commit + $commit_id1" >> $testroot/stdout.expected
1085 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1086 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1087 echo '--- alpha' >> $testroot/stdout.expected
1088 echo '+++ alpha' >> $testroot/stdout.expected
1089 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1090 echo '-alpha' >> $testroot/stdout.expected
1091 echo '+modified alpha' >> $testroot/stdout.expected
1092 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1093 echo 'blob + /dev/null' >> $testroot/stdout.expected
1094 echo '--- beta' >> $testroot/stdout.expected
1095 echo '+++ /dev/null' >> $testroot/stdout.expected
1096 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1097 echo '-beta' >> $testroot/stdout.expected
1098 echo 'blob - /dev/null' >> $testroot/stdout.expected
1099 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1100 echo '--- /dev/null' >> $testroot/stdout.expected
1101 echo '+++ new' >> $testroot/stdout.expected
1102 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1103 echo '+new file' >> $testroot/stdout.expected
1104 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 \
1105 > $testroot/stdout)
1106 cmp -s $testroot/stdout.expected $testroot/stdout
1107 ret=$?
1108 if [ $ret -ne 0 ]; then
1109 diff -u $testroot/stdout.expected $testroot/stdout
1110 test_done "$testroot" "$ret"
1111 return 1
1114 # same diff, filtered by paths
1115 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1116 echo "commit - $commit_id0" >> $testroot/stdout.expected
1117 echo "commit + $commit_id1" >> $testroot/stdout.expected
1118 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1119 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1120 echo '--- alpha' >> $testroot/stdout.expected
1121 echo '+++ alpha' >> $testroot/stdout.expected
1122 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1123 echo '-alpha' >> $testroot/stdout.expected
1124 echo '+modified alpha' >> $testroot/stdout.expected
1125 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 alpha \
1126 > $testroot/stdout)
1127 cmp -s $testroot/stdout.expected $testroot/stdout
1128 ret=$?
1129 if [ $ret -ne 0 ]; then
1130 diff -u $testroot/stdout.expected $testroot/stdout
1131 test_done "$testroot" "$ret"
1132 return 1
1134 # same in a work tree
1135 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 alpha \
1136 > $testroot/stdout)
1137 cmp -s $testroot/stdout.expected $testroot/stdout
1138 ret=$?
1139 if [ $ret -ne 0 ]; then
1140 diff -u $testroot/stdout.expected $testroot/stdout
1141 test_done "$testroot" "$ret"
1142 return 1
1145 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1146 echo "commit - $commit_id0" >> $testroot/stdout.expected
1147 echo "commit + $commit_id1" >> $testroot/stdout.expected
1148 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1149 echo 'blob + /dev/null' >> $testroot/stdout.expected
1150 echo '--- beta' >> $testroot/stdout.expected
1151 echo '+++ /dev/null' >> $testroot/stdout.expected
1152 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1153 echo '-beta' >> $testroot/stdout.expected
1154 echo 'blob - /dev/null' >> $testroot/stdout.expected
1155 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1156 echo '--- /dev/null' >> $testroot/stdout.expected
1157 echo '+++ new' >> $testroot/stdout.expected
1158 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1159 echo '+new file' >> $testroot/stdout.expected
1160 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 \
1161 beta new > $testroot/stdout)
1162 cmp -s $testroot/stdout.expected $testroot/stdout
1163 ret=$?
1164 if [ $ret -ne 0 ]; then
1165 diff -u $testroot/stdout.expected $testroot/stdout
1166 test_done "$testroot" "$ret"
1167 return 1
1170 # more than two -c options are not allowed
1171 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 -c foo \
1172 2> $testroot/stderr)
1173 ret=$?
1174 if [ $ret -eq 0 ]; then
1175 echo "diff succeeded unexpectedly" >&2
1176 test_done "$testroot" "1"
1177 return 1
1179 echo "got: too many -c options used" > $testroot/stderr.expected
1180 cmp -s $testroot/stderr.expected $testroot/stderr
1181 ret=$?
1182 if [ $ret -ne 0 ]; then
1183 diff -u $testroot/stderr.expected $testroot/stderr
1184 test_done "$testroot" "$ret"
1185 return 1
1188 # use of -c options implies a repository diff; use with -P is an error
1189 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -P foo \
1190 2> $testroot/stderr)
1191 ret=$?
1192 if [ $ret -eq 0 ]; then
1193 echo "diff succeeded unexpectedly" >&2
1194 test_done "$testroot" "1"
1195 return 1
1197 echo "got: -P option can only be used when diffing a work tree" \
1198 > $testroot/stderr.expected
1199 cmp -s $testroot/stderr.expected $testroot/stderr
1200 ret=$?
1201 if [ $ret -ne 0 ]; then
1202 diff -u $testroot/stderr.expected $testroot/stderr
1203 test_done "$testroot" "$ret"
1204 return 1
1207 # use of -c options implies a repository diff; use with -s is an error
1208 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -s foo \
1209 2> $testroot/stderr)
1210 ret=$?
1211 if [ $ret -eq 0 ]; then
1212 echo "diff succeeded unexpectedly" >&2
1213 test_done "$testroot" "1"
1214 return 1
1216 echo "got: -s option can only be used when diffing a work tree" \
1217 > $testroot/stderr.expected
1218 cmp -s $testroot/stderr.expected $testroot/stderr
1219 ret=$?
1220 if [ $ret -ne 0 ]; then
1221 diff -u $testroot/stderr.expected $testroot/stderr
1222 test_done "$testroot" "$ret"
1223 return 1
1226 # three arguments imply use of path filtering (repository case)
1227 (cd $testroot/repo && got diff $commit_id0 $commit_id1 foo \
1228 2> $testroot/stderr)
1229 ret=$?
1230 if [ $ret -eq 0 ]; then
1231 echo "diff succeeded unexpectedly" >&2
1232 test_done "$testroot" "1"
1233 return 1
1235 echo "got: specified paths cannot be resolved: no got work tree found" \
1236 > $testroot/stderr.expected
1237 cmp -s $testroot/stderr.expected $testroot/stderr
1238 ret=$?
1239 if [ $ret -ne 0 ]; then
1240 diff -u $testroot/stderr.expected $testroot/stderr
1241 test_done "$testroot" "$ret"
1242 return 1
1245 # three arguments imply use of path filtering (work tree case)
1246 (cd $testroot/wt && got diff $commit_id0 master foo \
1247 2> $testroot/stderr)
1248 ret=$?
1249 if [ $ret -eq 0 ]; then
1250 echo "diff succeeded unexpectedly" >&2
1251 test_done "$testroot" "1"
1252 return 1
1254 echo "got: $commit_id0: No such file or directory" \
1255 > $testroot/stderr.expected
1256 cmp -s $testroot/stderr.expected $testroot/stderr
1257 ret=$?
1258 if [ $ret -ne 0 ]; then
1259 diff -u $testroot/stderr.expected $testroot/stderr
1261 test_done "$testroot" "$ret"
1264 test_diff_ignored_file() {
1265 local testroot=`test_init diff_ignored_file`
1267 got checkout $testroot/repo $testroot/wt > /dev/null
1268 ret=$?
1269 if [ $ret -ne 0 ]; then
1270 test_done "$testroot" "$ret"
1271 return 1
1274 echo 1 > $testroot/wt/number
1275 (cd $testroot/wt && got add number >/dev/null)
1276 (cd $testroot/wt && got commit -m 'add number' >/dev/null)
1278 echo "**/number" > $testroot/wt/.gitignore
1280 echo 2 > $testroot/wt/number
1281 (cd $testroot/wt && got diff number | sed '1,/^@@/d' > $testroot/stdout)
1283 echo "-1" > $testroot/stdout.expected
1284 echo "+2" >> $testroot/stdout.expected
1286 cmp -s $testroot/stdout.expected $testroot/stdout
1287 ret=$?
1288 if [ $ret -ne 0 ]; then
1289 diff -u $testroot/stdout.expected $testroot/stdout
1291 test_done "$testroot" "$ret"
1294 test_diff_crlf() {
1295 local testroot=`test_init diff_crlf`
1297 got checkout $testroot/repo $testroot/wt > /dev/null
1298 ret=$?
1299 if [ $ret -ne 0 ]; then
1300 test_done "$testroot" $ret
1301 return 1
1304 printf 'test\r\n' > $testroot/wt/crlf
1305 (cd $testroot/wt && got add crlf && got commit -m +crlf) >/dev/null
1306 ret=$?
1307 if [ $ret -ne 0 ]; then
1308 test_done "$testroot" $ret
1309 return 1
1312 printf 'test 2\r\n' > $testroot/wt/crlf
1313 (cd $testroot/wt && got diff | sed -n '/^---/,$p' > $testroot/stdout)
1314 cat <<EOF > $testroot/stdout.expected
1315 --- crlf
1316 +++ crlf
1317 @@ -1 +1 @@
1318 -test
1319 +test 2
1320 EOF
1322 cmp -s $testroot/stdout.expected $testroot/stdout
1323 ret=$?
1324 if [ $ret -ne 0 ]; then
1325 diff -u $testroot/stdout.expected $testroot/stdout
1327 test_done "$testroot" $ret
1330 test_parseargs "$@"
1331 run_test test_diff_basic
1332 run_test test_diff_shows_conflict
1333 run_test test_diff_tag
1334 run_test test_diff_lightweight_tag
1335 run_test test_diff_ignore_whitespace
1336 run_test test_diff_submodule_of_same_repo
1337 run_test test_diff_symlinks_in_work_tree
1338 run_test test_diff_symlinks_in_repo
1339 run_test test_diff_binary_files
1340 run_test test_diff_commits
1341 run_test test_diff_ignored_file
1342 run_test test_diff_crlf