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 (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
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 (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
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 (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
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 (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)
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 (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
374 ret=$?
375 if [ $ret -ne 0 ]; then
376 diff -u $testroot/stdout.expected $testroot/stdout
377 test_done "$testroot" "$ret"
378 return 1
379 fi
381 echo "got: $head_rev: No such file or directory" \
382 > $testroot/stderr.expected
383 cmp -s $testroot/stderr.expected $testroot/stderr
384 ret=$?
385 if [ $ret -ne 0 ]; then
386 diff -u $testroot/stderr.expected $testroot/stderr
387 return 1
388 fi
390 # diff two blob ids
391 (cd $testroot/wt && got commit -m 'edit' alpha >/dev/null)
392 local alpha_new_blobid=`get_blob_id $testroot/repo "" alpha`
393 (cd $testroot/wt && got diff $alpha_blobid $alpha_new_blobid) \
394 > $testroot/diff
395 ret=$?
396 if [ $ret -ne 0 ]; then
397 echo "diff failed unexpectedly" >&2
398 test_done "$testroot" "$ret"
399 return 1
400 fi
402 cat <<EOF >$testroot/diff.expected
403 blob - $alpha_blobid
404 blob + $alpha_new_blobid
405 --- $alpha_blobid
406 +++ $alpha_new_blobid
407 @@ -1 +1 @@
408 -alpha
409 +modified alpha
410 EOF
412 cmp -s $testroot/diff.expected $testroot/diff
413 ret=$?
414 if [ $ret -ne 0 ]; then
415 echo
416 diff -u $testroot/diff.expected $testroot/diff
417 test_done "$testroot" "$ret"
418 return 1
419 fi
421 test_done "$testroot" "$ret"
424 test_diff_shows_conflict() {
425 local testroot=`test_init diff_shows_conflict 1`
427 echo "1" > $testroot/repo/numbers
428 echo "2" >> $testroot/repo/numbers
429 echo "3" >> $testroot/repo/numbers
430 echo "4" >> $testroot/repo/numbers
431 echo "5" >> $testroot/repo/numbers
432 echo "6" >> $testroot/repo/numbers
433 echo "7" >> $testroot/repo/numbers
434 echo "8" >> $testroot/repo/numbers
435 (cd $testroot/repo && git add numbers)
436 git_commit $testroot/repo -m "added numbers file"
437 local base_commit=`git_show_head $testroot/repo`
439 got checkout $testroot/repo $testroot/wt > /dev/null
440 ret=$?
441 if [ $ret -ne 0 ]; then
442 test_done "$testroot" "$ret"
443 return 1
444 fi
446 ed -s $testroot/repo/numbers <<-\EOF
447 ,s/2/22/
448 ,s/8/33/
450 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
456 ,s/2/77/
457 ,s/8/88/
459 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
470 ret=$?
471 if [ $ret -ne 0 ]; then
472 diff -u $testroot/stdout.expected $testroot/stdout
473 test_done "$testroot" "$ret"
474 return 1
475 fi
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
515 ret=$?
516 if [ $ret -ne 0 ]; then
517 diff -u $testroot/stdout.expected $testroot/stdout
518 fi
519 test_done "$testroot" "$ret"
522 test_diff_tag() {
523 local testroot=`test_init diff_tag`
524 local commit_id0=`git_show_head $testroot/repo`
525 local tag1=1.0.0
526 local tag2=2.0.0
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
558 ret=$?
559 if [ $ret -ne 0 ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
562 return 1
563 fi
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
580 ret=$?
581 if [ $ret -ne 0 ]; then
582 diff -u $testroot/stdout.expected $testroot/stdout
583 fi
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`
590 local tag1=1.0.0
591 local tag2=2.0.0
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
623 ret=$?
624 if [ $ret -ne 0 ]; then
625 diff -u $testroot/stdout.expected $testroot/stdout
626 test_done "$testroot" "$ret"
627 return 1
628 fi
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
645 ret=$?
646 if [ $ret -ne 0 ]; then
647 diff -u $testroot/stdout.expected $testroot/stdout
648 fi
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
657 ret=$?
658 if [ $ret -ne 0 ]; then
659 test_done "$testroot" "$ret"
660 return 1
661 fi
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
676 ret=$?
677 if [ $ret -ne 0 ]; then
678 diff -u $testroot/stdout.expected $testroot/stdout
679 fi
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/$' | \
692 cut -d ' ' -f 1)
693 submodule_id=$(got tree -r $testroot/repo -i | grep 'repo2\$$' | \
694 cut -d ' ' -f 1)
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
700 ret=$?
701 if [ $ret -eq 0 ]; then
702 echo "diff command succeeded unexpectedly" >&2
703 test_done "$testroot" "1"
704 return 1
705 fi
706 echo "got: wrong type of object" > $testroot/stderr.expected
708 cmp -s $testroot/stderr.expected $testroot/stderr
709 ret=$?
710 if [ $ret -ne 0 ]; then
711 diff -u $testroot/stderr.expected $testroot/stderr
712 return 1
713 fi
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
731 ret=$?
732 if [ $ret -ne 0 ]; then
733 test_done "$testroot" "$ret"
734 return 1
735 fi
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
816 ret=$?
817 if [ $ret -ne 0 ]; then
818 diff -u $testroot/stdout.expected $testroot/stdout
819 fi
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
935 ret=$?
936 if [ $ret -ne 0 ]; then
937 diff -u $testroot/stdout.expected $testroot/stdout
938 fi
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
947 ret=$?
948 if [ $ret -ne 0 ]; then
949 test_done "$testroot" "$ret"
950 return 1
951 fi
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
966 ret=$?
967 if [ $ret -ne 0 ]; then
968 diff -a -u $testroot/stdout.expected $testroot/stdout
969 test_done "$testroot" "$ret"
970 return 1
971 fi
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
986 ret=$?
987 if [ $ret -ne 0 ]; then
988 diff -a -u $testroot/stdout.expected $testroot/stdout
989 test_done "$testroot" "$ret"
990 return 1
991 fi
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
1015 ret=$?
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
1029 ret=$?
1030 if [ $ret -ne 0 ]; then
1031 test_done "$testroot" "$ret"
1032 return 1
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
1070 ret=$?
1071 if [ $ret -ne 0 ]; then
1072 diff -u $testroot/stdout.expected $testroot/stdout
1073 test_done "$testroot" "$ret"
1074 return 1
1077 # same diff with explicit parent commit ID
1078 (cd $testroot/wt && got diff -c $commit_id0 -c master \
1079 > $testroot/stdout)
1080 cmp -s $testroot/stdout.expected $testroot/stdout
1081 ret=$?
1082 if [ $ret -ne 0 ]; then
1083 diff -u $testroot/stdout.expected $testroot/stdout
1084 test_done "$testroot" "$ret"
1085 return 1
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 \
1112 > $testroot/stdout)
1113 cmp -s $testroot/stdout.expected $testroot/stdout
1114 ret=$?
1115 if [ $ret -ne 0 ]; then
1116 diff -u $testroot/stdout.expected $testroot/stdout
1117 test_done "$testroot" "$ret"
1118 return 1
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 \
1133 > $testroot/stdout)
1134 cmp -s $testroot/stdout.expected $testroot/stdout
1135 ret=$?
1136 if [ $ret -ne 0 ]; then
1137 diff -u $testroot/stdout.expected $testroot/stdout
1138 test_done "$testroot" "$ret"
1139 return 1
1141 # same in a work tree
1142 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 alpha \
1143 > $testroot/stdout)
1144 cmp -s $testroot/stdout.expected $testroot/stdout
1145 ret=$?
1146 if [ $ret -ne 0 ]; then
1147 diff -u $testroot/stdout.expected $testroot/stdout
1148 test_done "$testroot" "$ret"
1149 return 1
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
1170 ret=$?
1171 if [ $ret -ne 0 ]; then
1172 diff -u $testroot/stdout.expected $testroot/stdout
1173 test_done "$testroot" "$ret"
1174 return 1
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)
1180 ret=$?
1181 if [ $ret -eq 0 ]; then
1182 echo "diff succeeded unexpectedly" >&2
1183 test_done "$testroot" "1"
1184 return 1
1186 echo "got: too many -c options used" > $testroot/stderr.expected
1187 cmp -s $testroot/stderr.expected $testroot/stderr
1188 ret=$?
1189 if [ $ret -ne 0 ]; then
1190 diff -u $testroot/stderr.expected $testroot/stderr
1191 test_done "$testroot" "$ret"
1192 return 1
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)
1198 ret=$?
1199 if [ $ret -eq 0 ]; then
1200 echo "diff succeeded unexpectedly" >&2
1201 test_done "$testroot" "1"
1202 return 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
1207 ret=$?
1208 if [ $ret -ne 0 ]; then
1209 diff -u $testroot/stderr.expected $testroot/stderr
1210 test_done "$testroot" "$ret"
1211 return 1
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)
1217 ret=$?
1218 if [ $ret -eq 0 ]; then
1219 echo "diff succeeded unexpectedly" >&2
1220 test_done "$testroot" "1"
1221 return 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
1226 ret=$?
1227 if [ $ret -ne 0 ]; then
1228 diff -u $testroot/stderr.expected $testroot/stderr
1229 test_done "$testroot" "$ret"
1230 return 1
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)
1236 ret=$?
1237 if [ $ret -eq 0 ]; then
1238 echo "diff succeeded unexpectedly" >&2
1239 test_done "$testroot" "1"
1240 return 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
1245 ret=$?
1246 if [ $ret -ne 0 ]; then
1247 diff -u $testroot/stderr.expected $testroot/stderr
1248 test_done "$testroot" "$ret"
1249 return 1
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)
1255 ret=$?
1256 if [ $ret -eq 0 ]; then
1257 echo "diff succeeded unexpectedly" >&2
1258 test_done "$testroot" "1"
1259 return 1
1261 echo "got: $commit_id0: No such file or directory" \
1262 > $testroot/stderr.expected
1263 cmp -s $testroot/stderr.expected $testroot/stderr
1264 ret=$?
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
1275 ret=$?
1276 if [ $ret -ne 0 ]; then
1277 test_done "$testroot" "$ret"
1278 return 1
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
1294 ret=$?
1295 if [ $ret -ne 0 ]; then
1296 diff -u $testroot/stdout.expected $testroot/stdout
1298 test_done "$testroot" "$ret"
1301 test_diff_crlf() {
1302 local testroot=`test_init diff_crlf`
1304 got checkout $testroot/repo $testroot/wt > /dev/null
1305 ret=$?
1306 if [ $ret -ne 0 ]; then
1307 test_done "$testroot" $ret
1308 return 1
1311 printf 'test\r\n' > $testroot/wt/crlf
1312 (cd $testroot/wt && got add crlf && got commit -m +crlf) >/dev/null
1313 ret=$?
1314 if [ $ret -ne 0 ]; then
1315 test_done "$testroot" $ret
1316 return 1
1319 printf 'test 2\r\n' > $testroot/wt/crlf
1320 (cd $testroot/wt && got diff | sed -n '/^---/,$p' > $testroot/stdout)
1321 cat <<EOF > $testroot/stdout.expected
1322 --- crlf
1323 +++ crlf
1324 @@ -1 +1 @@
1325 -test
1326 +test 2
1327 EOF
1329 cmp -s $testroot/stdout.expected $testroot/stdout
1330 ret=$?
1331 if [ $ret -ne 0 ]; then
1332 diff -u $testroot/stdout.expected $testroot/stdout
1334 test_done "$testroot" $ret
1337 test_diff_worktree_newfile_xbit() {
1338 local testroot=`test_init diff_worktree_newfile_xbit`
1340 got checkout $testroot/repo $testroot/wt > /dev/null
1341 ret=$?
1342 if [ $ret -ne 0 ]; then
1343 test_done "$testroot" $ret
1344 return 1
1347 echo xfile > $testroot/wt/xfile
1348 chmod +x $testroot/wt/xfile
1349 (cd $testroot/wt && got add xfile) > /dev/null
1350 ret=$?
1351 if [ $ret -ne 0 ]; then
1352 test_done "$testroot" $ret
1353 return 1
1355 (cd $testroot/wt && got diff) > $testroot/stdout
1356 ret=$?
1357 if [ $ret -ne 0 ]; then
1358 test_done "$testroot" $ret
1359 return 1
1362 local commit_id=`git_show_head $testroot/repo`
1363 cat <<EOF > $testroot/stdout.expected
1364 diff $testroot/wt
1365 commit - $commit_id
1366 path + $testroot/wt
1367 blob - /dev/null
1368 file + xfile (mode 755)
1369 --- /dev/null
1370 +++ xfile
1371 @@ -0,0 +1 @@
1372 +xfile
1373 EOF
1375 cmp -s $testroot/stdout.expected $testroot/stdout
1376 ret=$?
1377 if [ $ret -ne 0 ]; then
1378 echo "failed to record mode 755"
1379 diff -u $testroot/stdout.expected $testroot/stdout
1381 test_done "$testroot" $ret
1384 test_diff_commit_diffstat() {
1385 local testroot=`test_init diff_commit_diffstat`
1386 local commit_id0=`git_show_head $testroot/repo`
1387 local alpha_id0=`get_blob_id $testroot/repo "" alpha`
1388 local beta_id0=`get_blob_id $testroot/repo "" beta`
1390 got checkout $testroot/repo $testroot/wt > /dev/null
1391 ret=$?
1392 if [ $ret -ne 0 ]; then
1393 test_done "$testroot" "$ret"
1394 return 1
1397 echo "modified alpha" > $testroot/wt/alpha
1398 (cd $testroot/wt && got rm beta >/dev/null)
1399 echo "new file" > $testroot/wt/new
1400 (cd $testroot/wt && got add new >/dev/null)
1401 (cd $testroot/wt && got commit -m 'committing changes' >/dev/null)
1402 local commit_id1=`git_show_head $testroot/repo`
1404 local alpha_id1=`get_blob_id $testroot/repo "" alpha`
1405 local new_id1=`get_blob_id $testroot/repo "" new`
1407 cat <<EOF >$testroot/stdout.expected
1408 diffstat $commit_id0 refs/heads/master
1409 M alpha | 1+ 1-
1410 D beta | 0+ 1-
1411 A new | 1+ 0-
1413 3 files changed, 2 insertions(+), 2 deletions(-)
1415 EOF
1417 echo "diff $commit_id0 refs/heads/master" >> $testroot/stdout.expected
1418 echo "commit - $commit_id0" >> $testroot/stdout.expected
1419 echo "commit + $commit_id1" >> $testroot/stdout.expected
1420 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1421 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1422 echo '--- alpha' >> $testroot/stdout.expected
1423 echo '+++ alpha' >> $testroot/stdout.expected
1424 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1425 echo '-alpha' >> $testroot/stdout.expected
1426 echo '+modified alpha' >> $testroot/stdout.expected
1427 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1428 echo 'blob + /dev/null' >> $testroot/stdout.expected
1429 echo '--- beta' >> $testroot/stdout.expected
1430 echo '+++ /dev/null' >> $testroot/stdout.expected
1431 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1432 echo '-beta' >> $testroot/stdout.expected
1433 echo 'blob - /dev/null' >> $testroot/stdout.expected
1434 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1435 echo '--- /dev/null' >> $testroot/stdout.expected
1436 echo '+++ new' >> $testroot/stdout.expected
1437 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1438 echo '+new file' >> $testroot/stdout.expected
1440 (cd $testroot/wt && got diff -d -c master > $testroot/stdout)
1441 cmp -s $testroot/stdout.expected $testroot/stdout
1442 ret=$?
1443 if [ $ret -ne 0 ]; then
1444 diff -u $testroot/stdout.expected $testroot/stdout
1445 test_done "$testroot" "$ret"
1446 return 1
1449 # same diffstat with explicit parent commit ID
1450 (cd $testroot/wt && got diff -d -c $commit_id0 -c master \
1451 > $testroot/stdout)
1452 cmp -s $testroot/stdout.expected $testroot/stdout
1453 ret=$?
1454 if [ $ret -ne 0 ]; then
1455 diff -u $testroot/stdout.expected $testroot/stdout
1456 test_done "$testroot" "$ret"
1457 return 1
1460 cat <<EOF >$testroot/stdout.expected
1461 diffstat $commit_id0 $commit_id1
1462 M alpha | 1+ 1-
1463 D beta | 0+ 1-
1464 A new | 1+ 0-
1466 3 files changed, 2 insertions(+), 2 deletions(-)
1468 EOF
1470 # same diffstat with commit object IDs
1471 echo "diff $commit_id0 $commit_id1" >> $testroot/stdout.expected
1472 echo "commit - $commit_id0" >> $testroot/stdout.expected
1473 echo "commit + $commit_id1" >> $testroot/stdout.expected
1474 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1475 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1476 echo '--- alpha' >> $testroot/stdout.expected
1477 echo '+++ alpha' >> $testroot/stdout.expected
1478 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1479 echo '-alpha' >> $testroot/stdout.expected
1480 echo '+modified alpha' >> $testroot/stdout.expected
1481 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1482 echo 'blob + /dev/null' >> $testroot/stdout.expected
1483 echo '--- beta' >> $testroot/stdout.expected
1484 echo '+++ /dev/null' >> $testroot/stdout.expected
1485 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1486 echo '-beta' >> $testroot/stdout.expected
1487 echo 'blob - /dev/null' >> $testroot/stdout.expected
1488 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1489 echo '--- /dev/null' >> $testroot/stdout.expected
1490 echo '+++ new' >> $testroot/stdout.expected
1491 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1492 echo '+new file' >> $testroot/stdout.expected
1493 (cd $testroot/wt && got diff -d -c $commit_id0 -c $commit_id1 \
1494 > $testroot/stdout)
1495 cmp -s $testroot/stdout.expected $testroot/stdout
1496 ret=$?
1497 if [ $ret -ne 0 ]; then
1498 diff -u $testroot/stdout.expected $testroot/stdout
1499 test_done "$testroot" "$ret"
1500 return 1
1503 cat <<EOF >$testroot/stdout.expected
1504 diffstat $commit_id0 $commit_id1
1505 M alpha | 1+ 1-
1507 1 file changed, 1 insertion(+), 1 deletion(-)
1509 EOF
1511 # same diffstat filtered by path "alpha"
1512 echo "diff $commit_id0 $commit_id1" >> $testroot/stdout.expected
1513 echo "commit - $commit_id0" >> $testroot/stdout.expected
1514 echo "commit + $commit_id1" >> $testroot/stdout.expected
1515 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1516 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1517 echo '--- alpha' >> $testroot/stdout.expected
1518 echo '+++ alpha' >> $testroot/stdout.expected
1519 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1520 echo '-alpha' >> $testroot/stdout.expected
1521 echo '+modified alpha' >> $testroot/stdout.expected
1522 (cd $testroot/repo && got diff -d -c $commit_id0 -c $commit_id1 alpha \
1523 > $testroot/stdout)
1524 cmp -s $testroot/stdout.expected $testroot/stdout
1525 ret=$?
1526 if [ $ret -ne 0 ]; then
1527 diff -u $testroot/stdout.expected $testroot/stdout
1528 test_done "$testroot" "$ret"
1529 return 1
1531 # same diffstat in work tree
1532 (cd $testroot/wt && got diff -d -c $commit_id0 -c $commit_id1 alpha \
1533 > $testroot/stdout)
1534 cmp -s $testroot/stdout.expected $testroot/stdout
1535 ret=$?
1536 if [ $ret -ne 0 ]; then
1537 diff -u $testroot/stdout.expected $testroot/stdout
1538 test_done "$testroot" "$ret"
1539 return 1
1542 cat <<EOF >$testroot/stdout.expected
1543 diffstat $commit_id0 $commit_id1
1544 D beta | 0+ 1-
1545 A new | 1+ 0-
1547 2 files changed, 1 insertion(+), 1 deletion(-)
1549 EOF
1551 # same diffstat filtered by paths "beta" and "new"
1552 echo "diff $commit_id0 $commit_id1" >> $testroot/stdout.expected
1553 echo "commit - $commit_id0" >> $testroot/stdout.expected
1554 echo "commit + $commit_id1" >> $testroot/stdout.expected
1555 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1556 echo 'blob + /dev/null' >> $testroot/stdout.expected
1557 echo '--- beta' >> $testroot/stdout.expected
1558 echo '+++ /dev/null' >> $testroot/stdout.expected
1559 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1560 echo '-beta' >> $testroot/stdout.expected
1561 echo 'blob - /dev/null' >> $testroot/stdout.expected
1562 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1563 echo '--- /dev/null' >> $testroot/stdout.expected
1564 echo '+++ new' >> $testroot/stdout.expected
1565 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1566 echo '+new file' >> $testroot/stdout.expected
1567 (cd $testroot/repo && got diff -d -c $commit_id0 -c $commit_id1 \
1568 beta new > $testroot/stdout)
1569 cmp -s $testroot/stdout.expected $testroot/stdout
1570 ret=$?
1571 if [ $ret -ne 0 ]; then
1572 diff -u $testroot/stdout.expected $testroot/stdout
1574 test_done "$testroot" "$ret"
1577 test_diff_worktree_diffstat() {
1578 local testroot=`test_init diff_worktree_diffstat`
1579 local head_rev=`git_show_head $testroot/repo`
1580 local alpha_blobid=`get_blob_id $testroot/repo "" alpha`
1582 got checkout $testroot/repo $testroot/wt > /dev/null
1583 ret=$?
1584 if [ $ret -ne 0 ]; then
1585 test_done "$testroot" "$ret"
1586 return 1
1589 echo "modified alpha" > $testroot/wt/alpha
1590 (cd $testroot/wt && got rm beta >/dev/null)
1591 echo "new file" > $testroot/wt/new
1592 (cd $testroot/wt && got add new >/dev/null)
1594 cat <<EOF >$testroot/stdout.expected
1595 diffstat $testroot/wt
1596 M alpha | 1+ 1-
1597 D beta | 0+ 1-
1598 A new | 1+ 0-
1600 3 files changed, 2 insertions(+), 2 deletions(-)
1602 EOF
1604 echo "diff $testroot/wt" >> $testroot/stdout.expected
1605 echo "commit - $head_rev" >> $testroot/stdout.expected
1606 echo "path + $testroot/wt" >> $testroot/stdout.expected
1607 echo -n 'blob - ' >> $testroot/stdout.expected
1608 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
1609 >> $testroot/stdout.expected
1610 echo 'file + alpha' >> $testroot/stdout.expected
1611 echo '--- alpha' >> $testroot/stdout.expected
1612 echo '+++ alpha' >> $testroot/stdout.expected
1613 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1614 echo '-alpha' >> $testroot/stdout.expected
1615 echo '+modified alpha' >> $testroot/stdout.expected
1616 echo -n 'blob - ' >> $testroot/stdout.expected
1617 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1618 >> $testroot/stdout.expected
1619 echo 'file + /dev/null' >> $testroot/stdout.expected
1620 echo '--- beta' >> $testroot/stdout.expected
1621 echo '+++ /dev/null' >> $testroot/stdout.expected
1622 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1623 echo '-beta' >> $testroot/stdout.expected
1624 echo 'blob - /dev/null' >> $testroot/stdout.expected
1625 echo 'file + new (mode 644)' >> $testroot/stdout.expected
1626 echo '--- /dev/null' >> $testroot/stdout.expected
1627 echo '+++ new' >> $testroot/stdout.expected
1628 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1629 echo '+new file' >> $testroot/stdout.expected
1631 (cd $testroot/wt && got diff -d > $testroot/stdout)
1632 cmp -s $testroot/stdout.expected $testroot/stdout
1633 ret=$?
1634 if [ $ret -ne 0 ]; then
1635 diff -u $testroot/stdout.expected $testroot/stdout
1636 test_done "$testroot" "$ret"
1637 return 1
1640 echo "modified zeta" > $testroot/wt/epsilon/zeta
1642 cat <<EOF >$testroot/stdout.expected
1643 diffstat $testroot/wt
1644 M alpha | 1+ 1-
1645 D beta | 0+ 1-
1646 M epsilon/zeta | 1+ 1-
1647 A new | 1+ 0-
1649 4 files changed, 3 insertions(+), 3 deletions(-)
1651 EOF
1653 # specify paths to diffstat
1654 echo "diff $testroot/wt" >> $testroot/stdout.expected
1655 echo "commit - $head_rev" >> $testroot/stdout.expected
1656 echo "path + $testroot/wt" >> $testroot/stdout.expected
1657 echo -n 'blob - ' >> $testroot/stdout.expected
1658 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
1659 >> $testroot/stdout.expected
1660 echo 'file + alpha' >> $testroot/stdout.expected
1661 echo '--- alpha' >> $testroot/stdout.expected
1662 echo '+++ alpha' >> $testroot/stdout.expected
1663 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1664 echo '-alpha' >> $testroot/stdout.expected
1665 echo '+modified alpha' >> $testroot/stdout.expected
1666 echo -n 'blob - ' >> $testroot/stdout.expected
1667 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1668 >> $testroot/stdout.expected
1669 echo 'file + /dev/null' >> $testroot/stdout.expected
1670 echo '--- beta' >> $testroot/stdout.expected
1671 echo '+++ /dev/null' >> $testroot/stdout.expected
1672 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1673 echo '-beta' >> $testroot/stdout.expected
1674 echo -n 'blob - ' >> $testroot/stdout.expected
1675 got tree -r $testroot/repo -i epsilon | grep 'zeta$' | cut -d' ' -f 1 \
1676 >> $testroot/stdout.expected
1677 echo 'file + epsilon/zeta' >> $testroot/stdout.expected
1678 echo '--- epsilon/zeta' >> $testroot/stdout.expected
1679 echo '+++ epsilon/zeta' >> $testroot/stdout.expected
1680 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1681 echo '-zeta' >> $testroot/stdout.expected
1682 echo '+modified zeta' >> $testroot/stdout.expected
1683 echo 'blob - /dev/null' >> $testroot/stdout.expected
1684 echo 'file + new (mode 644)' >> $testroot/stdout.expected
1685 echo '--- /dev/null' >> $testroot/stdout.expected
1686 echo '+++ new' >> $testroot/stdout.expected
1687 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1688 echo '+new file' >> $testroot/stdout.expected
1690 (cd $testroot/wt && got diff -d new alpha epsilon beta > $testroot/stdout)
1691 cmp -s $testroot/stdout.expected $testroot/stdout
1692 ret=$?
1693 if [ $ret -ne 0 ]; then
1694 diff -u $testroot/stdout.expected $testroot/stdout
1695 test_done "$testroot" "$ret"
1696 return 1
1699 # same diff irrespective of argument order
1700 (cd $testroot/wt && got diff -d alpha new epsilon beta \
1701 > $testroot/stdout 2> $testroot/stderr)
1702 ret=$?
1703 if [ $ret -ne 0 ]; then
1704 echo "diff failed unexpectedly" >&2
1705 test_done "$testroot" "1"
1706 return 1
1708 cmp -s $testroot/stdout.expected $testroot/stdout
1709 ret=$?
1710 if [ $ret -ne 0 ]; then
1711 diff -u $testroot/stdout.expected $testroot/stdout
1712 test_done "$testroot" "$ret"
1713 return 1
1716 # force paths with -P
1717 echo master > $testroot/wt/master
1718 (cd $testroot/wt && got add master > /dev/null)
1719 (cd $testroot/wt && got diff -d -P new master > $testroot/stdout)
1720 ret=$?
1721 if [ $ret -ne 0 ]; then
1722 echo "diff failed unexpectedly" >&2
1723 test_done "$testroot" "1"
1724 return 1
1727 cat <<EOF >$testroot/stdout.expected
1728 diffstat $testroot/wt
1729 A master | 1+ 0-
1730 A new | 1+ 0-
1732 2 files changed, 2 insertions(+), 0 deletions(-)
1734 EOF
1736 echo "diff $testroot/wt" >> $testroot/stdout.expected
1737 echo "commit - $head_rev" >> $testroot/stdout.expected
1738 echo "path + $testroot/wt" >> $testroot/stdout.expected
1739 echo 'blob - /dev/null' >> $testroot/stdout.expected
1740 echo 'file + master (mode 644)' >> $testroot/stdout.expected
1741 echo '--- /dev/null' >> $testroot/stdout.expected
1742 echo '+++ master' >> $testroot/stdout.expected
1743 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1744 echo '+master' >> $testroot/stdout.expected
1745 echo 'blob - /dev/null' >> $testroot/stdout.expected
1746 echo 'file + new (mode 644)' >> $testroot/stdout.expected
1747 echo '--- /dev/null' >> $testroot/stdout.expected
1748 echo '+++ new' >> $testroot/stdout.expected
1749 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1750 echo '+new file' >> $testroot/stdout.expected
1751 cmp -s $testroot/stdout.expected $testroot/stdout
1752 ret=$?
1753 if [ $ret -ne 0 ]; then
1754 diff -u $testroot/stdout.expected $testroot/stdout
1755 test_done "$testroot" "$ret"
1756 return 1
1759 # diff two blob ids
1760 (cd $testroot/wt && got commit -m 'edit' alpha >/dev/null)
1761 local alpha_new_blobid=`get_blob_id $testroot/repo "" alpha`
1762 (cd $testroot/wt && got diff -d $alpha_blobid $alpha_new_blobid) \
1763 > $testroot/stdout
1764 ret=$?
1765 if [ $ret -ne 0 ]; then
1766 echo "diff failed unexpectedly" >&2
1767 test_done "$testroot" "$ret"
1768 return 1
1771 short_alpha_id=$(printf '%.10s' $alpha_blobid)
1772 short_alpha_new_id=$(printf '%.10s' $alpha_new_blobid)
1773 cat <<EOF >$testroot/stdout.expected
1774 diffstat $alpha_blobid $alpha_new_blobid
1775 M $short_alpha_id -> $short_alpha_new_id | 1+ 1-
1777 1 file changed, 1 insertion(+), 1 deletion(-)
1779 blob - $alpha_blobid
1780 blob + $alpha_new_blobid
1781 --- $alpha_blobid
1782 +++ $alpha_new_blobid
1783 @@ -1 +1 @@
1784 -alpha
1785 +modified alpha
1786 EOF
1788 cmp -s $testroot/stdout.expected $testroot/stdout
1789 ret=$?
1790 if [ $ret -ne 0 ]; then
1791 diff -u $testroot/stdout.expected $testroot/stdout
1793 test_done "$testroot" "$ret"
1796 test_diff_file_to_dir() {
1797 local testroot=`test_init diff_file_to_dir`
1798 local commit_id0=`git_show_head $testroot/repo`
1799 local alpha_blobid=`get_blob_id $testroot/repo "" alpha`
1801 got checkout $testroot/repo $testroot/wt > /dev/null
1802 ret=$?
1803 if [ $ret -ne 0 ]; then
1804 test_done "$testroot" "$ret"
1805 return 1
1808 git_rm $testroot/repo alpha
1809 mkdir $testroot/repo/alpha
1810 echo eta > $testroot/repo/alpha/eta
1811 (cd $testroot/repo && git add alpha/eta)
1812 git_commit $testroot/repo -m "changed alpha into directory"
1813 local commit_id1=`git_show_head $testroot/repo`
1814 local alpha_eta_blobid=`get_blob_id $testroot/repo alpha eta`
1816 cat <<EOF >$testroot/stdout.expected
1817 diff $commit_id0 $commit_id1
1818 commit - $commit_id0
1819 commit + $commit_id1
1820 blob - $alpha_blobid (mode 644)
1821 blob + /dev/null
1822 --- alpha
1823 +++ /dev/null
1824 @@ -1 +0,0 @@
1825 -alpha
1826 blob - /dev/null
1827 blob + $alpha_eta_blobid (mode 644)
1828 --- /dev/null
1829 +++ alpha/eta
1830 @@ -0,0 +1 @@
1831 +eta
1832 EOF
1833 got diff -r $testroot/repo $commit_id0 $commit_id1 > $testroot/stdout
1834 ret=$?
1835 if [ $ret -ne 0 ]; then
1836 echo "diff failed unexpectedly" >&2
1837 test_done "$testroot" "1"
1838 return 1
1841 cmp -s $testroot/stdout.expected $testroot/stdout
1842 ret=$?
1843 if [ $ret -ne 0 ]; then
1844 diff -u $testroot/stdout.expected $testroot/stdout
1845 test_done "$testroot" "$ret"
1846 return 1
1849 local author_time=`git_show_author_time $testroot/repo`
1850 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1851 cat <<EOF >$testroot/stdout.expected
1852 -----------------------------------------------
1853 commit $commit_id1 (master)
1854 from: $GOT_AUTHOR
1855 date: $d
1857 changed alpha into directory
1859 D alpha
1860 A alpha/eta
1862 EOF
1864 got log -P -r $testroot/repo -l1 -c $commit_id1 > $testroot/stdout
1865 ret=$?
1866 if [ $ret -ne 0 ]; then
1867 echo "diff failed unexpectedly" >&2
1868 test_done "$testroot" "1"
1869 return 1
1872 cmp -s $testroot/stdout.expected $testroot/stdout
1873 ret=$?
1874 if [ $ret -ne 0 ]; then
1875 diff -u $testroot/stdout.expected $testroot/stdout
1877 test_done "$testroot" "$ret"
1880 test_diff_dir_to_file() {
1881 local testroot=`test_init diff_file_to_dir`
1882 local commit_id0=`git_show_head $testroot/repo`
1883 local epsilon_zeta_blobid=`get_blob_id $testroot/repo epsilon zeta`
1885 got checkout $testroot/repo $testroot/wt > /dev/null
1886 ret=$?
1887 if [ $ret -ne 0 ]; then
1888 test_done "$testroot" "$ret"
1889 return 1
1892 git_rmdir $testroot/repo epsilon
1893 echo epsilon > $testroot/repo/epsilon
1894 (cd $testroot/repo && git add epsilon)
1895 git_commit $testroot/repo -m "changed epsilon into file"
1896 local commit_id1=`git_show_head $testroot/repo`
1897 local epsilon_blobid=`get_blob_id $testroot/repo "" epsilon`
1899 cat <<EOF >$testroot/stdout.expected
1900 diff $commit_id0 $commit_id1
1901 commit - $commit_id0
1902 commit + $commit_id1
1903 blob - $epsilon_zeta_blobid (mode 644)
1904 blob + /dev/null
1905 --- epsilon/zeta
1906 +++ /dev/null
1907 @@ -1 +0,0 @@
1908 -zeta
1909 blob - /dev/null
1910 blob + $epsilon_blobid (mode 644)
1911 --- /dev/null
1912 +++ epsilon
1913 @@ -0,0 +1 @@
1914 +epsilon
1915 EOF
1916 got diff -r $testroot/repo $commit_id0 $commit_id1 > $testroot/stdout
1917 ret=$?
1918 if [ $ret -ne 0 ]; then
1919 echo "diff failed unexpectedly" >&2
1920 test_done "$testroot" "1"
1921 return 1
1924 cmp -s $testroot/stdout.expected $testroot/stdout
1925 ret=$?
1926 if [ $ret -ne 0 ]; then
1927 diff -u $testroot/stdout.expected $testroot/stdout
1928 test_done "$testroot" "$ret"
1929 return 1
1932 local author_time=`git_show_author_time $testroot/repo`
1933 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
1934 cat <<EOF >$testroot/stdout.expected
1935 -----------------------------------------------
1936 commit $commit_id1 (master)
1937 from: $GOT_AUTHOR
1938 date: $d
1940 changed epsilon into file
1942 D epsilon/zeta
1943 A epsilon
1945 EOF
1947 got log -P -r $testroot/repo -l1 -c $commit_id1 > $testroot/stdout
1948 ret=$?
1949 if [ $ret -ne 0 ]; then
1950 echo "diff failed unexpectedly" >&2
1951 test_done "$testroot" "1"
1952 return 1
1955 cmp -s $testroot/stdout.expected $testroot/stdout
1956 ret=$?
1957 if [ $ret -ne 0 ]; then
1958 diff -u $testroot/stdout.expected $testroot/stdout
1960 test_done "$testroot" "$ret"
1963 test_parseargs "$@"
1964 run_test test_diff_basic
1965 run_test test_diff_shows_conflict
1966 run_test test_diff_tag
1967 run_test test_diff_lightweight_tag
1968 run_test test_diff_ignore_whitespace
1969 run_test test_diff_submodule_of_same_repo
1970 run_test test_diff_symlinks_in_work_tree
1971 run_test test_diff_symlinks_in_repo
1972 run_test test_diff_binary_files
1973 run_test test_diff_commits
1974 run_test test_diff_ignored_file
1975 run_test test_diff_crlf
1976 run_test test_diff_worktree_newfile_xbit
1977 run_test test_diff_commit_diffstat
1978 run_test test_diff_worktree_diffstat
1979 run_test test_diff_file_to_dir
1980 run_test test_diff_dir_to_file