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 'one\r\ntwo\r\nthree\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 '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
1322 --- crlf$
1323 +++ crlf$
1324 @@ -1,3 +1,3 @@$
1325 one\r$
1326 -two\r$
1327 +twain\r$
1328 three\r$
1329 EOF
1331 cmp -s $testroot/stdout.expected $testroot/stdout
1332 ret=$?
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
1343 ret=$?
1344 if [ $ret -ne 0 ]; then
1345 test_done "$testroot" $ret
1346 return 1
1349 echo xfile > $testroot/wt/xfile
1350 chmod +x $testroot/wt/xfile
1351 (cd $testroot/wt && got add xfile) > /dev/null
1352 ret=$?
1353 if [ $ret -ne 0 ]; then
1354 test_done "$testroot" $ret
1355 return 1
1357 (cd $testroot/wt && got diff) > $testroot/stdout
1358 ret=$?
1359 if [ $ret -ne 0 ]; then
1360 test_done "$testroot" $ret
1361 return 1
1364 local commit_id=`git_show_head $testroot/repo`
1365 cat <<EOF > $testroot/stdout.expected
1366 diff $testroot/wt
1367 commit - $commit_id
1368 path + $testroot/wt
1369 blob - /dev/null
1370 file + xfile (mode 755)
1371 --- /dev/null
1372 +++ xfile
1373 @@ -0,0 +1 @@
1374 +xfile
1375 EOF
1377 cmp -s $testroot/stdout.expected $testroot/stdout
1378 ret=$?
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
1393 ret=$?
1394 if [ $ret -ne 0 ]; then
1395 test_done "$testroot" "$ret"
1396 return 1
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
1411 M alpha | 1+ 1-
1412 D beta | 0+ 1-
1413 A new | 1+ 0-
1415 3 files changed, 2 insertions(+), 2 deletions(-)
1417 EOF
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
1444 ret=$?
1445 if [ $ret -ne 0 ]; then
1446 diff -u $testroot/stdout.expected $testroot/stdout
1447 test_done "$testroot" "$ret"
1448 return 1
1451 # same diffstat with explicit parent commit ID
1452 (cd $testroot/wt && got diff -d -c $commit_id0 -c master \
1453 > $testroot/stdout)
1454 cmp -s $testroot/stdout.expected $testroot/stdout
1455 ret=$?
1456 if [ $ret -ne 0 ]; then
1457 diff -u $testroot/stdout.expected $testroot/stdout
1458 test_done "$testroot" "$ret"
1459 return 1
1462 cat <<EOF >$testroot/stdout.expected
1463 diffstat $commit_id0 $commit_id1
1464 M alpha | 1+ 1-
1465 D beta | 0+ 1-
1466 A new | 1+ 0-
1468 3 files changed, 2 insertions(+), 2 deletions(-)
1470 EOF
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 \
1496 > $testroot/stdout)
1497 cmp -s $testroot/stdout.expected $testroot/stdout
1498 ret=$?
1499 if [ $ret -ne 0 ]; then
1500 diff -u $testroot/stdout.expected $testroot/stdout
1501 test_done "$testroot" "$ret"
1502 return 1
1505 cat <<EOF >$testroot/stdout.expected
1506 diffstat $commit_id0 $commit_id1
1507 M alpha | 1+ 1-
1509 1 file changed, 1 insertion(+), 1 deletion(-)
1511 EOF
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 \
1525 > $testroot/stdout)
1526 cmp -s $testroot/stdout.expected $testroot/stdout
1527 ret=$?
1528 if [ $ret -ne 0 ]; then
1529 diff -u $testroot/stdout.expected $testroot/stdout
1530 test_done "$testroot" "$ret"
1531 return 1
1533 # same diffstat in work tree
1534 (cd $testroot/wt && got diff -d -c $commit_id0 -c $commit_id1 alpha \
1535 > $testroot/stdout)
1536 cmp -s $testroot/stdout.expected $testroot/stdout
1537 ret=$?
1538 if [ $ret -ne 0 ]; then
1539 diff -u $testroot/stdout.expected $testroot/stdout
1540 test_done "$testroot" "$ret"
1541 return 1
1544 cat <<EOF >$testroot/stdout.expected
1545 diffstat $commit_id0 $commit_id1
1546 D beta | 0+ 1-
1547 A new | 1+ 0-
1549 2 files changed, 1 insertion(+), 1 deletion(-)
1551 EOF
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
1572 ret=$?
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
1585 ret=$?
1586 if [ $ret -ne 0 ]; then
1587 test_done "$testroot" "$ret"
1588 return 1
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
1598 M alpha | 1+ 1-
1599 D beta | 0+ 1-
1600 A new | 1+ 0-
1602 3 files changed, 2 insertions(+), 2 deletions(-)
1604 EOF
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
1635 ret=$?
1636 if [ $ret -ne 0 ]; then
1637 diff -u $testroot/stdout.expected $testroot/stdout
1638 test_done "$testroot" "$ret"
1639 return 1
1642 echo "modified zeta" > $testroot/wt/epsilon/zeta
1644 cat <<EOF >$testroot/stdout.expected
1645 diffstat $testroot/wt
1646 M alpha | 1+ 1-
1647 D beta | 0+ 1-
1648 M epsilon/zeta | 1+ 1-
1649 A new | 1+ 0-
1651 4 files changed, 3 insertions(+), 3 deletions(-)
1653 EOF
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
1694 ret=$?
1695 if [ $ret -ne 0 ]; then
1696 diff -u $testroot/stdout.expected $testroot/stdout
1697 test_done "$testroot" "$ret"
1698 return 1
1701 # same diff irrespective of argument order
1702 (cd $testroot/wt && got diff -d alpha new epsilon beta \
1703 > $testroot/stdout 2> $testroot/stderr)
1704 ret=$?
1705 if [ $ret -ne 0 ]; then
1706 echo "diff failed unexpectedly" >&2
1707 test_done "$testroot" "1"
1708 return 1
1710 cmp -s $testroot/stdout.expected $testroot/stdout
1711 ret=$?
1712 if [ $ret -ne 0 ]; then
1713 diff -u $testroot/stdout.expected $testroot/stdout
1714 test_done "$testroot" "$ret"
1715 return 1
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)
1722 ret=$?
1723 if [ $ret -ne 0 ]; then
1724 echo "diff failed unexpectedly" >&2
1725 test_done "$testroot" "1"
1726 return 1
1729 cat <<EOF >$testroot/stdout.expected
1730 diffstat $testroot/wt
1731 A master | 1+ 0-
1732 A new | 1+ 0-
1734 2 files changed, 2 insertions(+), 0 deletions(-)
1736 EOF
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
1754 ret=$?
1755 if [ $ret -ne 0 ]; then
1756 diff -u $testroot/stdout.expected $testroot/stdout
1757 test_done "$testroot" "$ret"
1758 return 1
1761 # diff two blob ids
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) \
1765 > $testroot/stdout
1766 ret=$?
1767 if [ $ret -ne 0 ]; then
1768 echo "diff failed unexpectedly" >&2
1769 test_done "$testroot" "$ret"
1770 return 1
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
1783 --- $alpha_blobid
1784 +++ $alpha_new_blobid
1785 @@ -1 +1 @@
1786 -alpha
1787 +modified alpha
1788 EOF
1790 cmp -s $testroot/stdout.expected $testroot/stdout
1791 ret=$?
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
1804 ret=$?
1805 if [ $ret -ne 0 ]; then
1806 test_done "$testroot" "$ret"
1807 return 1
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)
1823 blob + /dev/null
1824 --- alpha
1825 +++ /dev/null
1826 @@ -1 +0,0 @@
1827 -alpha
1828 blob - /dev/null
1829 blob + $alpha_eta_blobid (mode 644)
1830 --- /dev/null
1831 +++ alpha/eta
1832 @@ -0,0 +1 @@
1833 +eta
1834 EOF
1835 got diff -r $testroot/repo $commit_id0 $commit_id1 > $testroot/stdout
1836 ret=$?
1837 if [ $ret -ne 0 ]; then
1838 echo "diff failed unexpectedly" >&2
1839 test_done "$testroot" "1"
1840 return 1
1843 cmp -s $testroot/stdout.expected $testroot/stdout
1844 ret=$?
1845 if [ $ret -ne 0 ]; then
1846 diff -u $testroot/stdout.expected $testroot/stdout
1847 test_done "$testroot" "$ret"
1848 return 1
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)
1856 from: $GOT_AUTHOR
1857 date: $d
1859 changed alpha into directory
1861 D alpha
1862 A alpha/eta
1864 EOF
1866 got log -P -r $testroot/repo -l1 -c $commit_id1 > $testroot/stdout
1867 ret=$?
1868 if [ $ret -ne 0 ]; then
1869 echo "diff failed unexpectedly" >&2
1870 test_done "$testroot" "1"
1871 return 1
1874 cmp -s $testroot/stdout.expected $testroot/stdout
1875 ret=$?
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
1888 ret=$?
1889 if [ $ret -ne 0 ]; then
1890 test_done "$testroot" "$ret"
1891 return 1
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)
1906 blob + /dev/null
1907 --- epsilon/zeta
1908 +++ /dev/null
1909 @@ -1 +0,0 @@
1910 -zeta
1911 blob - /dev/null
1912 blob + $epsilon_blobid (mode 644)
1913 --- /dev/null
1914 +++ epsilon
1915 @@ -0,0 +1 @@
1916 +epsilon
1917 EOF
1918 got diff -r $testroot/repo $commit_id0 $commit_id1 > $testroot/stdout
1919 ret=$?
1920 if [ $ret -ne 0 ]; then
1921 echo "diff failed unexpectedly" >&2
1922 test_done "$testroot" "1"
1923 return 1
1926 cmp -s $testroot/stdout.expected $testroot/stdout
1927 ret=$?
1928 if [ $ret -ne 0 ]; then
1929 diff -u $testroot/stdout.expected $testroot/stdout
1930 test_done "$testroot" "$ret"
1931 return 1
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)
1939 from: $GOT_AUTHOR
1940 date: $d
1942 changed epsilon into file
1944 D epsilon/zeta
1945 A epsilon
1947 EOF
1949 got log -P -r $testroot/repo -l1 -c $commit_id1 > $testroot/stdout
1950 ret=$?
1951 if [ $ret -ne 0 ]; then
1952 echo "diff failed unexpectedly" >&2
1953 test_done "$testroot" "1"
1954 return 1
1957 cmp -s $testroot/stdout.expected $testroot/stdout
1958 ret=$?
1959 if [ $ret -ne 0 ]; then
1960 diff -u $testroot/stdout.expected $testroot/stdout
1962 test_done "$testroot" "$ret"
1965 test_parseargs "$@"
1966 run_test test_diff_basic
1967 run_test test_diff_shows_conflict
1968 run_test test_diff_tag
1969 run_test test_diff_lightweight_tag
1970 run_test test_diff_ignore_whitespace
1971 run_test test_diff_submodule_of_same_repo
1972 run_test test_diff_symlinks_in_work_tree
1973 run_test test_diff_symlinks_in_repo
1974 run_test test_diff_binary_files
1975 run_test test_diff_commits
1976 run_test test_diff_ignored_file
1977 run_test test_diff_crlf
1978 run_test test_diff_worktree_newfile_xbit
1979 run_test test_diff_commit_diffstat
1980 run_test test_diff_worktree_diffstat
1981 run_test test_diff_file_to_dir
1982 run_test test_diff_dir_to_file