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) > $testroot/diff
394 ret=$?
395 if [ $ret -ne 0 ]; then
396 echo "diff failed unexpectedly" >&2
397 test_done "$testroot" "$ret"
398 return 1
399 fi
401 cat <<EOF >$testroot/diff.expected
402 blob - $alpha_blobid
403 blob + $alpha_new_blobid
404 --- $alpha_blobid
405 +++ $alpha_new_blobid
406 @@ -1 +1 @@
407 -alpha
408 +modified alpha
409 EOF
411 cmp -s $testroot/diff.expected $testroot/diff
412 ret=$?
413 if [ $ret -ne 0 ]; then
414 echo
415 diff -u $testroot/diff.expected $testroot/diff
416 test_done "$testroot" "$ret"
417 return 1
418 fi
420 test_done "$testroot" "$ret"
423 test_diff_shows_conflict() {
424 local testroot=`test_init diff_shows_conflict 1`
426 echo "1" > $testroot/repo/numbers
427 echo "2" >> $testroot/repo/numbers
428 echo "3" >> $testroot/repo/numbers
429 echo "4" >> $testroot/repo/numbers
430 echo "5" >> $testroot/repo/numbers
431 echo "6" >> $testroot/repo/numbers
432 echo "7" >> $testroot/repo/numbers
433 echo "8" >> $testroot/repo/numbers
434 (cd $testroot/repo && git add numbers)
435 git_commit $testroot/repo -m "added numbers file"
436 local base_commit=`git_show_head $testroot/repo`
438 got checkout $testroot/repo $testroot/wt > /dev/null
439 ret=$?
440 if [ $ret -ne 0 ]; then
441 test_done "$testroot" "$ret"
442 return 1
443 fi
445 sed -i '' -e 's/2/22/' $testroot/repo/numbers
446 sed -i '' -e 's/8/33/' $testroot/repo/numbers
447 git_commit $testroot/repo -m "modified line 2"
448 local head_rev=`git_show_head $testroot/repo`
450 # modify lines 2 and 8 in conflicting ways
451 sed -i '' -e 's/2/77/' $testroot/wt/numbers
452 sed -i '' -e 's/8/88/' $testroot/wt/numbers
454 echo "C numbers" > $testroot/stdout.expected
455 echo -n "Updated to refs/heads/master: $head_rev" \
456 >> $testroot/stdout.expected
457 echo >> $testroot/stdout.expected
458 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
460 (cd $testroot/wt && got update > $testroot/stdout)
462 cmp -s $testroot/stdout.expected $testroot/stdout
463 ret=$?
464 if [ $ret -ne 0 ]; then
465 diff -u $testroot/stdout.expected $testroot/stdout
466 test_done "$testroot" "$ret"
467 return 1
468 fi
470 echo "diff $testroot/wt" > $testroot/stdout.expected
471 echo "commit - $head_rev" >> $testroot/stdout.expected
472 echo "path + $testroot/wt" >> $testroot/stdout.expected
473 echo -n 'blob - ' >> $testroot/stdout.expected
474 got tree -r $testroot/repo -i | grep 'numbers$' | cut -d' ' -f 1 \
475 >> $testroot/stdout.expected
476 echo 'file + numbers' >> $testroot/stdout.expected
477 echo '--- numbers' >> $testroot/stdout.expected
478 echo '+++ numbers' >> $testroot/stdout.expected
479 echo '@@ -1,8 +1,20 @@' >> $testroot/stdout.expected
480 echo ' 1' >> $testroot/stdout.expected
481 echo "+<<<<<<< merged change: commit $head_rev" \
482 >> $testroot/stdout.expected
483 echo ' 22' >> $testroot/stdout.expected
484 echo "+||||||| 3-way merge base: commit $base_commit" \
485 >> $testroot/stdout.expected
486 echo '+2' >> $testroot/stdout.expected
487 echo '+=======' >> $testroot/stdout.expected
488 echo '+77' >> $testroot/stdout.expected
489 echo '+>>>>>>>' >> $testroot/stdout.expected
490 echo ' 3' >> $testroot/stdout.expected
491 echo ' 4' >> $testroot/stdout.expected
492 echo ' 5' >> $testroot/stdout.expected
493 echo ' 6' >> $testroot/stdout.expected
494 echo ' 7' >> $testroot/stdout.expected
495 echo "+<<<<<<< merged change: commit $head_rev" \
496 >> $testroot/stdout.expected
497 echo ' 33' >> $testroot/stdout.expected
498 echo "+||||||| 3-way merge base: commit $base_commit" \
499 >> $testroot/stdout.expected
500 echo '+8' >> $testroot/stdout.expected
501 echo '+=======' >> $testroot/stdout.expected
502 echo '+88' >> $testroot/stdout.expected
503 echo '+>>>>>>>' >> $testroot/stdout.expected
505 (cd $testroot/wt && got diff > $testroot/stdout)
507 cmp -s $testroot/stdout.expected $testroot/stdout
508 ret=$?
509 if [ $ret -ne 0 ]; then
510 diff -u $testroot/stdout.expected $testroot/stdout
511 fi
512 test_done "$testroot" "$ret"
515 test_diff_tag() {
516 local testroot=`test_init diff_tag`
517 local commit_id0=`git_show_head $testroot/repo`
518 local tag1=1.0.0
519 local tag2=2.0.0
521 echo "modified alpha" > $testroot/repo/alpha
522 git_commit $testroot/repo -m "changed alpha"
523 local commit_id1=`git_show_head $testroot/repo`
525 (cd $testroot/repo && git tag -m "test" $tag1)
527 echo "new file" > $testroot/repo/new
528 (cd $testroot/repo && git add new)
529 git_commit $testroot/repo -m "new file"
530 local commit_id2=`git_show_head $testroot/repo`
532 (cd $testroot/repo && git tag -m "test" $tag2)
534 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
535 echo "commit - $commit_id0" >> $testroot/stdout.expected
536 echo "commit + $commit_id1" >> $testroot/stdout.expected
537 echo -n 'blob - ' >> $testroot/stdout.expected
538 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
539 cut -d' ' -f 1 >> $testroot/stdout.expected
540 echo -n 'blob + ' >> $testroot/stdout.expected
541 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
542 >> $testroot/stdout.expected
543 echo '--- alpha' >> $testroot/stdout.expected
544 echo '+++ alpha' >> $testroot/stdout.expected
545 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
546 echo '-alpha' >> $testroot/stdout.expected
547 echo '+modified alpha' >> $testroot/stdout.expected
549 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
550 cmp -s $testroot/stdout.expected $testroot/stdout
551 ret=$?
552 if [ $ret -ne 0 ]; then
553 diff -u $testroot/stdout.expected $testroot/stdout
554 test_done "$testroot" "$ret"
555 return 1
556 fi
558 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
559 echo "commit - $commit_id1" >> $testroot/stdout.expected
560 echo "commit + $commit_id2" >> $testroot/stdout.expected
561 echo "blob - /dev/null" >> $testroot/stdout.expected
562 echo -n 'blob + ' >> $testroot/stdout.expected
563 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
564 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
565 echo " (mode 644)" >> $testroot/stdout.expected
566 echo '--- /dev/null' >> $testroot/stdout.expected
567 echo '+++ new' >> $testroot/stdout.expected
568 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
569 echo '+new file' >> $testroot/stdout.expected
571 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
572 cmp -s $testroot/stdout.expected $testroot/stdout
573 ret=$?
574 if [ $ret -ne 0 ]; then
575 diff -u $testroot/stdout.expected $testroot/stdout
576 fi
577 test_done "$testroot" "$ret"
580 test_diff_lightweight_tag() {
581 local testroot=`test_init diff_tag`
582 local commit_id0=`git_show_head $testroot/repo`
583 local tag1=1.0.0
584 local tag2=2.0.0
586 echo "modified alpha" > $testroot/repo/alpha
587 git_commit $testroot/repo -m "changed alpha"
588 local commit_id1=`git_show_head $testroot/repo`
590 (cd $testroot/repo && git tag $tag1)
592 echo "new file" > $testroot/repo/new
593 (cd $testroot/repo && git add new)
594 git_commit $testroot/repo -m "new file"
595 local commit_id2=`git_show_head $testroot/repo`
597 (cd $testroot/repo && git tag $tag2)
599 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
600 echo "commit - $commit_id0" >> $testroot/stdout.expected
601 echo "commit + $commit_id1" >> $testroot/stdout.expected
602 echo -n 'blob - ' >> $testroot/stdout.expected
603 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
604 cut -d' ' -f 1 >> $testroot/stdout.expected
605 echo -n 'blob + ' >> $testroot/stdout.expected
606 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
607 >> $testroot/stdout.expected
608 echo '--- alpha' >> $testroot/stdout.expected
609 echo '+++ alpha' >> $testroot/stdout.expected
610 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
611 echo '-alpha' >> $testroot/stdout.expected
612 echo '+modified alpha' >> $testroot/stdout.expected
614 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
615 cmp -s $testroot/stdout.expected $testroot/stdout
616 ret=$?
617 if [ $ret -ne 0 ]; then
618 diff -u $testroot/stdout.expected $testroot/stdout
619 test_done "$testroot" "$ret"
620 return 1
621 fi
623 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
624 echo "commit - $commit_id1" >> $testroot/stdout.expected
625 echo "commit + $commit_id2" >> $testroot/stdout.expected
626 echo "blob - /dev/null" >> $testroot/stdout.expected
627 echo -n 'blob + ' >> $testroot/stdout.expected
628 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
629 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
630 echo " (mode 644)" >> $testroot/stdout.expected
631 echo '--- /dev/null' >> $testroot/stdout.expected
632 echo '+++ new' >> $testroot/stdout.expected
633 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
634 echo '+new file' >> $testroot/stdout.expected
636 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
637 cmp -s $testroot/stdout.expected $testroot/stdout
638 ret=$?
639 if [ $ret -ne 0 ]; then
640 diff -u $testroot/stdout.expected $testroot/stdout
641 fi
642 test_done "$testroot" "$ret"
645 test_diff_ignore_whitespace() {
646 local testroot=`test_init diff_ignore_whitespace`
647 local commit_id0=`git_show_head $testroot/repo`
649 got checkout $testroot/repo $testroot/wt > /dev/null
650 ret=$?
651 if [ $ret -ne 0 ]; then
652 test_done "$testroot" "$ret"
653 return 1
654 fi
656 echo "alpha " > $testroot/wt/alpha
658 (cd $testroot/wt && got diff -w > $testroot/stdout)
660 echo "diff $testroot/wt" > $testroot/stdout.expected
661 echo "commit - $commit_id0" >> $testroot/stdout.expected
662 echo "path + $testroot/wt" >> $testroot/stdout.expected
663 echo -n 'blob - ' >> $testroot/stdout.expected
664 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
665 cut -d' ' -f 1 >> $testroot/stdout.expected
666 echo 'file + alpha' >> $testroot/stdout.expected
668 cmp -s $testroot/stdout.expected $testroot/stdout
669 ret=$?
670 if [ $ret -ne 0 ]; then
671 diff -u $testroot/stdout.expected $testroot/stdout
672 fi
673 test_done "$testroot" "$ret"
676 test_diff_submodule_of_same_repo() {
677 local testroot=`test_init diff_submodule_of_same_repo`
679 (cd $testroot && git clone -q repo repo2 >/dev/null)
680 (cd $testroot/repo && git submodule -q add ../repo2)
681 (cd $testroot/repo && git commit -q -m 'adding submodule')
683 epsilon_id=$(got tree -r $testroot/repo -i | grep 'epsilon/$' | \
684 cut -d ' ' -f 1)
685 submodule_id=$(got tree -r $testroot/repo -i | grep 'repo2\$$' | \
686 cut -d ' ' -f 1)
688 # Attempt a (nonsensical) diff between a tree object and a submodule.
689 # Currently fails with "wrong type of object" error
690 got diff -r $testroot/repo $epsilon_id $submodule_id \
691 > $testroot/stdout 2> $testroot/stderr
692 ret=$?
693 if [ $ret -eq 0 ]; then
694 echo "diff command succeeded unexpectedly" >&2
695 test_done "$testroot" "1"
696 return 1
697 fi
698 echo "got: wrong type of object" > $testroot/stderr.expected
700 cmp -s $testroot/stderr.expected $testroot/stderr
701 ret=$?
702 if [ $ret -ne 0 ]; then
703 diff -u $testroot/stderr.expected $testroot/stderr
704 return 1
705 fi
706 test_done "$testroot" "$ret"
709 test_diff_symlinks_in_work_tree() {
710 local testroot=`test_init diff_symlinks_in_work_tree`
712 (cd $testroot/repo && ln -s alpha alpha.link)
713 (cd $testroot/repo && ln -s epsilon epsilon.link)
714 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
715 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
716 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
717 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
718 (cd $testroot/repo && git add .)
719 git_commit $testroot/repo -m "add symlinks"
720 local commit_id1=`git_show_head $testroot/repo`
722 got checkout $testroot/repo $testroot/wt > /dev/null
723 ret=$?
724 if [ $ret -ne 0 ]; then
725 test_done "$testroot" "$ret"
726 return 1
727 fi
729 (cd $testroot/wt && ln -sf beta alpha.link)
730 (cd $testroot/wt && ln -sfT gamma epsilon.link)
731 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
732 echo -n '.got/bar' > $testroot/wt/dotgotfoo.link
733 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
734 (cd $testroot/wt && ln -sf epsilon/zeta zeta.link)
735 (cd $testroot/wt && got add zeta.link > /dev/null)
736 (cd $testroot/wt && got diff > $testroot/stdout)
738 echo "diff $testroot/wt" > $testroot/stdout.expected
739 echo "commit - $commit_id1" >> $testroot/stdout.expected
740 echo "path + $testroot/wt" >> $testroot/stdout.expected
741 echo -n 'blob - ' >> $testroot/stdout.expected
742 got tree -r $testroot/repo -c $commit_id1 -i | \
743 grep 'alpha.link@ -> alpha$' | \
744 cut -d' ' -f 1 >> $testroot/stdout.expected
745 echo 'file + alpha.link' >> $testroot/stdout.expected
746 echo '--- alpha.link' >> $testroot/stdout.expected
747 echo '+++ alpha.link' >> $testroot/stdout.expected
748 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
749 echo '-alpha' >> $testroot/stdout.expected
750 echo '\ No newline at end of file' >> $testroot/stdout.expected
751 echo '+beta' >> $testroot/stdout.expected
752 echo '\ No newline at end of file' >> $testroot/stdout.expected
753 echo -n 'blob - ' >> $testroot/stdout.expected
754 got tree -r $testroot/repo -c $commit_id1 -i | \
755 grep 'dotgotfoo.link@ -> .got/foo$' | \
756 cut -d' ' -f 1 >> $testroot/stdout.expected
757 echo 'file + dotgotfoo.link' >> $testroot/stdout.expected
758 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
759 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
760 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
761 echo '-.got/foo' >> $testroot/stdout.expected
762 echo '\ No newline at end of file' >> $testroot/stdout.expected
763 echo '+.got/bar' >> $testroot/stdout.expected
764 echo '\ No newline at end of file' >> $testroot/stdout.expected
765 echo -n 'blob - ' >> $testroot/stdout.expected
766 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
767 grep 'beta.link@ -> ../beta$' | \
768 cut -d' ' -f 1 >> $testroot/stdout.expected
769 echo 'file + epsilon/beta.link' >> $testroot/stdout.expected
770 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
771 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
772 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
773 echo '-../beta' >> $testroot/stdout.expected
774 echo '\ No newline at end of file' >> $testroot/stdout.expected
775 echo '+../gamma/delta' >> $testroot/stdout.expected
776 echo '\ No newline at end of file' >> $testroot/stdout.expected
777 echo -n 'blob - ' >> $testroot/stdout.expected
778 got tree -r $testroot/repo -c $commit_id1 -i | \
779 grep 'epsilon.link@ -> epsilon$' | \
780 cut -d' ' -f 1 >> $testroot/stdout.expected
781 echo 'file + epsilon.link' >> $testroot/stdout.expected
782 echo '--- epsilon.link' >> $testroot/stdout.expected
783 echo '+++ epsilon.link' >> $testroot/stdout.expected
784 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
785 echo '-epsilon' >> $testroot/stdout.expected
786 echo '\ No newline at end of file' >> $testroot/stdout.expected
787 echo '+gamma' >> $testroot/stdout.expected
788 echo '\ No newline at end of file' >> $testroot/stdout.expected
789 echo -n 'blob - ' >> $testroot/stdout.expected
790 got tree -r $testroot/repo -c $commit_id1 -i | \
791 grep 'nonexistent.link@ -> nonexistent$' | \
792 cut -d' ' -f 1 >> $testroot/stdout.expected
793 echo 'file + /dev/null' >> $testroot/stdout.expected
794 echo '--- nonexistent.link' >> $testroot/stdout.expected
795 echo '+++ /dev/null' >> $testroot/stdout.expected
796 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
797 echo '-nonexistent' >> $testroot/stdout.expected
798 echo '\ No newline at end of file' >> $testroot/stdout.expected
799 echo 'blob - /dev/null' >> $testroot/stdout.expected
800 echo 'file + zeta.link' >> $testroot/stdout.expected
801 echo '--- /dev/null' >> $testroot/stdout.expected
802 echo '+++ zeta.link' >> $testroot/stdout.expected
803 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
804 echo '+epsilon/zeta' >> $testroot/stdout.expected
805 echo '\ No newline at end of file' >> $testroot/stdout.expected
807 cmp -s $testroot/stdout.expected $testroot/stdout
808 ret=$?
809 if [ $ret -ne 0 ]; then
810 diff -u $testroot/stdout.expected $testroot/stdout
811 fi
812 test_done "$testroot" "$ret"
815 test_diff_symlinks_in_repo() {
816 local testroot=`test_init diff_symlinks_in_repo`
818 (cd $testroot/repo && ln -s alpha alpha.link)
819 (cd $testroot/repo && ln -s epsilon epsilon.link)
820 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
821 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
822 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
823 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
824 (cd $testroot/repo && git add .)
825 git_commit $testroot/repo -m "add symlinks"
826 local commit_id1=`git_show_head $testroot/repo`
828 (cd $testroot/repo && ln -sf beta alpha.link)
829 (cd $testroot/repo && ln -sfT gamma epsilon.link)
830 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
831 (cd $testroot/repo && ln -sf .got/bar $testroot/repo/dotgotfoo.link)
832 (cd $testroot/repo && git rm -q nonexistent.link)
833 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
834 (cd $testroot/repo && git add .)
835 git_commit $testroot/repo -m "change symlinks"
836 local commit_id2=`git_show_head $testroot/repo`
838 got diff -r $testroot/repo $commit_id1 $commit_id2 > $testroot/stdout
840 echo "diff $commit_id1 $commit_id2" > $testroot/stdout.expected
841 echo "commit - $commit_id1" >> $testroot/stdout.expected
842 echo "commit + $commit_id2" >> $testroot/stdout.expected
843 echo -n 'blob - ' >> $testroot/stdout.expected
844 got tree -r $testroot/repo -c $commit_id1 -i | \
845 grep 'alpha.link@ -> alpha$' | \
846 cut -d' ' -f 1 >> $testroot/stdout.expected
847 echo -n 'blob + ' >> $testroot/stdout.expected
848 got tree -r $testroot/repo -c $commit_id2 -i | \
849 grep 'alpha.link@ -> beta$' | \
850 cut -d' ' -f 1 >> $testroot/stdout.expected
851 echo '--- alpha.link' >> $testroot/stdout.expected
852 echo '+++ alpha.link' >> $testroot/stdout.expected
853 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
854 echo '-alpha' >> $testroot/stdout.expected
855 echo '\ No newline at end of file' >> $testroot/stdout.expected
856 echo '+beta' >> $testroot/stdout.expected
857 echo '\ No newline at end of file' >> $testroot/stdout.expected
858 echo -n 'blob - ' >> $testroot/stdout.expected
859 got tree -r $testroot/repo -c $commit_id1 -i | \
860 grep 'dotgotfoo.link@ -> .got/foo$' | \
861 cut -d' ' -f 1 >> $testroot/stdout.expected
862 echo -n 'blob + ' >> $testroot/stdout.expected
863 got tree -r $testroot/repo -c $commit_id2 -i | \
864 grep 'dotgotfoo.link@ -> .got/bar$' | \
865 cut -d' ' -f 1 >> $testroot/stdout.expected
866 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
867 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
868 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
869 echo '-.got/foo' >> $testroot/stdout.expected
870 echo '\ No newline at end of file' >> $testroot/stdout.expected
871 echo '+.got/bar' >> $testroot/stdout.expected
872 echo '\ No newline at end of file' >> $testroot/stdout.expected
873 echo -n 'blob - ' >> $testroot/stdout.expected
874 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
875 grep 'beta.link@ -> ../beta$' | \
876 cut -d' ' -f 1 >> $testroot/stdout.expected
877 echo -n 'blob + ' >> $testroot/stdout.expected
878 got tree -r $testroot/repo -c $commit_id2 -i epsilon | \
879 grep 'beta.link@ -> ../gamma/delta$' | \
880 cut -d' ' -f 1 >> $testroot/stdout.expected
881 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
882 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
883 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
884 echo '-../beta' >> $testroot/stdout.expected
885 echo '\ No newline at end of file' >> $testroot/stdout.expected
886 echo '+../gamma/delta' >> $testroot/stdout.expected
887 echo '\ No newline at end of file' >> $testroot/stdout.expected
888 echo -n 'blob - ' >> $testroot/stdout.expected
889 got tree -r $testroot/repo -c $commit_id1 -i | \
890 grep 'epsilon.link@ -> epsilon$' | \
891 cut -d' ' -f 1 >> $testroot/stdout.expected
892 echo -n 'blob + ' >> $testroot/stdout.expected
893 got tree -r $testroot/repo -c $commit_id2 -i | \
894 grep 'epsilon.link@ -> gamma$' | \
895 cut -d' ' -f 1 >> $testroot/stdout.expected
896 echo '--- epsilon.link' >> $testroot/stdout.expected
897 echo '+++ epsilon.link' >> $testroot/stdout.expected
898 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
899 echo '-epsilon' >> $testroot/stdout.expected
900 echo '\ No newline at end of file' >> $testroot/stdout.expected
901 echo '+gamma' >> $testroot/stdout.expected
902 echo '\ No newline at end of file' >> $testroot/stdout.expected
903 echo -n 'blob - ' >> $testroot/stdout.expected
904 got tree -r $testroot/repo -c $commit_id1 -i | \
905 grep 'nonexistent.link@ -> nonexistent$' | \
906 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
907 >> $testroot/stdout.expected
908 echo 'blob + /dev/null' >> $testroot/stdout.expected
909 echo '--- nonexistent.link' >> $testroot/stdout.expected
910 echo '+++ /dev/null' >> $testroot/stdout.expected
911 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
912 echo '-nonexistent' >> $testroot/stdout.expected
913 echo '\ No newline at end of file' >> $testroot/stdout.expected
914 echo 'blob - /dev/null' >> $testroot/stdout.expected
915 echo -n 'blob + ' >> $testroot/stdout.expected
916 got tree -r $testroot/repo -c $commit_id2 -i | \
917 grep 'zeta.link@ -> epsilon/zeta$' | \
918 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
919 >> $testroot/stdout.expected
920 echo '--- /dev/null' >> $testroot/stdout.expected
921 echo '+++ zeta.link' >> $testroot/stdout.expected
922 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
923 echo '+epsilon/zeta' >> $testroot/stdout.expected
924 echo '\ No newline at end of file' >> $testroot/stdout.expected
926 cmp -s $testroot/stdout.expected $testroot/stdout
927 ret=$?
928 if [ $ret -ne 0 ]; then
929 diff -u $testroot/stdout.expected $testroot/stdout
930 fi
931 test_done "$testroot" "$ret"
934 test_diff_binary_files() {
935 local testroot=`test_init diff_binary_files`
936 local head_rev=`git_show_head $testroot/repo`
938 got checkout $testroot/repo $testroot/wt > /dev/null
939 ret=$?
940 if [ $ret -ne 0 ]; then
941 test_done "$testroot" "$ret"
942 return 1
943 fi
945 printf '\377\377\0\0\377\377\0\0' > $testroot/wt/foo
946 (cd $testroot/wt && got add foo >/dev/null)
948 echo "diff $testroot/wt" > $testroot/stdout.expected
949 echo "commit - $head_rev" >> $testroot/stdout.expected
950 echo "path + $testroot/wt" >> $testroot/stdout.expected
951 echo 'blob - /dev/null' >> $testroot/stdout.expected
952 echo 'file + foo' >> $testroot/stdout.expected
953 echo "Binary files /dev/null and foo differ" \
954 >> $testroot/stdout.expected
956 (cd $testroot/wt && got diff > $testroot/stdout)
957 cmp -s $testroot/stdout.expected $testroot/stdout
958 ret=$?
959 if [ $ret -ne 0 ]; then
960 diff -a -u $testroot/stdout.expected $testroot/stdout
961 test_done "$testroot" "$ret"
962 return 1
963 fi
965 echo "diff $testroot/wt" > $testroot/stdout.expected
966 echo "commit - $head_rev" >> $testroot/stdout.expected
967 echo "path + $testroot/wt" >> $testroot/stdout.expected
968 echo 'blob - /dev/null' >> $testroot/stdout.expected
969 echo 'file + foo' >> $testroot/stdout.expected
970 echo '--- /dev/null' >> $testroot/stdout.expected
971 echo '+++ foo' >> $testroot/stdout.expected
972 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
973 printf '+\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
974 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
976 (cd $testroot/wt && got diff -a > $testroot/stdout)
977 cmp -s $testroot/stdout.expected $testroot/stdout
978 ret=$?
979 if [ $ret -ne 0 ]; then
980 diff -a -u $testroot/stdout.expected $testroot/stdout
981 test_done "$testroot" "$ret"
982 return 1
983 fi
985 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
986 local head_rev=`git_show_head $testroot/repo`
988 printf '\377\200\0\0\377\200\0\0' > $testroot/wt/foo
990 echo "diff $testroot/wt" > $testroot/stdout.expected
991 echo "commit - $head_rev" >> $testroot/stdout.expected
992 echo "path + $testroot/wt" >> $testroot/stdout.expected
993 echo -n 'blob - ' >> $testroot/stdout.expected
994 got tree -r $testroot/repo -i | grep 'foo$' | cut -d' ' -f 1 \
995 >> $testroot/stdout.expected
996 echo 'file + foo' >> $testroot/stdout.expected
997 echo '--- foo' >> $testroot/stdout.expected
998 echo '+++ foo' >> $testroot/stdout.expected
999 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1000 printf -- '-\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
1001 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
1002 printf '+\377\200\0\0\377\200\0\0\n' >> $testroot/stdout.expected
1003 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
1005 (cd $testroot/wt && got diff -a > $testroot/stdout)
1006 cmp -s $testroot/stdout.expected $testroot/stdout
1007 ret=$?
1008 if [ $ret -ne 0 ]; then
1009 diff -a -u $testroot/stdout.expected $testroot/stdout
1011 test_done "$testroot" "$ret"
1014 test_diff_commits() {
1015 local testroot=`test_init diff_commits`
1016 local commit_id0=`git_show_head $testroot/repo`
1017 alpha_id0=`get_blob_id $testroot/repo "" alpha`
1018 beta_id0=`get_blob_id $testroot/repo "" beta`
1020 got checkout $testroot/repo $testroot/wt > /dev/null
1021 ret=$?
1022 if [ $ret -ne 0 ]; then
1023 test_done "$testroot" "$ret"
1024 return 1
1027 echo "modified alpha" > $testroot/wt/alpha
1028 (cd $testroot/wt && got rm beta >/dev/null)
1029 echo "new file" > $testroot/wt/new
1030 (cd $testroot/wt && got add new >/dev/null)
1031 (cd $testroot/wt && got commit -m 'committing changes' >/dev/null)
1032 local commit_id1=`git_show_head $testroot/repo`
1034 alpha_id1=`get_blob_id $testroot/repo "" alpha`
1035 new_id1=`get_blob_id $testroot/repo "" new`
1037 echo "diff $commit_id0 refs/heads/master" > $testroot/stdout.expected
1038 echo "commit - $commit_id0" >> $testroot/stdout.expected
1039 echo "commit + $commit_id1" >> $testroot/stdout.expected
1040 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1041 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1042 echo '--- alpha' >> $testroot/stdout.expected
1043 echo '+++ alpha' >> $testroot/stdout.expected
1044 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1045 echo '-alpha' >> $testroot/stdout.expected
1046 echo '+modified alpha' >> $testroot/stdout.expected
1047 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1048 echo 'blob + /dev/null' >> $testroot/stdout.expected
1049 echo '--- beta' >> $testroot/stdout.expected
1050 echo '+++ /dev/null' >> $testroot/stdout.expected
1051 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1052 echo '-beta' >> $testroot/stdout.expected
1053 echo 'blob - /dev/null' >> $testroot/stdout.expected
1054 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1055 echo '--- /dev/null' >> $testroot/stdout.expected
1056 echo '+++ new' >> $testroot/stdout.expected
1057 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1058 echo '+new file' >> $testroot/stdout.expected
1060 (cd $testroot/wt && got diff -c master > $testroot/stdout)
1061 cmp -s $testroot/stdout.expected $testroot/stdout
1062 ret=$?
1063 if [ $ret -ne 0 ]; then
1064 diff -u $testroot/stdout.expected $testroot/stdout
1065 test_done "$testroot" "$ret"
1066 return 1
1069 # same diff with explicit parent commit ID
1070 (cd $testroot/wt && got diff -c $commit_id0 -c master \
1071 > $testroot/stdout)
1072 cmp -s $testroot/stdout.expected $testroot/stdout
1073 ret=$?
1074 if [ $ret -ne 0 ]; then
1075 diff -u $testroot/stdout.expected $testroot/stdout
1076 test_done "$testroot" "$ret"
1077 return 1
1080 # same diff with commit object IDs
1081 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1082 echo "commit - $commit_id0" >> $testroot/stdout.expected
1083 echo "commit + $commit_id1" >> $testroot/stdout.expected
1084 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1085 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1086 echo '--- alpha' >> $testroot/stdout.expected
1087 echo '+++ alpha' >> $testroot/stdout.expected
1088 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1089 echo '-alpha' >> $testroot/stdout.expected
1090 echo '+modified alpha' >> $testroot/stdout.expected
1091 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1092 echo 'blob + /dev/null' >> $testroot/stdout.expected
1093 echo '--- beta' >> $testroot/stdout.expected
1094 echo '+++ /dev/null' >> $testroot/stdout.expected
1095 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1096 echo '-beta' >> $testroot/stdout.expected
1097 echo 'blob - /dev/null' >> $testroot/stdout.expected
1098 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1099 echo '--- /dev/null' >> $testroot/stdout.expected
1100 echo '+++ new' >> $testroot/stdout.expected
1101 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1102 echo '+new file' >> $testroot/stdout.expected
1103 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 \
1104 > $testroot/stdout)
1105 cmp -s $testroot/stdout.expected $testroot/stdout
1106 ret=$?
1107 if [ $ret -ne 0 ]; then
1108 diff -u $testroot/stdout.expected $testroot/stdout
1109 test_done "$testroot" "$ret"
1110 return 1
1113 # same diff, filtered by paths
1114 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1115 echo "commit - $commit_id0" >> $testroot/stdout.expected
1116 echo "commit + $commit_id1" >> $testroot/stdout.expected
1117 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1118 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1119 echo '--- alpha' >> $testroot/stdout.expected
1120 echo '+++ alpha' >> $testroot/stdout.expected
1121 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1122 echo '-alpha' >> $testroot/stdout.expected
1123 echo '+modified alpha' >> $testroot/stdout.expected
1124 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 alpha \
1125 > $testroot/stdout)
1126 cmp -s $testroot/stdout.expected $testroot/stdout
1127 ret=$?
1128 if [ $ret -ne 0 ]; then
1129 diff -u $testroot/stdout.expected $testroot/stdout
1130 test_done "$testroot" "$ret"
1131 return 1
1133 # same in a work tree
1134 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 alpha \
1135 > $testroot/stdout)
1136 cmp -s $testroot/stdout.expected $testroot/stdout
1137 ret=$?
1138 if [ $ret -ne 0 ]; then
1139 diff -u $testroot/stdout.expected $testroot/stdout
1140 test_done "$testroot" "$ret"
1141 return 1
1144 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1145 echo "commit - $commit_id0" >> $testroot/stdout.expected
1146 echo "commit + $commit_id1" >> $testroot/stdout.expected
1147 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1148 echo 'blob + /dev/null' >> $testroot/stdout.expected
1149 echo '--- beta' >> $testroot/stdout.expected
1150 echo '+++ /dev/null' >> $testroot/stdout.expected
1151 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1152 echo '-beta' >> $testroot/stdout.expected
1153 echo 'blob - /dev/null' >> $testroot/stdout.expected
1154 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1155 echo '--- /dev/null' >> $testroot/stdout.expected
1156 echo '+++ new' >> $testroot/stdout.expected
1157 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1158 echo '+new file' >> $testroot/stdout.expected
1159 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 \
1160 beta new > $testroot/stdout)
1161 cmp -s $testroot/stdout.expected $testroot/stdout
1162 ret=$?
1163 if [ $ret -ne 0 ]; then
1164 diff -u $testroot/stdout.expected $testroot/stdout
1165 test_done "$testroot" "$ret"
1166 return 1
1169 # more than two -c options are not allowed
1170 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 -c foo \
1171 2> $testroot/stderr)
1172 ret=$?
1173 if [ $ret -eq 0 ]; then
1174 echo "diff succeeded unexpectedly" >&2
1175 test_done "$testroot" "1"
1176 return 1
1178 echo "got: too many -c options used" > $testroot/stderr.expected
1179 cmp -s $testroot/stderr.expected $testroot/stderr
1180 ret=$?
1181 if [ $ret -ne 0 ]; then
1182 diff -u $testroot/stderr.expected $testroot/stderr
1183 test_done "$testroot" "$ret"
1184 return 1
1187 # use of -c options implies a repository diff; use with -P is an error
1188 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -P foo \
1189 2> $testroot/stderr)
1190 ret=$?
1191 if [ $ret -eq 0 ]; then
1192 echo "diff succeeded unexpectedly" >&2
1193 test_done "$testroot" "1"
1194 return 1
1196 echo "got: -P option can only be used when diffing a work tree" \
1197 > $testroot/stderr.expected
1198 cmp -s $testroot/stderr.expected $testroot/stderr
1199 ret=$?
1200 if [ $ret -ne 0 ]; then
1201 diff -u $testroot/stderr.expected $testroot/stderr
1202 test_done "$testroot" "$ret"
1203 return 1
1206 # use of -c options implies a repository diff; use with -s is an error
1207 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -s foo \
1208 2> $testroot/stderr)
1209 ret=$?
1210 if [ $ret -eq 0 ]; then
1211 echo "diff succeeded unexpectedly" >&2
1212 test_done "$testroot" "1"
1213 return 1
1215 echo "got: -s option can only be used when diffing a work tree" \
1216 > $testroot/stderr.expected
1217 cmp -s $testroot/stderr.expected $testroot/stderr
1218 ret=$?
1219 if [ $ret -ne 0 ]; then
1220 diff -u $testroot/stderr.expected $testroot/stderr
1221 test_done "$testroot" "$ret"
1222 return 1
1225 # three arguments imply use of path filtering (repository case)
1226 (cd $testroot/repo && got diff $commit_id0 $commit_id1 foo \
1227 2> $testroot/stderr)
1228 ret=$?
1229 if [ $ret -eq 0 ]; then
1230 echo "diff succeeded unexpectedly" >&2
1231 test_done "$testroot" "1"
1232 return 1
1234 echo "got: specified paths cannot be resolved: no got work tree found" \
1235 > $testroot/stderr.expected
1236 cmp -s $testroot/stderr.expected $testroot/stderr
1237 ret=$?
1238 if [ $ret -ne 0 ]; then
1239 diff -u $testroot/stderr.expected $testroot/stderr
1240 test_done "$testroot" "$ret"
1241 return 1
1244 # three arguments imply use of path filtering (work tree case)
1245 (cd $testroot/wt && got diff $commit_id0 master foo \
1246 2> $testroot/stderr)
1247 ret=$?
1248 if [ $ret -eq 0 ]; then
1249 echo "diff succeeded unexpectedly" >&2
1250 test_done "$testroot" "1"
1251 return 1
1253 echo "got: $commit_id0: No such file or directory" \
1254 > $testroot/stderr.expected
1255 cmp -s $testroot/stderr.expected $testroot/stderr
1256 ret=$?
1257 if [ $ret -ne 0 ]; then
1258 diff -u $testroot/stderr.expected $testroot/stderr
1260 test_done "$testroot" "$ret"
1263 test_diff_ignored_file() {
1264 local testroot=`test_init diff_ignored_file`
1266 got checkout $testroot/repo $testroot/wt > /dev/null
1267 ret=$?
1268 if [ $ret -ne 0 ]; then
1269 test_done "$testroot" "$ret"
1270 return 1
1273 echo 1 > $testroot/wt/number
1274 (cd $testroot/wt && got add number >/dev/null)
1275 (cd $testroot/wt && got commit -m 'add number' >/dev/null)
1277 echo "**/number" > $testroot/wt/.gitignore
1279 echo 2 > $testroot/wt/number
1280 (cd $testroot/wt && got diff number | sed '1,/^@@/d' > $testroot/stdout)
1282 echo "-1" > $testroot/stdout.expected
1283 echo "+2" >> $testroot/stdout.expected
1285 cmp -s $testroot/stdout.expected $testroot/stdout
1286 ret=$?
1287 if [ $ret -ne 0 ]; then
1288 diff -u $testroot/stdout.expected $testroot/stdout
1290 test_done "$testroot" "$ret"
1293 test_diff_crlf() {
1294 local testroot=`test_init diff_crlf`
1296 got checkout $testroot/repo $testroot/wt > /dev/null
1297 ret=$?
1298 if [ $ret -ne 0 ]; then
1299 test_done "$testroot" $ret
1300 return 1
1303 printf 'test\r\n' > $testroot/wt/crlf
1304 (cd $testroot/wt && got add crlf && got commit -m +crlf) >/dev/null
1305 ret=$?
1306 if [ $ret -ne 0 ]; then
1307 test_done "$testroot" $ret
1308 return 1
1311 printf 'test 2\r\n' > $testroot/wt/crlf
1312 (cd $testroot/wt && got diff | sed -n '/^---/,$p' > $testroot/stdout)
1313 cat <<EOF > $testroot/stdout.expected
1314 --- crlf
1315 +++ crlf
1316 @@ -1 +1 @@
1317 -test
1318 +test 2
1319 EOF
1321 cmp -s $testroot/stdout.expected $testroot/stdout
1322 ret=$?
1323 if [ $ret -ne 0 ]; then
1324 diff -u $testroot/stdout.expected $testroot/stdout
1326 test_done "$testroot" $ret
1329 test_parseargs "$@"
1330 run_test test_diff_basic
1331 run_test test_diff_shows_conflict
1332 run_test test_diff_tag
1333 run_test test_diff_lightweight_tag
1334 run_test test_diff_ignore_whitespace
1335 run_test test_diff_submodule_of_same_repo
1336 run_test test_diff_symlinks_in_work_tree
1337 run_test test_diff_symlinks_in_repo
1338 run_test test_diff_binary_files
1339 run_test test_diff_commits
1340 run_test test_diff_ignored_file
1341 run_test test_diff_crlf