3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
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
26 if [ $ret -ne 0 ]; then
27 test_done
"$testroot" "$ret"
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 (mode 644)' >> $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
66 if [ $ret -ne 0 ]; then
67 diff -u $testroot/stdout.expected
$testroot/stdout
68 test_done
"$testroot" "$ret"
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
77 if [ $ret -ne 0 ]; then
78 diff -u $testroot/stderr.expected
$testroot/stderr
79 test_done
"$testroot" "$ret"
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
89 if [ $ret -ne 0 ]; then
90 diff -u $testroot/stderr.expected
$testroot/stderr
91 test_done
"$testroot" "$ret"
95 # diff non-existent path
96 (cd $testroot/wt
&& got
diff nonexistent
> $testroot/stdout \
99 echo -n > $testroot/stdout.expected
100 cmp -s $testroot/stdout.expected
$testroot/stdout
102 if [ $ret -ne 0 ]; then
103 diff -u $testroot/stdout.expected
$testroot/stdout
104 test_done
"$testroot" "$ret"
108 echo "got: nonexistent: No such file or directory" \
109 > $testroot/stderr.expected
110 cmp -s $testroot/stderr.expected
$testroot/stderr
112 if [ $ret -ne 0 ]; then
113 diff -u $testroot/stderr.expected
$testroot/stderr
114 test_done
"$testroot" "$ret"
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 (mode 644)' >> $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
160 if [ $ret -ne 0 ]; then
161 diff -u $testroot/stdout.expected
$testroot/stdout
162 test_done
"$testroot" "$ret"
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
)
170 if [ $ret -ne 0 ]; then
171 echo "diff failed unexpectedly" >&2
172 test_done
"$testroot" "1"
175 cmp -s $testroot/stdout.expected
$testroot/stdout
177 if [ $ret -ne 0 ]; then
178 diff -u $testroot/stdout.expected
$testroot/stdout
179 test_done
"$testroot" "$ret"
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
)
189 if [ $ret -ne 0 ]; then
190 echo "diff failed unexpectedly" >&2
191 test_done
"$testroot" "1"
194 cmp -s $testroot/stdout.expected
$testroot/stdout
196 if [ $ret -ne 0 ]; then
197 diff -u $testroot/stdout.expected
$testroot/stdout
198 test_done
"$testroot" "$ret"
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
)
207 if [ $ret -ne 0 ]; then
208 echo "diff failed unexpectedly" >&2
209 test_done
"$testroot" "1"
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
218 if [ $ret -ne 0 ]; then
219 diff -u $testroot/stdout.expected
$testroot/stdout
220 test_done
"$testroot" "$ret"
223 # same without a work tree
224 (cd $testroot/repo
&& got
diff master new
> $testroot/stdout
)
226 if [ $ret -ne 0 ]; then
227 echo "diff failed unexpectedly" >&2
228 test_done
"$testroot" "1"
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
236 if [ $ret -ne 0 ]; then
237 diff -u $testroot/stdout.expected
$testroot/stdout
238 test_done
"$testroot" "$ret"
241 # same with -r argument
242 got
diff -r $testroot/repo master new
> $testroot/stdout
244 if [ $ret -ne 0 ]; then
245 echo "diff failed unexpectedly" >&2
246 test_done
"$testroot" "1"
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
254 if [ $ret -ne 0 ]; then
255 diff -u $testroot/stdout.expected
$testroot/stdout
256 test_done
"$testroot" "$ret"
260 # -P can be used to force use of paths
261 (cd $testroot/wt
&& got
diff -P new master
> $testroot/stdout
)
263 if [ $ret -ne 0 ]; then
264 echo "diff failed unexpectedly" >&2
265 test_done
"$testroot" "1"
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 (mode 644)' >> $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 (mode 644)' >> $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
285 if [ $ret -ne 0 ]; then
286 diff -u $testroot/stdout.expected
$testroot/stdout
287 test_done
"$testroot" "$ret"
291 # -P can only be used in a work tree
292 got
diff -r $testroot/repo
-P new master
2> $testroot/stderr
294 if [ $ret -eq 0 ]; then
295 echo "diff succeeded unexpectedly" >&2
296 test_done
"$testroot" "1"
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
303 if [ $ret -ne 0 ]; then
304 diff -u $testroot/stderr.expected
$testroot/stderr
305 test_done
"$testroot" "$ret"
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 (mode 644)' >> $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
)
321 if [ $ret -ne 0 ]; then
322 echo "diff failed unexpectedly" >&2
323 test_done
"$testroot" "1"
326 cmp -s $testroot/stdout.expected
$testroot/stdout
328 if [ $ret -ne 0 ]; then
329 diff -u $testroot/stdout.expected
$testroot/stdout
330 test_done
"$testroot" "$ret"
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
)
338 if [ $ret -eq 0 ]; then
339 echo "diff succeeded unexpectedly" >&2
340 test_done
"$testroot" "1"
343 echo "got: $head_rev: No such file or directory" \
344 > $testroot/stderr.expected
345 cmp -s $testroot/stderr.expected
$testroot/stderr
347 if [ $ret -ne 0 ]; then
348 diff -u $testroot/stderr.expected
$testroot/stderr
349 test_done
"$testroot" "$ret"
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
)
358 if [ $ret -eq 0 ]; then
359 echo "diff succeeded unexpectedly" >&2
360 test_done
"$testroot" "1"
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 (mode 644)' >> $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
375 if [ $ret -ne 0 ]; then
376 diff -u $testroot/stdout.expected
$testroot/stdout
377 test_done
"$testroot" "$ret"
381 echo "got: $head_rev: No such file or directory" \
382 > $testroot/stderr.expected
383 cmp -s $testroot/stderr.expected
$testroot/stderr
385 if [ $ret -ne 0 ]; then
386 diff -u $testroot/stderr.expected
$testroot/stderr
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) \
396 if [ $ret -ne 0 ]; then
397 echo "diff failed unexpectedly" >&2
398 test_done
"$testroot" "$ret"
402 cat <<EOF >$testroot/diff.expected
404 blob + $alpha_new_blobid
406 +++ $alpha_new_blobid
412 cmp -s $testroot/diff.expected
$testroot/diff
414 if [ $ret -ne 0 ]; then
416 diff -u $testroot/diff.expected
$testroot/diff
417 test_done
"$testroot" "$ret"
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
441 if [ $ret -ne 0 ]; then
442 test_done
"$testroot" "$ret"
446 ed
-s $testroot/repo
/numbers
<<-\EOF
451 git_commit $testroot/repo -m "modified line 2"
452 local head_rev=`git_show_head $testroot/repo`
454 # modify lines 2 and 8 in conflicting ways
455 ed -s $testroot/wt/numbers <<-\
EOF
461 echo "C numbers" > $testroot/stdout.expected
462 echo -n "Updated to refs/heads/master: $head_rev" \
463 >> $testroot/stdout.expected
464 echo >> $testroot/stdout.expected
465 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
467 (cd $testroot/wt && got update > $testroot/stdout)
469 cmp -s $testroot/stdout.expected $testroot/stdout
471 if [ $ret -ne 0 ]; then
472 diff -u $testroot/stdout.expected $testroot/stdout
473 test_done "$testroot" "$ret"
477 echo "diff $testroot/wt" > $testroot/stdout.expected
478 echo "commit - $head_rev" >> $testroot/stdout.expected
479 echo "path
+ $testroot/wt
" >> $testroot/stdout.expected
480 echo -n 'blob - ' >> $testroot/stdout.expected
481 got tree -r $testroot/repo -i | grep 'numbers$' | cut -d' ' -f 1 \
482 >> $testroot/stdout.expected
483 echo 'file + numbers' >> $testroot/stdout.expected
484 echo '--- numbers' >> $testroot/stdout.expected
485 echo '+++ numbers' >> $testroot/stdout.expected
486 echo '@@ -1,8 +1,20 @@' >> $testroot/stdout.expected
487 echo ' 1' >> $testroot/stdout.expected
488 echo "+<<<<<<< merged change: commit $head_rev" \
489 >> $testroot/stdout.expected
490 echo ' 22' >> $testroot/stdout.expected
491 echo "+||||||| 3-way merge base: commit $base_commit" \
492 >> $testroot/stdout.expected
493 echo '+2' >> $testroot/stdout.expected
494 echo '+=======' >> $testroot/stdout.expected
495 echo '+77' >> $testroot/stdout.expected
496 echo '+>>>>>>>' >> $testroot/stdout.expected
497 echo ' 3' >> $testroot/stdout.expected
498 echo ' 4' >> $testroot/stdout.expected
499 echo ' 5' >> $testroot/stdout.expected
500 echo ' 6' >> $testroot/stdout.expected
501 echo ' 7' >> $testroot/stdout.expected
502 echo "+<<<<<<< merged change: commit $head_rev" \
503 >> $testroot/stdout.expected
504 echo ' 33' >> $testroot/stdout.expected
505 echo "+||||||| 3-way merge base: commit $base_commit" \
506 >> $testroot/stdout.expected
507 echo '+8' >> $testroot/stdout.expected
508 echo '+=======' >> $testroot/stdout.expected
509 echo '+88' >> $testroot/stdout.expected
510 echo '+>>>>>>>' >> $testroot/stdout.expected
512 (cd $testroot/wt && got diff > $testroot/stdout)
514 cmp -s $testroot/stdout.expected $testroot/stdout
516 if [ $ret -ne 0 ]; then
517 diff -u $testroot/stdout.expected $testroot/stdout
519 test_done "$testroot" "$ret"
523 local testroot=`test_init diff_tag`
524 local commit_id0=`git_show_head $testroot/repo`
528 echo "modified alpha" > $testroot/repo/alpha
529 git_commit $testroot/repo -m "changed alpha"
530 local commit_id1=`git_show_head $testroot/repo`
532 (cd $testroot/repo && git tag -m "test" $tag1)
534 echo "new file" > $testroot/repo/new
535 (cd $testroot/repo && git add new)
536 git_commit $testroot/repo -m "new file"
537 local commit_id2=`git_show_head $testroot/repo`
539 (cd $testroot/repo && git tag -m "test" $tag2)
541 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
542 echo "commit - $commit_id0" >> $testroot/stdout.expected
543 echo "commit + $commit_id1" >> $testroot/stdout.expected
544 echo -n 'blob - ' >> $testroot/stdout.expected
545 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
546 cut -d' ' -f 1 >> $testroot/stdout.expected
547 echo -n 'blob + ' >> $testroot/stdout.expected
548 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
549 >> $testroot/stdout.expected
550 echo '--- alpha' >> $testroot/stdout.expected
551 echo '+++ alpha' >> $testroot/stdout.expected
552 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
553 echo '-alpha' >> $testroot/stdout.expected
554 echo '+modified alpha' >> $testroot/stdout.expected
556 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
557 cmp -s $testroot/stdout.expected $testroot/stdout
559 if [ $ret -ne 0 ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
565 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
566 echo "commit - $commit_id1" >> $testroot/stdout.expected
567 echo "commit + $commit_id2" >> $testroot/stdout.expected
568 echo "blob - /dev/null" >> $testroot/stdout.expected
569 echo -n 'blob + ' >> $testroot/stdout.expected
570 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
571 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
572 echo " (mode 644)" >> $testroot/stdout.expected
573 echo '--- /dev/null' >> $testroot/stdout.expected
574 echo '+++ new' >> $testroot/stdout.expected
575 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
576 echo '+new file' >> $testroot/stdout.expected
578 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
579 cmp -s $testroot/stdout.expected $testroot/stdout
581 if [ $ret -ne 0 ]; then
582 diff -u $testroot/stdout.expected $testroot/stdout
584 test_done "$testroot" "$ret"
587 test_diff_lightweight_tag() {
588 local testroot=`test_init diff_tag`
589 local commit_id0=`git_show_head $testroot/repo`
593 echo "modified alpha" > $testroot/repo/alpha
594 git_commit $testroot/repo -m "changed alpha"
595 local commit_id1=`git_show_head $testroot/repo`
597 (cd $testroot/repo && git tag $tag1)
599 echo "new file" > $testroot/repo/new
600 (cd $testroot/repo && git add new)
601 git_commit $testroot/repo -m "new file"
602 local commit_id2=`git_show_head $testroot/repo`
604 (cd $testroot/repo && git tag $tag2)
606 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
607 echo "commit - $commit_id0" >> $testroot/stdout.expected
608 echo "commit + $commit_id1" >> $testroot/stdout.expected
609 echo -n 'blob - ' >> $testroot/stdout.expected
610 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
611 cut -d' ' -f 1 >> $testroot/stdout.expected
612 echo -n 'blob + ' >> $testroot/stdout.expected
613 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
614 >> $testroot/stdout.expected
615 echo '--- alpha' >> $testroot/stdout.expected
616 echo '+++ alpha' >> $testroot/stdout.expected
617 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
618 echo '-alpha' >> $testroot/stdout.expected
619 echo '+modified alpha' >> $testroot/stdout.expected
621 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
622 cmp -s $testroot/stdout.expected $testroot/stdout
624 if [ $ret -ne 0 ]; then
625 diff -u $testroot/stdout.expected $testroot/stdout
626 test_done "$testroot" "$ret"
630 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
631 echo "commit - $commit_id1" >> $testroot/stdout.expected
632 echo "commit + $commit_id2" >> $testroot/stdout.expected
633 echo "blob - /dev/null" >> $testroot/stdout.expected
634 echo -n 'blob + ' >> $testroot/stdout.expected
635 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
636 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
637 echo " (mode 644)" >> $testroot/stdout.expected
638 echo '--- /dev/null' >> $testroot/stdout.expected
639 echo '+++ new' >> $testroot/stdout.expected
640 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
641 echo '+new file' >> $testroot/stdout.expected
643 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
644 cmp -s $testroot/stdout.expected $testroot/stdout
646 if [ $ret -ne 0 ]; then
647 diff -u $testroot/stdout.expected $testroot/stdout
649 test_done "$testroot" "$ret"
652 test_diff_ignore_whitespace() {
653 local testroot=`test_init diff_ignore_whitespace`
654 local commit_id0=`git_show_head $testroot/repo`
656 got checkout $testroot/repo $testroot/wt > /dev/null
658 if [ $ret -ne 0 ]; then
659 test_done "$testroot" "$ret"
663 echo "alpha " > $testroot/wt/alpha
665 (cd $testroot/wt && got diff -w > $testroot/stdout)
667 echo "diff $testroot/wt" > $testroot/stdout.expected
668 echo "commit - $commit_id0" >> $testroot/stdout.expected
669 echo "path + $testroot/wt" >> $testroot/stdout.expected
670 echo -n 'blob - ' >> $testroot/stdout.expected
671 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
672 cut -d' ' -f 1 >> $testroot/stdout.expected
673 echo 'file + alpha' >> $testroot/stdout.expected
675 cmp -s $testroot/stdout.expected $testroot/stdout
677 if [ $ret -ne 0 ]; then
678 diff -u $testroot/stdout.expected $testroot/stdout
680 test_done "$testroot" "$ret"
683 test_diff_submodule_of_same_repo() {
684 local testroot=`test_init diff_submodule_of_same_repo`
686 (cd $testroot && git clone -q repo repo2 >/dev/null)
687 (cd $testroot/repo && git -c protocol.file.allow=always \
688 submodule -q add ../repo2)
689 (cd $testroot/repo && git commit -q -m 'adding submodule')
691 epsilon_id=$(got tree -r $testroot/repo -i | grep 'epsilon/$' | \
693 submodule_id=$(got tree -r $testroot/repo -i | grep 'repo2\$$' | \
696 # Attempt a (nonsensical) diff between a tree object and a submodule.
697 # Currently fails with "wrong type of object" error
698 got diff -r $testroot/repo $epsilon_id $submodule_id \
699 > $testroot/stdout 2> $testroot/stderr
701 if [ $ret -eq 0 ]; then
702 echo "diff command succeeded unexpectedly" >&2
703 test_done "$testroot" "1"
706 echo "got: wrong type of object" > $testroot/stderr.expected
708 cmp -s $testroot/stderr.expected $testroot/stderr
710 if [ $ret -ne 0 ]; then
711 diff -u $testroot/stderr.expected $testroot/stderr
714 test_done "$testroot" "$ret"
717 test_diff_symlinks_in_work_tree() {
718 local testroot=`test_init diff_symlinks_in_work_tree`
720 (cd $testroot/repo && ln -s alpha alpha.link)
721 (cd $testroot/repo && ln -s epsilon epsilon.link)
722 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
723 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
724 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
725 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
726 (cd $testroot/repo && git add .)
727 git_commit $testroot/repo -m "add symlinks"
728 local commit_id1=`git_show_head $testroot/repo`
730 got checkout $testroot/repo $testroot/wt > /dev/null
732 if [ $ret -ne 0 ]; then
733 test_done "$testroot" "$ret"
737 (cd $testroot/wt && ln -sf beta alpha.link)
738 (cd $testroot/wt && rm epsilon.link && ln -s gamma epsilon.link)
739 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
740 echo -n '.got/bar' > $testroot/wt/dotgotfoo.link
741 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
742 (cd $testroot/wt && ln -sf epsilon/zeta zeta.link)
743 (cd $testroot/wt && got add zeta.link > /dev/null)
744 (cd $testroot/wt && got diff > $testroot/stdout)
746 echo "diff $testroot/wt" > $testroot/stdout.expected
747 echo "commit - $commit_id1" >> $testroot/stdout.expected
748 echo "path + $testroot/wt" >> $testroot/stdout.expected
749 echo -n 'blob - ' >> $testroot/stdout.expected
750 got tree -r $testroot/repo -c $commit_id1 -i | \
751 grep 'alpha.link@ -> alpha$' | \
752 cut -d' ' -f 1 >> $testroot/stdout.expected
753 echo 'file + alpha.link' >> $testroot/stdout.expected
754 echo '--- alpha.link' >> $testroot/stdout.expected
755 echo '+++ alpha.link' >> $testroot/stdout.expected
756 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
757 echo '-alpha' >> $testroot/stdout.expected
758 echo '\ No newline at end of file' >> $testroot/stdout.expected
759 echo '+beta' >> $testroot/stdout.expected
760 echo '\ No newline at end of file' >> $testroot/stdout.expected
761 echo -n 'blob - ' >> $testroot/stdout.expected
762 got tree -r $testroot/repo -c $commit_id1 -i | \
763 grep 'dotgotfoo.link@ -> .got/foo$' | \
764 cut -d' ' -f 1 >> $testroot/stdout.expected
765 echo 'file + dotgotfoo.link' >> $testroot/stdout.expected
766 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
767 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
768 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
769 echo '-.got/foo' >> $testroot/stdout.expected
770 echo '\ No newline at end of file' >> $testroot/stdout.expected
771 echo '+.got/bar' >> $testroot/stdout.expected
772 echo '\ No newline at end of file' >> $testroot/stdout.expected
773 echo -n 'blob - ' >> $testroot/stdout.expected
774 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
775 grep 'beta.link@ -> ../beta$' | \
776 cut -d' ' -f 1 >> $testroot/stdout.expected
777 echo 'file + epsilon/beta.link' >> $testroot/stdout.expected
778 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
779 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
780 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
781 echo '-../beta' >> $testroot/stdout.expected
782 echo '\ No newline at end of file' >> $testroot/stdout.expected
783 echo '+../gamma/delta' >> $testroot/stdout.expected
784 echo '\ No newline at end of file' >> $testroot/stdout.expected
785 echo -n 'blob - ' >> $testroot/stdout.expected
786 got tree -r $testroot/repo -c $commit_id1 -i | \
787 grep 'epsilon.link@ -> epsilon$' | \
788 cut -d' ' -f 1 >> $testroot/stdout.expected
789 echo 'file + epsilon.link' >> $testroot/stdout.expected
790 echo '--- epsilon.link' >> $testroot/stdout.expected
791 echo '+++ epsilon.link' >> $testroot/stdout.expected
792 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
793 echo '-epsilon' >> $testroot/stdout.expected
794 echo '\ No newline at end of file' >> $testroot/stdout.expected
795 echo '+gamma' >> $testroot/stdout.expected
796 echo '\ No newline at end of file' >> $testroot/stdout.expected
797 echo -n 'blob - ' >> $testroot/stdout.expected
798 got tree -r $testroot/repo -c $commit_id1 -i | \
799 grep 'nonexistent.link@ -> nonexistent$' | \
800 cut -d' ' -f 1 >> $testroot/stdout.expected
801 echo 'file + /dev/null' >> $testroot/stdout.expected
802 echo '--- nonexistent.link' >> $testroot/stdout.expected
803 echo '+++ /dev/null' >> $testroot/stdout.expected
804 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
805 echo '-nonexistent' >> $testroot/stdout.expected
806 echo '\ No newline at end of file' >> $testroot/stdout.expected
807 echo 'blob - /dev/null' >> $testroot/stdout.expected
808 echo 'file + zeta.link (mode 120000)' >> $testroot/stdout.expected
809 echo '--- /dev/null' >> $testroot/stdout.expected
810 echo '+++ zeta.link' >> $testroot/stdout.expected
811 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
812 echo '+epsilon/zeta' >> $testroot/stdout.expected
813 echo '\ No newline at end of file' >> $testroot/stdout.expected
815 cmp -s $testroot/stdout.expected $testroot/stdout
817 if [ $ret -ne 0 ]; then
818 diff -u $testroot/stdout.expected $testroot/stdout
820 test_done "$testroot" "$ret"
823 test_diff_symlinks_in_repo() {
824 local testroot=`test_init diff_symlinks_in_repo`
826 (cd $testroot/repo && ln -s alpha alpha.link)
827 (cd $testroot/repo && ln -s epsilon epsilon.link)
828 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
829 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
830 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
831 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
832 (cd $testroot/repo && git add .)
833 git_commit $testroot/repo -m "add symlinks"
834 local commit_id1=`git_show_head $testroot/repo`
836 (cd $testroot/repo && ln -sf beta alpha.link)
837 (cd $testroot/repo && rm epsilon.link && ln -s gamma epsilon.link)
838 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
839 (cd $testroot/repo && ln -sf .got/bar $testroot/repo/dotgotfoo.link)
840 (cd $testroot/repo && git rm -q nonexistent.link)
841 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
842 (cd $testroot/repo && git add .)
843 git_commit $testroot/repo -m "change symlinks"
844 local commit_id2=`git_show_head $testroot/repo`
846 got diff -r $testroot/repo $commit_id1 $commit_id2 > $testroot/stdout
848 echo "diff $commit_id1 $commit_id2" > $testroot/stdout.expected
849 echo "commit - $commit_id1" >> $testroot/stdout.expected
850 echo "commit + $commit_id2" >> $testroot/stdout.expected
851 echo -n 'blob - ' >> $testroot/stdout.expected
852 got tree -r $testroot/repo -c $commit_id1 -i | \
853 grep 'alpha.link@ -> alpha$' | \
854 cut -d' ' -f 1 >> $testroot/stdout.expected
855 echo -n 'blob + ' >> $testroot/stdout.expected
856 got tree -r $testroot/repo -c $commit_id2 -i | \
857 grep 'alpha.link@ -> beta$' | \
858 cut -d' ' -f 1 >> $testroot/stdout.expected
859 echo '--- alpha.link' >> $testroot/stdout.expected
860 echo '+++ alpha.link' >> $testroot/stdout.expected
861 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
862 echo '-alpha' >> $testroot/stdout.expected
863 echo '\ No newline at end of file' >> $testroot/stdout.expected
864 echo '+beta' >> $testroot/stdout.expected
865 echo '\ No newline at end of file' >> $testroot/stdout.expected
866 echo -n 'blob - ' >> $testroot/stdout.expected
867 got tree -r $testroot/repo -c $commit_id1 -i | \
868 grep 'dotgotfoo.link@ -> .got/foo$' | \
869 cut -d' ' -f 1 >> $testroot/stdout.expected
870 echo -n 'blob + ' >> $testroot/stdout.expected
871 got tree -r $testroot/repo -c $commit_id2 -i | \
872 grep 'dotgotfoo.link@ -> .got/bar$' | \
873 cut -d' ' -f 1 >> $testroot/stdout.expected
874 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
875 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
876 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
877 echo '-.got/foo' >> $testroot/stdout.expected
878 echo '\ No newline at end of file' >> $testroot/stdout.expected
879 echo '+.got/bar' >> $testroot/stdout.expected
880 echo '\ No newline at end of file' >> $testroot/stdout.expected
881 echo -n 'blob - ' >> $testroot/stdout.expected
882 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
883 grep 'beta.link@ -> ../beta$' | \
884 cut -d' ' -f 1 >> $testroot/stdout.expected
885 echo -n 'blob + ' >> $testroot/stdout.expected
886 got tree -r $testroot/repo -c $commit_id2 -i epsilon | \
887 grep 'beta.link@ -> ../gamma/delta$' | \
888 cut -d' ' -f 1 >> $testroot/stdout.expected
889 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
890 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
891 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
892 echo '-../beta' >> $testroot/stdout.expected
893 echo '\ No newline at end of file' >> $testroot/stdout.expected
894 echo '+../gamma/delta' >> $testroot/stdout.expected
895 echo '\ No newline at end of file' >> $testroot/stdout.expected
896 echo -n 'blob - ' >> $testroot/stdout.expected
897 got tree -r $testroot/repo -c $commit_id1 -i | \
898 grep 'epsilon.link@ -> epsilon$' | \
899 cut -d' ' -f 1 >> $testroot/stdout.expected
900 echo -n 'blob + ' >> $testroot/stdout.expected
901 got tree -r $testroot/repo -c $commit_id2 -i | \
902 grep 'epsilon.link@ -> gamma$' | \
903 cut -d' ' -f 1 >> $testroot/stdout.expected
904 echo '--- epsilon.link' >> $testroot/stdout.expected
905 echo '+++ epsilon.link' >> $testroot/stdout.expected
906 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
907 echo '-epsilon' >> $testroot/stdout.expected
908 echo '\ No newline at end of file' >> $testroot/stdout.expected
909 echo '+gamma' >> $testroot/stdout.expected
910 echo '\ No newline at end of file' >> $testroot/stdout.expected
911 echo -n 'blob - ' >> $testroot/stdout.expected
912 got tree -r $testroot/repo -c $commit_id1 -i | \
913 grep 'nonexistent.link@ -> nonexistent$' | \
914 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
915 >> $testroot/stdout.expected
916 echo 'blob + /dev/null' >> $testroot/stdout.expected
917 echo '--- nonexistent.link' >> $testroot/stdout.expected
918 echo '+++ /dev/null' >> $testroot/stdout.expected
919 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
920 echo '-nonexistent' >> $testroot/stdout.expected
921 echo '\ No newline at end of file' >> $testroot/stdout.expected
922 echo 'blob - /dev/null' >> $testroot/stdout.expected
923 echo -n 'blob + ' >> $testroot/stdout.expected
924 got tree -r $testroot/repo -c $commit_id2 -i | \
925 grep 'zeta.link@ -> epsilon/zeta$' | \
926 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
927 >> $testroot/stdout.expected
928 echo '--- /dev/null' >> $testroot/stdout.expected
929 echo '+++ zeta.link' >> $testroot/stdout.expected
930 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
931 echo '+epsilon/zeta' >> $testroot/stdout.expected
932 echo '\ No newline at end of file' >> $testroot/stdout.expected
934 cmp -s $testroot/stdout.expected $testroot/stdout
936 if [ $ret -ne 0 ]; then
937 diff -u $testroot/stdout.expected $testroot/stdout
939 test_done "$testroot" "$ret"
942 test_diff_binary_files() {
943 local testroot=`test_init diff_binary_files`
944 local head_rev=`git_show_head $testroot/repo`
946 got checkout $testroot/repo $testroot/wt > /dev/null
948 if [ $ret -ne 0 ]; then
949 test_done "$testroot" "$ret"
953 printf '\377\377\0\0\377\377\0\0' > $testroot/wt/foo
954 (cd $testroot/wt && got add foo >/dev/null)
956 echo "diff $testroot/wt" > $testroot/stdout.expected
957 echo "commit - $head_rev" >> $testroot/stdout.expected
958 echo "path + $testroot/wt" >> $testroot/stdout.expected
959 echo 'blob - /dev/null' >> $testroot/stdout.expected
960 echo 'file + foo (mode 644)' >> $testroot/stdout.expected
961 echo "Binary files /dev/null and foo differ" \
962 >> $testroot/stdout.expected
964 (cd $testroot/wt && got diff > $testroot/stdout)
965 cmp -s $testroot/stdout.expected $testroot/stdout
967 if [ $ret -ne 0 ]; then
968 diff -a -u $testroot/stdout.expected $testroot/stdout
969 test_done "$testroot" "$ret"
973 echo "diff $testroot/wt" > $testroot/stdout.expected
974 echo "commit - $head_rev" >> $testroot/stdout.expected
975 echo "path + $testroot/wt" >> $testroot/stdout.expected
976 echo 'blob - /dev/null' >> $testroot/stdout.expected
977 echo 'file + foo (mode 644)' >> $testroot/stdout.expected
978 echo '--- /dev/null' >> $testroot/stdout.expected
979 echo '+++ foo' >> $testroot/stdout.expected
980 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
981 printf '+\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
982 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
984 (cd $testroot/wt && got diff -a > $testroot/stdout)
985 cmp -s $testroot/stdout.expected $testroot/stdout
987 if [ $ret -ne 0 ]; then
988 diff -a -u $testroot/stdout.expected $testroot/stdout
989 test_done "$testroot" "$ret"
993 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
994 local head_rev=`git_show_head $testroot/repo`
996 printf '\377\200\0\0\377\200\0\0' > $testroot/wt/foo
998 echo "diff $testroot/wt" > $testroot/stdout.expected
999 echo "commit - $head_rev" >> $testroot/stdout.expected
1000 echo "path + $testroot/wt" >> $testroot/stdout.expected
1001 echo -n 'blob - ' >> $testroot/stdout.expected
1002 got tree -r $testroot/repo -i | grep 'foo$' | cut -d' ' -f 1 \
1003 >> $testroot/stdout.expected
1004 echo 'file + foo' >> $testroot/stdout.expected
1005 echo '--- foo' >> $testroot/stdout.expected
1006 echo '+++ foo' >> $testroot/stdout.expected
1007 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1008 printf -- '-\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
1009 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
1010 printf '+\377\200\0\0\377\200\0\0\n' >> $testroot/stdout.expected
1011 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
1013 (cd $testroot/wt && got diff -a > $testroot/stdout)
1014 cmp -s $testroot/stdout.expected $testroot/stdout
1016 if [ $ret -ne 0 ]; then
1017 diff -a -u $testroot/stdout.expected $testroot/stdout
1019 test_done "$testroot" "$ret"
1022 test_diff_commits() {
1023 local testroot=`test_init diff_commits`
1024 local commit_id0=`git_show_head $testroot/repo`
1025 local alpha_id0=`get_blob_id $testroot/repo "" alpha`
1026 local beta_id0=`get_blob_id $testroot/repo "" beta`
1028 got checkout $testroot/repo $testroot/wt > /dev/null
1030 if [ $ret -ne 0 ]; then
1031 test_done "$testroot" "$ret"
1035 echo "modified alpha" > $testroot/wt/alpha
1036 (cd $testroot/wt && got rm beta >/dev/null)
1037 echo "new file" > $testroot/wt/new
1038 (cd $testroot/wt && got add new >/dev/null)
1039 (cd $testroot/wt && got commit -m 'committing changes' >/dev/null)
1040 local commit_id1=`git_show_head $testroot/repo`
1042 alpha_id1=`get_blob_id $testroot/repo "" alpha`
1043 new_id1=`get_blob_id $testroot/repo "" new`
1045 echo "diff $commit_id0 refs/heads/master" > $testroot/stdout.expected
1046 echo "commit - $commit_id0" >> $testroot/stdout.expected
1047 echo "commit + $commit_id1" >> $testroot/stdout.expected
1048 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1049 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1050 echo '--- alpha' >> $testroot/stdout.expected
1051 echo '+++ alpha' >> $testroot/stdout.expected
1052 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1053 echo '-alpha' >> $testroot/stdout.expected
1054 echo '+modified alpha' >> $testroot/stdout.expected
1055 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1056 echo 'blob + /dev/null' >> $testroot/stdout.expected
1057 echo '--- beta' >> $testroot/stdout.expected
1058 echo '+++ /dev/null' >> $testroot/stdout.expected
1059 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1060 echo '-beta' >> $testroot/stdout.expected
1061 echo 'blob - /dev/null' >> $testroot/stdout.expected
1062 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1063 echo '--- /dev/null' >> $testroot/stdout.expected
1064 echo '+++ new' >> $testroot/stdout.expected
1065 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1066 echo '+new file' >> $testroot/stdout.expected
1068 (cd $testroot/wt && got diff -c master > $testroot/stdout)
1069 cmp -s $testroot/stdout.expected $testroot/stdout
1071 if [ $ret -ne 0 ]; then
1072 diff -u $testroot/stdout.expected $testroot/stdout
1073 test_done "$testroot" "$ret"
1077 # same diff with explicit parent commit ID
1078 (cd $testroot/wt && got diff -c $commit_id0 -c master \
1080 cmp -s $testroot/stdout.expected $testroot/stdout
1082 if [ $ret -ne 0 ]; then
1083 diff -u $testroot/stdout.expected $testroot/stdout
1084 test_done "$testroot" "$ret"
1088 # same diff with commit object IDs
1089 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1090 echo "commit - $commit_id0" >> $testroot/stdout.expected
1091 echo "commit + $commit_id1" >> $testroot/stdout.expected
1092 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1093 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1094 echo '--- alpha' >> $testroot/stdout.expected
1095 echo '+++ alpha' >> $testroot/stdout.expected
1096 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1097 echo '-alpha' >> $testroot/stdout.expected
1098 echo '+modified alpha' >> $testroot/stdout.expected
1099 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1100 echo 'blob + /dev/null' >> $testroot/stdout.expected
1101 echo '--- beta' >> $testroot/stdout.expected
1102 echo '+++ /dev/null' >> $testroot/stdout.expected
1103 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1104 echo '-beta' >> $testroot/stdout.expected
1105 echo 'blob - /dev/null' >> $testroot/stdout.expected
1106 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1107 echo '--- /dev/null' >> $testroot/stdout.expected
1108 echo '+++ new' >> $testroot/stdout.expected
1109 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1110 echo '+new file' >> $testroot/stdout.expected
1111 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 \
1113 cmp -s $testroot/stdout.expected $testroot/stdout
1115 if [ $ret -ne 0 ]; then
1116 diff -u $testroot/stdout.expected $testroot/stdout
1117 test_done "$testroot" "$ret"
1121 # same diff, filtered by paths
1122 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1123 echo "commit - $commit_id0" >> $testroot/stdout.expected
1124 echo "commit + $commit_id1" >> $testroot/stdout.expected
1125 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1126 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1127 echo '--- alpha' >> $testroot/stdout.expected
1128 echo '+++ alpha' >> $testroot/stdout.expected
1129 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1130 echo '-alpha' >> $testroot/stdout.expected
1131 echo '+modified alpha' >> $testroot/stdout.expected
1132 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 alpha \
1134 cmp -s $testroot/stdout.expected $testroot/stdout
1136 if [ $ret -ne 0 ]; then
1137 diff -u $testroot/stdout.expected $testroot/stdout
1138 test_done "$testroot" "$ret"
1141 # same in a work tree
1142 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 alpha \
1144 cmp -s $testroot/stdout.expected $testroot/stdout
1146 if [ $ret -ne 0 ]; then
1147 diff -u $testroot/stdout.expected $testroot/stdout
1148 test_done "$testroot" "$ret"
1152 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1153 echo "commit - $commit_id0" >> $testroot/stdout.expected
1154 echo "commit + $commit_id1" >> $testroot/stdout.expected
1155 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1156 echo 'blob + /dev/null' >> $testroot/stdout.expected
1157 echo '--- beta' >> $testroot/stdout.expected
1158 echo '+++ /dev/null' >> $testroot/stdout.expected
1159 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1160 echo '-beta' >> $testroot/stdout.expected
1161 echo 'blob - /dev/null' >> $testroot/stdout.expected
1162 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1163 echo '--- /dev/null' >> $testroot/stdout.expected
1164 echo '+++ new' >> $testroot/stdout.expected
1165 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1166 echo '+new file' >> $testroot/stdout.expected
1167 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 \
1168 beta new > $testroot/stdout)
1169 cmp -s $testroot/stdout.expected $testroot/stdout
1171 if [ $ret -ne 0 ]; then
1172 diff -u $testroot/stdout.expected $testroot/stdout
1173 test_done "$testroot" "$ret"
1177 # more than two -c options are not allowed
1178 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 -c foo \
1179 2> $testroot/stderr)
1181 if [ $ret -eq 0 ]; then
1182 echo "diff succeeded unexpectedly" >&2
1183 test_done "$testroot" "1"
1186 echo "got: too many -c options used" > $testroot/stderr.expected
1187 cmp -s $testroot/stderr.expected $testroot/stderr
1189 if [ $ret -ne 0 ]; then
1190 diff -u $testroot/stderr.expected $testroot/stderr
1191 test_done "$testroot" "$ret"
1195 # use of -c options implies a repository diff; use with -P is an error
1196 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -P foo \
1197 2> $testroot/stderr)
1199 if [ $ret -eq 0 ]; then
1200 echo "diff succeeded unexpectedly" >&2
1201 test_done "$testroot" "1"
1204 echo "got: -P option can only be used when diffing a work tree" \
1205 > $testroot/stderr.expected
1206 cmp -s $testroot/stderr.expected $testroot/stderr
1208 if [ $ret -ne 0 ]; then
1209 diff -u $testroot/stderr.expected $testroot/stderr
1210 test_done "$testroot" "$ret"
1214 # use of -c options implies a repository diff; use with -s is an error
1215 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -s foo \
1216 2> $testroot/stderr)
1218 if [ $ret -eq 0 ]; then
1219 echo "diff succeeded unexpectedly" >&2
1220 test_done "$testroot" "1"
1223 echo "got: -s option can only be used when diffing a work tree" \
1224 > $testroot/stderr.expected
1225 cmp -s $testroot/stderr.expected $testroot/stderr
1227 if [ $ret -ne 0 ]; then
1228 diff -u $testroot/stderr.expected $testroot/stderr
1229 test_done "$testroot" "$ret"
1233 # three arguments imply use of path filtering (repository case)
1234 (cd $testroot/repo && got diff $commit_id0 $commit_id1 foo \
1235 2> $testroot/stderr)
1237 if [ $ret -eq 0 ]; then
1238 echo "diff succeeded unexpectedly" >&2
1239 test_done "$testroot" "1"
1242 echo "got: specified paths cannot be resolved: no got work tree found" \
1243 > $testroot/stderr.expected
1244 cmp -s $testroot/stderr.expected $testroot/stderr
1246 if [ $ret -ne 0 ]; then
1247 diff -u $testroot/stderr.expected $testroot/stderr
1248 test_done "$testroot" "$ret"
1252 # three arguments imply use of path filtering (work tree case)
1253 (cd $testroot/wt && got diff $commit_id0 master foo \
1254 2> $testroot/stderr)
1256 if [ $ret -eq 0 ]; then
1257 echo "diff succeeded unexpectedly" >&2
1258 test_done "$testroot" "1"
1261 echo "got: $commit_id0: No such file or directory" \
1262 > $testroot/stderr.expected
1263 cmp -s $testroot/stderr.expected $testroot/stderr
1265 if [ $ret -ne 0 ]; then
1266 diff -u $testroot/stderr.expected $testroot/stderr
1268 test_done "$testroot" "$ret"
1271 test_diff_ignored_file() {
1272 local testroot=`test_init diff_ignored_file`
1274 got checkout $testroot/repo $testroot/wt > /dev/null
1276 if [ $ret -ne 0 ]; then
1277 test_done "$testroot" "$ret"
1281 echo 1 > $testroot/wt/number
1282 (cd $testroot/wt && got add number >/dev/null)
1283 (cd $testroot/wt && got commit -m 'add number' >/dev/null)
1285 echo "**/number" > $testroot/wt/.gitignore
1287 echo 2 > $testroot/wt/number
1288 (cd $testroot/wt && got diff number | sed '1,/^@@/d' > $testroot/stdout)
1290 echo "-1" > $testroot/stdout.expected
1291 echo "+2" >> $testroot/stdout.expected
1293 cmp -s $testroot/stdout.expected $testroot/stdout
1295 if [ $ret -ne 0 ]; then
1296 diff -u $testroot/stdout.expected $testroot/stdout
1298 test_done "$testroot" "$ret"
1302 local testroot=`test_init diff_crlf`
1304 got checkout $testroot/repo $testroot/wt > /dev/null
1306 if [ $ret -ne 0 ]; then
1307 test_done "$testroot" $ret
1311 printf 'one\r\ntwo\r\nthree\r\n' > $testroot/wt/crlf
1312 (cd $testroot/wt && got add crlf && got commit -m +crlf) >/dev/null
1314 if [ $ret -ne 0 ]; then
1315 test_done "$testroot" $ret
1319 printf 'one\r\ntwain\r\nthree\r\n' > $testroot/wt/crlf
1320 (cd $testroot/wt && got diff | sed -n '/^---/,$l' > $testroot/stdout)
1321 cat <<\EOF > $testroot/stdout.expected
1331 cmp -s $testroot/stdout.expected $testroot/stdout
1333 if [ $ret -ne 0 ]; then
1334 diff -u $testroot/stdout.expected $testroot/stdout
1336 test_done "$testroot" $ret
1339 test_diff_worktree_newfile_xbit() {
1340 local testroot=`test_init diff_worktree_newfile_xbit`
1342 got checkout $testroot/repo $testroot/wt > /dev/null
1344 if [ $ret -ne 0 ]; then
1345 test_done "$testroot" $ret
1349 echo xfile > $testroot/wt/xfile
1350 chmod +x $testroot/wt/xfile
1351 (cd $testroot/wt && got add xfile) > /dev/null
1353 if [ $ret -ne 0 ]; then
1354 test_done "$testroot" $ret
1357 (cd $testroot/wt && got diff) > $testroot/stdout
1359 if [ $ret -ne 0 ]; then
1360 test_done "$testroot" $ret
1364 local commit_id=`git_show_head $testroot/repo`
1365 cat <<EOF > $testroot/stdout.expected
1370 file + xfile (mode 755)
1377 cmp -s $testroot/stdout.expected $testroot/stdout
1379 if [ $ret -ne 0 ]; then
1380 echo "failed to record mode 755"
1381 diff -u $testroot/stdout.expected $testroot/stdout
1383 test_done "$testroot" $ret
1386 test_diff_commit_diffstat() {
1387 local testroot=`test_init diff_commit_diffstat`
1388 local commit_id0=`git_show_head $testroot/repo`
1389 local alpha_id0=`get_blob_id $testroot/repo "" alpha`
1390 local beta_id0=`get_blob_id $testroot/repo "" beta`
1392 got checkout $testroot/repo $testroot/wt > /dev/null
1394 if [ $ret -ne 0 ]; then
1395 test_done "$testroot" "$ret"
1399 echo "modified alpha" > $testroot/wt/alpha
1400 (cd $testroot/wt && got rm beta >/dev/null)
1401 echo "new file" > $testroot/wt/new
1402 (cd $testroot/wt && got add new >/dev/null)
1403 (cd $testroot/wt && got commit -m 'committing changes' >/dev/null)
1404 local commit_id1=`git_show_head $testroot/repo`
1406 local alpha_id1=`get_blob_id $testroot/repo "" alpha`
1407 local new_id1=`get_blob_id $testroot/repo "" new`
1409 cat <<EOF >$testroot/stdout.expected
1410 diffstat $commit_id0 refs/heads/master
1415 3 files changed, 2 insertions(+), 2 deletions(-)
1419 echo "diff $commit_id0 refs/heads/master" >> $testroot/stdout.expected
1420 echo "commit - $commit_id0" >> $testroot/stdout.expected
1421 echo "commit + $commit_id1" >> $testroot/stdout.expected
1422 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1423 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1424 echo '--- alpha' >> $testroot/stdout.expected
1425 echo '+++ alpha' >> $testroot/stdout.expected
1426 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1427 echo '-alpha' >> $testroot/stdout.expected
1428 echo '+modified alpha' >> $testroot/stdout.expected
1429 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1430 echo 'blob + /dev/null' >> $testroot/stdout.expected
1431 echo '--- beta' >> $testroot/stdout.expected
1432 echo '+++ /dev/null' >> $testroot/stdout.expected
1433 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1434 echo '-beta' >> $testroot/stdout.expected
1435 echo 'blob - /dev/null' >> $testroot/stdout.expected
1436 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1437 echo '--- /dev/null' >> $testroot/stdout.expected
1438 echo '+++ new' >> $testroot/stdout.expected
1439 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1440 echo '+new file' >> $testroot/stdout.expected
1442 (cd $testroot/wt && got diff -d -c master > $testroot/stdout)
1443 cmp -s $testroot/stdout.expected $testroot/stdout
1445 if [ $ret -ne 0 ]; then
1446 diff -u $testroot/stdout.expected $testroot/stdout
1447 test_done "$testroot" "$ret"
1451 # same diffstat with explicit parent commit ID
1452 (cd $testroot/wt && got diff -d -c $commit_id0 -c master \
1454 cmp -s $testroot/stdout.expected $testroot/stdout
1456 if [ $ret -ne 0 ]; then
1457 diff -u $testroot/stdout.expected $testroot/stdout
1458 test_done "$testroot" "$ret"
1462 cat <<EOF >$testroot/stdout.expected
1463 diffstat $commit_id0 $commit_id1
1468 3 files changed, 2 insertions(+), 2 deletions(-)
1472 # same diffstat with commit object IDs
1473 echo "diff $commit_id0 $commit_id1" >> $testroot/stdout.expected
1474 echo "commit - $commit_id0" >> $testroot/stdout.expected
1475 echo "commit + $commit_id1" >> $testroot/stdout.expected
1476 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1477 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1478 echo '--- alpha' >> $testroot/stdout.expected
1479 echo '+++ alpha' >> $testroot/stdout.expected
1480 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1481 echo '-alpha' >> $testroot/stdout.expected
1482 echo '+modified alpha' >> $testroot/stdout.expected
1483 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1484 echo 'blob + /dev/null' >> $testroot/stdout.expected
1485 echo '--- beta' >> $testroot/stdout.expected
1486 echo '+++ /dev/null' >> $testroot/stdout.expected
1487 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1488 echo '-beta' >> $testroot/stdout.expected
1489 echo 'blob - /dev/null' >> $testroot/stdout.expected
1490 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1491 echo '--- /dev/null' >> $testroot/stdout.expected
1492 echo '+++ new' >> $testroot/stdout.expected
1493 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1494 echo '+new file' >> $testroot/stdout.expected
1495 (cd $testroot/wt && got diff -d -c $commit_id0 -c $commit_id1 \
1497 cmp -s $testroot/stdout.expected $testroot/stdout
1499 if [ $ret -ne 0 ]; then
1500 diff -u $testroot/stdout.expected $testroot/stdout
1501 test_done "$testroot" "$ret"
1505 cat <<EOF >$testroot/stdout.expected
1506 diffstat $commit_id0 $commit_id1
1509 1 file changed, 1 insertion(+), 1 deletion(-)
1513 # same diffstat filtered by path "alpha"
1514 echo "diff $commit_id0 $commit_id1" >> $testroot/stdout.expected
1515 echo "commit - $commit_id0" >> $testroot/stdout.expected
1516 echo "commit + $commit_id1" >> $testroot/stdout.expected
1517 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1518 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1519 echo '--- alpha' >> $testroot/stdout.expected
1520 echo '+++ alpha' >> $testroot/stdout.expected
1521 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1522 echo '-alpha' >> $testroot/stdout.expected
1523 echo '+modified alpha' >> $testroot/stdout.expected
1524 (cd $testroot/repo && got diff -d -c $commit_id0 -c $commit_id1 alpha \
1526 cmp -s $testroot/stdout.expected $testroot/stdout
1528 if [ $ret -ne 0 ]; then
1529 diff -u $testroot/stdout.expected $testroot/stdout
1530 test_done "$testroot" "$ret"
1533 # same diffstat in work tree
1534 (cd $testroot/wt && got diff -d -c $commit_id0 -c $commit_id1 alpha \
1536 cmp -s $testroot/stdout.expected $testroot/stdout
1538 if [ $ret -ne 0 ]; then
1539 diff -u $testroot/stdout.expected $testroot/stdout
1540 test_done "$testroot" "$ret"
1544 cat <<EOF >$testroot/stdout.expected
1545 diffstat $commit_id0 $commit_id1
1549 2 files changed, 1 insertion(+), 1 deletion(-)
1553 # same diffstat filtered by paths "beta" and "new"
1554 echo "diff $commit_id0 $commit_id1" >> $testroot/stdout.expected
1555 echo "commit - $commit_id0" >> $testroot/stdout.expected
1556 echo "commit + $commit_id1" >> $testroot/stdout.expected
1557 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1558 echo 'blob + /dev/null' >> $testroot/stdout.expected
1559 echo '--- beta' >> $testroot/stdout.expected
1560 echo '+++ /dev/null' >> $testroot/stdout.expected
1561 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1562 echo '-beta' >> $testroot/stdout.expected
1563 echo 'blob - /dev/null' >> $testroot/stdout.expected
1564 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1565 echo '--- /dev/null' >> $testroot/stdout.expected
1566 echo '+++ new' >> $testroot/stdout.expected
1567 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1568 echo '+new file' >> $testroot/stdout.expected
1569 (cd $testroot/repo && got diff -d -c $commit_id0 -c $commit_id1 \
1570 beta new > $testroot/stdout)
1571 cmp -s $testroot/stdout.expected $testroot/stdout
1573 if [ $ret -ne 0 ]; then
1574 diff -u $testroot/stdout.expected $testroot/stdout
1576 test_done "$testroot" "$ret"
1579 test_diff_worktree_diffstat() {
1580 local testroot=`test_init diff_worktree_diffstat`
1581 local head_rev=`git_show_head $testroot/repo`
1582 local alpha_blobid=`get_blob_id $testroot/repo "" alpha`
1584 got checkout $testroot/repo $testroot/wt > /dev/null
1586 if [ $ret -ne 0 ]; then
1587 test_done "$testroot" "$ret"
1591 echo "modified alpha" > $testroot/wt/alpha
1592 (cd $testroot/wt && got rm beta >/dev/null)
1593 echo "new file" > $testroot/wt/new
1594 (cd $testroot/wt && got add new >/dev/null)
1596 cat <<EOF >$testroot/stdout.expected
1597 diffstat $testroot/wt
1602 3 files changed, 2 insertions(+), 2 deletions(-)
1606 echo "diff $testroot/wt" >> $testroot/stdout.expected
1607 echo "commit - $head_rev" >> $testroot/stdout.expected
1608 echo "path + $testroot/wt" >> $testroot/stdout.expected
1609 echo -n 'blob - ' >> $testroot/stdout.expected
1610 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
1611 >> $testroot/stdout.expected
1612 echo 'file + alpha' >> $testroot/stdout.expected
1613 echo '--- alpha' >> $testroot/stdout.expected
1614 echo '+++ alpha' >> $testroot/stdout.expected
1615 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1616 echo '-alpha' >> $testroot/stdout.expected
1617 echo '+modified alpha' >> $testroot/stdout.expected
1618 echo -n 'blob - ' >> $testroot/stdout.expected
1619 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1620 >> $testroot/stdout.expected
1621 echo 'file + /dev/null' >> $testroot/stdout.expected
1622 echo '--- beta' >> $testroot/stdout.expected
1623 echo '+++ /dev/null' >> $testroot/stdout.expected
1624 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1625 echo '-beta' >> $testroot/stdout.expected
1626 echo 'blob - /dev/null' >> $testroot/stdout.expected
1627 echo 'file + new (mode 644)' >> $testroot/stdout.expected
1628 echo '--- /dev/null' >> $testroot/stdout.expected
1629 echo '+++ new' >> $testroot/stdout.expected
1630 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1631 echo '+new file' >> $testroot/stdout.expected
1633 (cd $testroot/wt && got diff -d > $testroot/stdout)
1634 cmp -s $testroot/stdout.expected $testroot/stdout
1636 if [ $ret -ne 0 ]; then
1637 diff -u $testroot/stdout.expected $testroot/stdout
1638 test_done "$testroot" "$ret"
1642 echo "modified zeta" > $testroot/wt/epsilon/zeta
1644 cat <<EOF >$testroot/stdout.expected
1645 diffstat $testroot/wt
1648 M epsilon/zeta | 1+ 1-
1651 4 files changed, 3 insertions(+), 3 deletions(-)
1655 # specify paths to diffstat
1656 echo "diff $testroot/wt" >> $testroot/stdout.expected
1657 echo "commit - $head_rev" >> $testroot/stdout.expected
1658 echo "path + $testroot/wt" >> $testroot/stdout.expected
1659 echo -n 'blob - ' >> $testroot/stdout.expected
1660 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
1661 >> $testroot/stdout.expected
1662 echo 'file + alpha' >> $testroot/stdout.expected
1663 echo '--- alpha' >> $testroot/stdout.expected
1664 echo '+++ alpha' >> $testroot/stdout.expected
1665 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1666 echo '-alpha' >> $testroot/stdout.expected
1667 echo '+modified alpha' >> $testroot/stdout.expected
1668 echo -n 'blob - ' >> $testroot/stdout.expected
1669 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1670 >> $testroot/stdout.expected
1671 echo 'file + /dev/null' >> $testroot/stdout.expected
1672 echo '--- beta' >> $testroot/stdout.expected
1673 echo '+++ /dev/null' >> $testroot/stdout.expected
1674 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1675 echo '-beta' >> $testroot/stdout.expected
1676 echo -n 'blob - ' >> $testroot/stdout.expected
1677 got tree -r $testroot/repo -i epsilon | grep 'zeta$' | cut -d' ' -f 1 \
1678 >> $testroot/stdout.expected
1679 echo 'file + epsilon/zeta' >> $testroot/stdout.expected
1680 echo '--- epsilon/zeta' >> $testroot/stdout.expected
1681 echo '+++ epsilon/zeta' >> $testroot/stdout.expected
1682 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1683 echo '-zeta' >> $testroot/stdout.expected
1684 echo '+modified zeta' >> $testroot/stdout.expected
1685 echo 'blob - /dev/null' >> $testroot/stdout.expected
1686 echo 'file + new (mode 644)' >> $testroot/stdout.expected
1687 echo '--- /dev/null' >> $testroot/stdout.expected
1688 echo '+++ new' >> $testroot/stdout.expected
1689 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1690 echo '+new file' >> $testroot/stdout.expected
1692 (cd $testroot/wt && got diff -d new alpha epsilon beta > $testroot/stdout)
1693 cmp -s $testroot/stdout.expected $testroot/stdout
1695 if [ $ret -ne 0 ]; then
1696 diff -u $testroot/stdout.expected $testroot/stdout
1697 test_done "$testroot" "$ret"
1701 # same diff irrespective of argument order
1702 (cd $testroot/wt && got diff -d alpha new epsilon beta \
1703 > $testroot/stdout 2> $testroot/stderr)
1705 if [ $ret -ne 0 ]; then
1706 echo "diff failed unexpectedly" >&2
1707 test_done "$testroot" "1"
1710 cmp -s $testroot/stdout.expected $testroot/stdout
1712 if [ $ret -ne 0 ]; then
1713 diff -u $testroot/stdout.expected $testroot/stdout
1714 test_done "$testroot" "$ret"
1718 # force paths with -P
1719 echo master > $testroot/wt/master
1720 (cd $testroot/wt && got add master > /dev/null)
1721 (cd $testroot/wt && got diff -d -P new master > $testroot/stdout)
1723 if [ $ret -ne 0 ]; then
1724 echo "diff failed unexpectedly" >&2
1725 test_done "$testroot" "1"
1729 cat <<EOF >$testroot/stdout.expected
1730 diffstat $testroot/wt
1734 2 files changed, 2 insertions(+), 0 deletions(-)
1738 echo "diff $testroot/wt" >> $testroot/stdout.expected
1739 echo "commit - $head_rev" >> $testroot/stdout.expected
1740 echo "path + $testroot/wt" >> $testroot/stdout.expected
1741 echo 'blob - /dev/null' >> $testroot/stdout.expected
1742 echo 'file + master (mode 644)' >> $testroot/stdout.expected
1743 echo '--- /dev/null' >> $testroot/stdout.expected
1744 echo '+++ master' >> $testroot/stdout.expected
1745 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1746 echo '+master' >> $testroot/stdout.expected
1747 echo 'blob - /dev/null' >> $testroot/stdout.expected
1748 echo 'file + new (mode 644)' >> $testroot/stdout.expected
1749 echo '--- /dev/null' >> $testroot/stdout.expected
1750 echo '+++ new' >> $testroot/stdout.expected
1751 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1752 echo '+new file' >> $testroot/stdout.expected
1753 cmp -s $testroot/stdout.expected $testroot/stdout
1755 if [ $ret -ne 0 ]; then
1756 diff -u $testroot/stdout.expected $testroot/stdout
1757 test_done "$testroot" "$ret"
1762 (cd $testroot/wt && got commit -m 'edit' alpha >/dev/null)
1763 local alpha_new_blobid=`get_blob_id $testroot/repo "" alpha`
1764 (cd $testroot/wt && got diff -d $alpha_blobid $alpha_new_blobid) \
1767 if [ $ret -ne 0 ]; then
1768 echo "diff failed unexpectedly" >&2
1769 test_done "$testroot" "$ret"
1773 short_alpha_id=$(printf '%.10s' $alpha_blobid)
1774 short_alpha_new_id=$(printf '%.10s' $alpha_new_blobid)
1775 cat <<EOF >$testroot/stdout.expected
1776 diffstat $alpha_blobid $alpha_new_blobid
1777 M $short_alpha_id -> $short_alpha_new_id | 1+ 1-
1779 1 file changed, 1 insertion(+), 1 deletion(-)
1781 blob - $alpha_blobid
1782 blob + $alpha_new_blobid
1784 +++ $alpha_new_blobid
1790 cmp -s $testroot/stdout.expected $testroot/stdout
1792 if [ $ret -ne 0 ]; then
1793 diff -u $testroot/stdout.expected $testroot/stdout
1795 test_done "$testroot" "$ret"
1798 test_diff_file_to_dir() {
1799 local testroot=`test_init diff_file_to_dir`
1800 local commit_id0=`git_show_head $testroot/repo`
1801 local alpha_blobid=`get_blob_id $testroot/repo "" alpha`
1803 got checkout $testroot/repo $testroot/wt > /dev/null
1805 if [ $ret -ne 0 ]; then
1806 test_done "$testroot" "$ret"
1810 git_rm $testroot/repo alpha
1811 mkdir $testroot/repo/alpha
1812 echo eta > $testroot/repo/alpha/eta
1813 (cd $testroot/repo && git add alpha/eta)
1814 git_commit $testroot/repo -m "changed alpha into directory"
1815 local commit_id1=`git_show_head $testroot/repo`
1816 local alpha_eta_blobid=`get_blob_id $testroot/repo alpha eta`
1818 cat <<EOF >$testroot/stdout.expected
1819 diff $commit_id0 $commit_id1
1820 commit - $commit_id0
1821 commit + $commit_id1
1822 blob - $alpha_blobid (mode 644)
1829 blob + $alpha_eta_blobid (mode 644)
1835 got diff -r $testroot/repo $commit_id0 $commit_id1 > $testroot/stdout
1837 if [ $ret -ne 0 ]; then
1838 echo "diff failed unexpectedly" >&2
1839 test_done "$testroot" "1"
1843 cmp -s $testroot/stdout.expected $testroot/stdout
1845 if [ $ret -ne 0 ]; then
1846 diff -u $testroot/stdout.expected $testroot/stdout
1847 test_done "$testroot" "$ret"
1851 local author_time=`git_show_author_time $testroot/repo`
1852 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1853 cat <<EOF >$testroot/stdout.expected
1854 -----------------------------------------------
1855 commit $commit_id1 (master)
1859 changed alpha into directory
1866 got log -P -r $testroot/repo -l1 -c $commit_id1 > $testroot/stdout
1868 if [ $ret -ne 0 ]; then
1869 echo "diff failed unexpectedly" >&2
1870 test_done "$testroot" "1"
1874 cmp -s $testroot/stdout.expected $testroot/stdout
1876 if [ $ret -ne 0 ]; then
1877 diff -u $testroot/stdout.expected $testroot/stdout
1879 test_done "$testroot" "$ret"
1882 test_diff_dir_to_file() {
1883 local testroot=`test_init diff_file_to_dir`
1884 local commit_id0=`git_show_head $testroot/repo`
1885 local epsilon_zeta_blobid=`get_blob_id $testroot/repo epsilon zeta`
1887 got checkout $testroot/repo $testroot/wt > /dev/null
1889 if [ $ret -ne 0 ]; then
1890 test_done "$testroot" "$ret"
1894 git_rmdir $testroot/repo epsilon
1895 echo epsilon > $testroot/repo/epsilon
1896 (cd $testroot/repo && git add epsilon)
1897 git_commit $testroot/repo -m "changed epsilon into file"
1898 local commit_id1=`git_show_head $testroot/repo`
1899 local epsilon_blobid=`get_blob_id $testroot/repo "" epsilon`
1901 cat <<EOF >$testroot/stdout.expected
1902 diff $commit_id0 $commit_id1
1903 commit - $commit_id0
1904 commit + $commit_id1
1905 blob - $epsilon_zeta_blobid (mode 644)
1912 blob + $epsilon_blobid (mode 644)
1918 got diff -r $testroot/repo $commit_id0 $commit_id1 > $testroot/stdout
1920 if [ $ret -ne 0 ]; then
1921 echo "diff failed unexpectedly" >&2
1922 test_done "$testroot" "1"
1926 cmp -s $testroot/stdout.expected $testroot/stdout
1928 if [ $ret -ne 0 ]; then
1929 diff -u $testroot/stdout.expected $testroot/stdout
1930 test_done "$testroot" "$ret"
1934 local author_time=`git_show_author_time $testroot/repo`
1935 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1936 cat <<EOF >$testroot/stdout.expected
1937 -----------------------------------------------
1938 commit $commit_id1 (master)
1942 changed epsilon into file
1949 got log -P -r $testroot/repo -l1 -c $commit_id1 > $testroot/stdout
1951 if [ $ret -ne 0 ]; then
1952 echo "diff failed unexpectedly" >&2
1953 test_done "$testroot" "1"
1957 cmp -s $testroot/stdout.expected $testroot/stdout
1959 if [ $ret -ne 0 ]; then
1960 diff -u $testroot/stdout.expected $testroot/stdout
1962 test_done "$testroot" "$ret"
1965 test_diff_path_in_root_commit() {
1966 local testroot=`test_init diff_path_in_root_commit`
1967 local commit_id=`git_show_head $testroot/repo`
1968 local alpha_blobid=`get_blob_id $testroot/repo "" alpha`
1970 got checkout $testroot/repo $testroot/wt > /dev/null
1972 if [ $ret -ne 0 ]; then
1973 test_done "$testroot" "$ret"
1977 (cd $testroot/wt && got diff -c $commit_id alpha > $testroot/stdout)
1979 cat <<EOF >$testroot/stdout.expected
1980 diff /dev/null $commit_id
1984 blob + $alpha_blobid (mode 644)
1991 cmp -s $testroot/stdout.expected $testroot/stdout
1993 if [ $ret -ne 0 ]; then
1994 diff -u $testroot/stdout.expected $testroot/stdout
1995 test_done "$testroot" "$ret"
1999 # diff non-existent path
2000 (cd $testroot/wt && got diff -c $commit_id nonexistent \
2001 > $testroot/stdout 2> $testroot/stderr)
2003 echo -n > $testroot/stdout.expected
2004 cmp -s $testroot/stdout.expected $testroot/stdout
2006 if [ $ret -ne 0 ]; then
2007 diff -u $testroot/stdout.expected $testroot/stdout
2008 test_done "$testroot" "$ret"
2012 echo "got: nonexistent: no such entry found in tree" \
2013 > $testroot/stderr.expected
2014 cmp -s $testroot/stderr.expected $testroot/stderr
2016 if [ $ret -ne 0 ]; then
2017 diff -u $testroot/stderr.expected $testroot/stderr
2018 test_done "$testroot" "$ret"
2022 test_done "$testroot" "$ret"
2025 test_diff_commit_keywords() {
2026 local testroot=`test_init diff_commit_keywords`
2028 got checkout $testroot/repo $testroot/wt > /dev/null
2030 if [ $ret -ne 0 ]; then
2031 echo "checkout failed unexpectedly" >&2
2032 test_done "$testroot" "$ret"
2036 set -A ids "$(git_show_head $testroot/repo)"
2037 set -A alpha_ids "$(get_blob_id $testroot/repo "" alpha)"
2038 set -A beta_ids "$(get_blob_id $testroot/repo "" beta)"
2040 for i in `seq 8`; do
2041 if [ $(( i % 2 )) -eq 0 ]; then
2042 echo "alpha change $i" > "$testroot/wt/alpha"
2044 echo "beta change $i" > "$testroot/wt/beta"
2047 (cd "$testroot/wt" && got ci -m "commit number $i" > /dev/null)
2049 if [ $ret -ne 0 ]; then
2050 echo "commit failed unexpectedly" >&2
2051 test_done "$testroot" "$ret"
2055 if [ $(( i % 2 )) -eq 0 ]; then
2056 set -- "$alpha_ids" \
2057 "$(get_blob_id $testroot/repo "" alpha)"
2060 set -- "$beta_ids" \
2061 "$(get_blob_id $testroot/repo "" beta)"
2065 set -- "$ids" "$(git_show_head $testroot/repo)"
2069 echo "diff $(pop_id 7 $ids) $(pop_id 8 $ids)" > \
2070 $testroot/stdout.expected
2071 echo "commit - $(pop_id 7 $ids)" >> $testroot/stdout.expected
2072 echo "commit + $(pop_id 8 $ids)" >> $testroot/stdout.expected
2073 echo "blob - $(pop_id 4 $beta_ids)" >> $testroot/stdout.expected
2074 echo "blob + $(pop_id 5 $beta_ids)" >> $testroot/stdout.expected
2075 echo '--- beta' >> $testroot/stdout.expected
2076 echo '+++ beta' >> $testroot/stdout.expected
2077 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2078 echo '-beta change 5' >> $testroot/stdout.expected
2079 echo '+beta change 7' >> $testroot/stdout.expected
2081 (cd $testroot/wt && got diff -cmaster:- > $testroot/stdout)
2083 if [ $ret -ne 0 ]; then
2084 echo "diff failed unexpectedly" >&2
2085 test_done "$testroot" "1"
2089 cmp -s $testroot/stdout.expected $testroot/stdout
2091 if [ $ret -ne 0 ]; then
2092 diff -u $testroot/stdout.expected $testroot/stdout
2093 test_done "$testroot" "$ret"
2097 (cd $testroot/wt && got update -c:head:-6 > /dev/null)
2099 if [ $ret -ne 0 ]; then
2100 echo "update failed unexpectedly" >&2
2101 test_done "$testroot" "1"
2105 echo "diff $(pop_id 1 $ids) $(pop_id 2 $ids)" > \
2106 $testroot/stdout.expected
2107 echo "commit - $(pop_id 1 $ids)" >> $testroot/stdout.expected
2108 echo "commit + $(pop_id 2 $ids)" >> $testroot/stdout.expected
2109 echo "blob - $(pop_id 1 $beta_ids)" >> $testroot/stdout.expected
2110 echo "blob + $(pop_id 2 $beta_ids)" >> $testroot/stdout.expected
2111 echo '--- beta' >> $testroot/stdout.expected
2112 echo '+++ beta' >> $testroot/stdout.expected
2113 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2114 echo '-beta' >> $testroot/stdout.expected
2115 echo '+beta change 1' >> $testroot/stdout.expected
2117 (cd $testroot/wt && got diff -c:base:- > $testroot/stdout)
2119 if [ $ret -ne 0 ]; then
2120 echo "diff failed unexpectedly" >&2
2121 test_done "$testroot" "1"
2125 cmp -s $testroot/stdout.expected $testroot/stdout
2127 if [ $ret -ne 0 ]; then
2128 diff -u $testroot/stdout.expected $testroot/stdout
2129 test_done "$testroot" "$ret"
2133 echo "diff $(pop_id 3 $ids) $(pop_id 4 $ids)" > \
2134 $testroot/stdout.expected
2135 echo "commit - $(pop_id 3 $ids)" >> $testroot/stdout.expected
2136 echo "commit + $(pop_id 4 $ids)" >> $testroot/stdout.expected
2137 echo "blob - $(pop_id 2 $beta_ids)" >> $testroot/stdout.expected
2138 echo "blob + $(pop_id 3 $beta_ids)" >> $testroot/stdout.expected
2139 echo '--- beta' >> $testroot/stdout.expected
2140 echo '+++ beta' >> $testroot/stdout.expected
2141 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2142 echo '-beta change 1' >> $testroot/stdout.expected
2143 echo '+beta change 3' >> $testroot/stdout.expected
2145 (cd $testroot/wt && got diff -c:base:+ > $testroot/stdout)
2147 if [ $ret -ne 0 ]; then
2148 echo "diff failed unexpectedly" >&2
2149 test_done "$testroot" "1"
2153 cmp -s $testroot/stdout.expected $testroot/stdout
2155 if [ $ret -ne 0 ]; then
2156 diff -u $testroot/stdout.expected $testroot/stdout
2157 test_done "$testroot" "$ret"
2161 # if modifier extends beyond HEAD, we should use HEAD ref
2162 echo "diff $(pop_id 8 $ids) $(pop_id 9 $ids)" > \
2163 $testroot/stdout.expected
2164 echo "commit - $(pop_id 8 $ids)" >> $testroot/stdout.expected
2165 echo "commit + $(pop_id 9 $ids)" >> $testroot/stdout.expected
2166 echo "blob - $(pop_id 4 $alpha_ids)" >> $testroot/stdout.expected
2167 echo "blob + $(pop_id 5 $alpha_ids)" >> $testroot/stdout.expected
2168 echo '--- alpha' >> $testroot/stdout.expected
2169 echo '+++ alpha' >> $testroot/stdout.expected
2170 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2171 echo '-alpha change 6' >> $testroot/stdout.expected
2172 echo '+alpha change 8' >> $testroot/stdout.expected
2174 (cd $testroot/wt && got diff -c:base:+20 > $testroot/stdout)
2176 if [ $ret -ne 0 ]; then
2177 echo "diff failed unexpectedly" >&2
2178 test_done "$testroot" "1"
2182 cmp -s $testroot/stdout.expected $testroot/stdout
2184 if [ $ret -ne 0 ]; then
2185 diff -u $testroot/stdout.expected $testroot/stdout
2186 test_done "$testroot" "$ret"
2190 echo "diff $(pop_id 3 $ids) $(pop_id 9 $ids)" > \
2191 $testroot/stdout.expected
2192 echo "commit - $(pop_id 3 $ids)" >> $testroot/stdout.expected
2193 echo "commit + $(pop_id 9 $ids)" >> $testroot/stdout.expected
2194 echo "blob - $(pop_id 2 $alpha_ids)" >> $testroot/stdout.expected
2195 echo "blob + $(pop_id 5 $alpha_ids)" >> $testroot/stdout.expected
2196 echo '--- alpha' >> $testroot/stdout.expected
2197 echo '+++ alpha' >> $testroot/stdout.expected
2198 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2199 echo '-alpha change 2' >> $testroot/stdout.expected
2200 echo '+alpha change 8' >> $testroot/stdout.expected
2201 echo "blob - $(pop_id 2 $beta_ids)" >> $testroot/stdout.expected
2202 echo "blob + $(pop_id 5 $beta_ids)" >> $testroot/stdout.expected
2203 echo '--- beta' >> $testroot/stdout.expected
2204 echo '+++ beta' >> $testroot/stdout.expected
2205 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2206 echo '-beta change 1' >> $testroot/stdout.expected
2207 echo '+beta change 7' >> $testroot/stdout.expected
2209 (cd $testroot/wt && got diff -c:base -c:head > $testroot/stdout)
2211 if [ $ret -ne 0 ]; then
2212 echo "diff failed unexpectedly" >&2
2213 test_done "$testroot" "1"
2217 cmp -s $testroot/stdout.expected $testroot/stdout
2219 if [ $ret -ne 0 ]; then
2220 diff -u $testroot/stdout.expected $testroot/stdout
2221 test_done "$testroot" "$ret"
2225 echo "diff $(pop_id 6 $ids) $(pop_id 8 $ids)" > \
2226 $testroot/stdout.expected
2227 echo "commit - $(pop_id 6 $ids)" >> $testroot/stdout.expected
2228 echo "commit + $(pop_id 8 $ids)" >> $testroot/stdout.expected
2229 echo "blob - $(pop_id 3 $alpha_ids)" >> $testroot/stdout.expected
2230 echo "blob + $(pop_id 4 $alpha_ids)" >> $testroot/stdout.expected
2231 echo '--- alpha' >> $testroot/stdout.expected
2232 echo '+++ alpha' >> $testroot/stdout.expected
2233 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2234 echo '-alpha change 4' >> $testroot/stdout.expected
2235 echo '+alpha change 6' >> $testroot/stdout.expected
2236 echo "blob - $(pop_id 4 $beta_ids)" >> $testroot/stdout.expected
2237 echo "blob + $(pop_id 5 $beta_ids)" >> $testroot/stdout.expected
2238 echo '--- beta' >> $testroot/stdout.expected
2239 echo '+++ beta' >> $testroot/stdout.expected
2240 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2241 echo '-beta change 5' >> $testroot/stdout.expected
2242 echo '+beta change 7' >> $testroot/stdout.expected
2244 got diff -r "$testroot/repo" -cmaster:-3 -c:head:-1 > $testroot/stdout
2246 if [ $ret -ne 0 ]; then
2247 echo "diff failed unexpectedly" >&2
2248 test_done "$testroot" "1"
2252 cmp -s $testroot/stdout.expected $testroot/stdout
2254 if [ $ret -ne 0 ]; then
2255 diff -u $testroot/stdout.expected $testroot/stdout
2256 test_done "$testroot" "$ret"
2260 echo "'-c BASE' requires work tree" > "$testroot/stderr.expected"
2262 got diff -r "$testroot/repo" -c:base -c:head 2> $testroot/stderr
2264 cmp -s $testroot/stdout.expected $testroot/stdout
2266 if [ $ret -ne 0 ]; then
2267 diff -u $testroot/stdout.expected $testroot/stdout
2270 test_done "$testroot" "$ret"
2274 run_test test_diff_basic
2275 run_test test_diff_shows_conflict
2276 run_test test_diff_tag
2277 run_test test_diff_lightweight_tag
2278 run_test test_diff_ignore_whitespace
2279 run_test test_diff_submodule_of_same_repo
2280 run_test test_diff_symlinks_in_work_tree
2281 run_test test_diff_symlinks_in_repo
2282 run_test test_diff_binary_files
2283 run_test test_diff_commits
2284 run_test test_diff_ignored_file
2285 run_test test_diff_crlf
2286 run_test test_diff_worktree_newfile_xbit
2287 run_test test_diff_commit_diffstat
2288 run_test test_diff_worktree_diffstat
2289 run_test test_diff_file_to_dir
2290 run_test test_diff_dir_to_file
2291 run_test test_diff_path_in_root_commit
2292 run_test test_diff_commit_keywords