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 sed -i 's/2/22/' $testroot/repo/numbers
447 sed -i 's/8/33/' $testroot/repo/numbers
448 git_commit $testroot/repo -m "modified line 2"
449 local head_rev=`git_show_head $testroot/repo`
451 # modify lines 2 and 8 in conflicting ways
452 sed -i 's/2/77/' $testroot/wt/numbers
453 sed -i 's/8/88/' $testroot/wt/numbers
455 echo "C numbers" > $testroot/stdout.expected
456 echo -n "Updated to refs/heads/master: $head_rev" \
457 >> $testroot/stdout.expected
458 echo >> $testroot/stdout.expected
459 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
461 (cd $testroot/wt && got update > $testroot/stdout)
463 cmp -s $testroot/stdout.expected $testroot/stdout
464 ret=$?
465 if [ $ret -ne 0 ]; then
466 diff -u $testroot/stdout.expected $testroot/stdout
467 test_done "$testroot" "$ret"
468 return 1
469 fi
471 echo "diff $testroot/wt" > $testroot/stdout.expected
472 echo "commit - $head_rev" >> $testroot/stdout.expected
473 echo "path + $testroot/wt" >> $testroot/stdout.expected
474 echo -n 'blob - ' >> $testroot/stdout.expected
475 got tree -r $testroot/repo -i | grep 'numbers$' | cut -d' ' -f 1 \
476 >> $testroot/stdout.expected
477 echo 'file + numbers' >> $testroot/stdout.expected
478 echo '--- numbers' >> $testroot/stdout.expected
479 echo '+++ numbers' >> $testroot/stdout.expected
480 echo '@@ -1,8 +1,20 @@' >> $testroot/stdout.expected
481 echo ' 1' >> $testroot/stdout.expected
482 echo "+<<<<<<< merged change: commit $head_rev" \
483 >> $testroot/stdout.expected
484 echo ' 22' >> $testroot/stdout.expected
485 echo "+||||||| 3-way merge base: commit $base_commit" \
486 >> $testroot/stdout.expected
487 echo '+2' >> $testroot/stdout.expected
488 echo '+=======' >> $testroot/stdout.expected
489 echo '+77' >> $testroot/stdout.expected
490 echo '+>>>>>>>' >> $testroot/stdout.expected
491 echo ' 3' >> $testroot/stdout.expected
492 echo ' 4' >> $testroot/stdout.expected
493 echo ' 5' >> $testroot/stdout.expected
494 echo ' 6' >> $testroot/stdout.expected
495 echo ' 7' >> $testroot/stdout.expected
496 echo "+<<<<<<< merged change: commit $head_rev" \
497 >> $testroot/stdout.expected
498 echo ' 33' >> $testroot/stdout.expected
499 echo "+||||||| 3-way merge base: commit $base_commit" \
500 >> $testroot/stdout.expected
501 echo '+8' >> $testroot/stdout.expected
502 echo '+=======' >> $testroot/stdout.expected
503 echo '+88' >> $testroot/stdout.expected
504 echo '+>>>>>>>' >> $testroot/stdout.expected
506 (cd $testroot/wt && got diff > $testroot/stdout)
508 cmp -s $testroot/stdout.expected $testroot/stdout
509 ret=$?
510 if [ $ret -ne 0 ]; then
511 diff -u $testroot/stdout.expected $testroot/stdout
512 fi
513 test_done "$testroot" "$ret"
516 test_diff_tag() {
517 local testroot=`test_init diff_tag`
518 local commit_id0=`git_show_head $testroot/repo`
519 local tag1=1.0.0
520 local tag2=2.0.0
522 echo "modified alpha" > $testroot/repo/alpha
523 git_commit $testroot/repo -m "changed alpha"
524 local commit_id1=`git_show_head $testroot/repo`
526 (cd $testroot/repo && git tag -m "test" $tag1)
528 echo "new file" > $testroot/repo/new
529 (cd $testroot/repo && git add new)
530 git_commit $testroot/repo -m "new file"
531 local commit_id2=`git_show_head $testroot/repo`
533 (cd $testroot/repo && git tag -m "test" $tag2)
535 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
536 echo "commit - $commit_id0" >> $testroot/stdout.expected
537 echo "commit + $commit_id1" >> $testroot/stdout.expected
538 echo -n 'blob - ' >> $testroot/stdout.expected
539 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
540 cut -d' ' -f 1 >> $testroot/stdout.expected
541 echo -n 'blob + ' >> $testroot/stdout.expected
542 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
543 >> $testroot/stdout.expected
544 echo '--- alpha' >> $testroot/stdout.expected
545 echo '+++ alpha' >> $testroot/stdout.expected
546 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
547 echo '-alpha' >> $testroot/stdout.expected
548 echo '+modified alpha' >> $testroot/stdout.expected
550 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
551 cmp -s $testroot/stdout.expected $testroot/stdout
552 ret=$?
553 if [ $ret -ne 0 ]; then
554 diff -u $testroot/stdout.expected $testroot/stdout
555 test_done "$testroot" "$ret"
556 return 1
557 fi
559 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
560 echo "commit - $commit_id1" >> $testroot/stdout.expected
561 echo "commit + $commit_id2" >> $testroot/stdout.expected
562 echo "blob - /dev/null" >> $testroot/stdout.expected
563 echo -n 'blob + ' >> $testroot/stdout.expected
564 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
565 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
566 echo " (mode 644)" >> $testroot/stdout.expected
567 echo '--- /dev/null' >> $testroot/stdout.expected
568 echo '+++ new' >> $testroot/stdout.expected
569 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
570 echo '+new file' >> $testroot/stdout.expected
572 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
573 cmp -s $testroot/stdout.expected $testroot/stdout
574 ret=$?
575 if [ $ret -ne 0 ]; then
576 diff -u $testroot/stdout.expected $testroot/stdout
577 fi
578 test_done "$testroot" "$ret"
581 test_diff_lightweight_tag() {
582 local testroot=`test_init diff_tag`
583 local commit_id0=`git_show_head $testroot/repo`
584 local tag1=1.0.0
585 local tag2=2.0.0
587 echo "modified alpha" > $testroot/repo/alpha
588 git_commit $testroot/repo -m "changed alpha"
589 local commit_id1=`git_show_head $testroot/repo`
591 (cd $testroot/repo && git tag $tag1)
593 echo "new file" > $testroot/repo/new
594 (cd $testroot/repo && git add new)
595 git_commit $testroot/repo -m "new file"
596 local commit_id2=`git_show_head $testroot/repo`
598 (cd $testroot/repo && git tag $tag2)
600 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
601 echo "commit - $commit_id0" >> $testroot/stdout.expected
602 echo "commit + $commit_id1" >> $testroot/stdout.expected
603 echo -n 'blob - ' >> $testroot/stdout.expected
604 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
605 cut -d' ' -f 1 >> $testroot/stdout.expected
606 echo -n 'blob + ' >> $testroot/stdout.expected
607 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
608 >> $testroot/stdout.expected
609 echo '--- alpha' >> $testroot/stdout.expected
610 echo '+++ alpha' >> $testroot/stdout.expected
611 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
612 echo '-alpha' >> $testroot/stdout.expected
613 echo '+modified alpha' >> $testroot/stdout.expected
615 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
616 cmp -s $testroot/stdout.expected $testroot/stdout
617 ret=$?
618 if [ $ret -ne 0 ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
625 echo "commit - $commit_id1" >> $testroot/stdout.expected
626 echo "commit + $commit_id2" >> $testroot/stdout.expected
627 echo "blob - /dev/null" >> $testroot/stdout.expected
628 echo -n 'blob + ' >> $testroot/stdout.expected
629 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
630 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
631 echo " (mode 644)" >> $testroot/stdout.expected
632 echo '--- /dev/null' >> $testroot/stdout.expected
633 echo '+++ new' >> $testroot/stdout.expected
634 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
635 echo '+new file' >> $testroot/stdout.expected
637 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
638 cmp -s $testroot/stdout.expected $testroot/stdout
639 ret=$?
640 if [ $ret -ne 0 ]; then
641 diff -u $testroot/stdout.expected $testroot/stdout
642 fi
643 test_done "$testroot" "$ret"
646 test_diff_ignore_whitespace() {
647 local testroot=`test_init diff_ignore_whitespace`
648 local commit_id0=`git_show_head $testroot/repo`
650 got checkout $testroot/repo $testroot/wt > /dev/null
651 ret=$?
652 if [ $ret -ne 0 ]; then
653 test_done "$testroot" "$ret"
654 return 1
655 fi
657 echo "alpha " > $testroot/wt/alpha
659 (cd $testroot/wt && got diff -w > $testroot/stdout)
661 echo "diff $testroot/wt" > $testroot/stdout.expected
662 echo "commit - $commit_id0" >> $testroot/stdout.expected
663 echo "path + $testroot/wt" >> $testroot/stdout.expected
664 echo -n 'blob - ' >> $testroot/stdout.expected
665 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
666 cut -d' ' -f 1 >> $testroot/stdout.expected
667 echo 'file + alpha' >> $testroot/stdout.expected
669 cmp -s $testroot/stdout.expected $testroot/stdout
670 ret=$?
671 if [ $ret -ne 0 ]; then
672 diff -u $testroot/stdout.expected $testroot/stdout
673 fi
674 test_done "$testroot" "$ret"
677 test_diff_submodule_of_same_repo() {
678 local testroot=`test_init diff_submodule_of_same_repo`
680 (cd $testroot && git clone -q repo repo2 >/dev/null)
681 (cd $testroot/repo && git -c protocol.file.allow=always \
682 submodule -q add ../repo2)
683 (cd $testroot/repo && git commit -q -m 'adding submodule')
685 epsilon_id=$(got tree -r $testroot/repo -i | grep 'epsilon/$' | \
686 cut -d ' ' -f 1)
687 submodule_id=$(got tree -r $testroot/repo -i | grep 'repo2\$$' | \
688 cut -d ' ' -f 1)
690 # Attempt a (nonsensical) diff between a tree object and a submodule.
691 # Currently fails with "wrong type of object" error
692 got diff -r $testroot/repo $epsilon_id $submodule_id \
693 > $testroot/stdout 2> $testroot/stderr
694 ret=$?
695 if [ $ret -eq 0 ]; then
696 echo "diff command succeeded unexpectedly" >&2
697 test_done "$testroot" "1"
698 return 1
699 fi
700 echo "got: wrong type of object" > $testroot/stderr.expected
702 cmp -s $testroot/stderr.expected $testroot/stderr
703 ret=$?
704 if [ $ret -ne 0 ]; then
705 diff -u $testroot/stderr.expected $testroot/stderr
706 return 1
707 fi
708 test_done "$testroot" "$ret"
711 test_diff_symlinks_in_work_tree() {
712 local testroot=`test_init diff_symlinks_in_work_tree`
714 (cd $testroot/repo && ln -s alpha alpha.link)
715 (cd $testroot/repo && ln -s epsilon epsilon.link)
716 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
717 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
718 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
719 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
720 (cd $testroot/repo && git add .)
721 git_commit $testroot/repo -m "add symlinks"
722 local commit_id1=`git_show_head $testroot/repo`
724 got checkout $testroot/repo $testroot/wt > /dev/null
725 ret=$?
726 if [ $ret -ne 0 ]; then
727 test_done "$testroot" "$ret"
728 return 1
729 fi
731 (cd $testroot/wt && ln -sf beta alpha.link)
732 (cd $testroot/wt && ln -sfh gamma epsilon.link)
733 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
734 echo -n '.got/bar' > $testroot/wt/dotgotfoo.link
735 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
736 (cd $testroot/wt && ln -sf epsilon/zeta zeta.link)
737 (cd $testroot/wt && got add zeta.link > /dev/null)
738 (cd $testroot/wt && got diff > $testroot/stdout)
740 echo "diff $testroot/wt" > $testroot/stdout.expected
741 echo "commit - $commit_id1" >> $testroot/stdout.expected
742 echo "path + $testroot/wt" >> $testroot/stdout.expected
743 echo -n 'blob - ' >> $testroot/stdout.expected
744 got tree -r $testroot/repo -c $commit_id1 -i | \
745 grep 'alpha.link@ -> alpha$' | \
746 cut -d' ' -f 1 >> $testroot/stdout.expected
747 echo 'file + alpha.link' >> $testroot/stdout.expected
748 echo '--- alpha.link' >> $testroot/stdout.expected
749 echo '+++ alpha.link' >> $testroot/stdout.expected
750 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
751 echo '-alpha' >> $testroot/stdout.expected
752 echo '\ No newline at end of file' >> $testroot/stdout.expected
753 echo '+beta' >> $testroot/stdout.expected
754 echo '\ No newline at end of file' >> $testroot/stdout.expected
755 echo -n 'blob - ' >> $testroot/stdout.expected
756 got tree -r $testroot/repo -c $commit_id1 -i | \
757 grep 'dotgotfoo.link@ -> .got/foo$' | \
758 cut -d' ' -f 1 >> $testroot/stdout.expected
759 echo 'file + dotgotfoo.link' >> $testroot/stdout.expected
760 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
761 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
762 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
763 echo '-.got/foo' >> $testroot/stdout.expected
764 echo '\ No newline at end of file' >> $testroot/stdout.expected
765 echo '+.got/bar' >> $testroot/stdout.expected
766 echo '\ No newline at end of file' >> $testroot/stdout.expected
767 echo -n 'blob - ' >> $testroot/stdout.expected
768 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
769 grep 'beta.link@ -> ../beta$' | \
770 cut -d' ' -f 1 >> $testroot/stdout.expected
771 echo 'file + epsilon/beta.link' >> $testroot/stdout.expected
772 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
773 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
774 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
775 echo '-../beta' >> $testroot/stdout.expected
776 echo '\ No newline at end of file' >> $testroot/stdout.expected
777 echo '+../gamma/delta' >> $testroot/stdout.expected
778 echo '\ No newline at end of file' >> $testroot/stdout.expected
779 echo -n 'blob - ' >> $testroot/stdout.expected
780 got tree -r $testroot/repo -c $commit_id1 -i | \
781 grep 'epsilon.link@ -> epsilon$' | \
782 cut -d' ' -f 1 >> $testroot/stdout.expected
783 echo 'file + epsilon.link' >> $testroot/stdout.expected
784 echo '--- epsilon.link' >> $testroot/stdout.expected
785 echo '+++ epsilon.link' >> $testroot/stdout.expected
786 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
787 echo '-epsilon' >> $testroot/stdout.expected
788 echo '\ No newline at end of file' >> $testroot/stdout.expected
789 echo '+gamma' >> $testroot/stdout.expected
790 echo '\ No newline at end of file' >> $testroot/stdout.expected
791 echo -n 'blob - ' >> $testroot/stdout.expected
792 got tree -r $testroot/repo -c $commit_id1 -i | \
793 grep 'nonexistent.link@ -> nonexistent$' | \
794 cut -d' ' -f 1 >> $testroot/stdout.expected
795 echo 'file + /dev/null' >> $testroot/stdout.expected
796 echo '--- nonexistent.link' >> $testroot/stdout.expected
797 echo '+++ /dev/null' >> $testroot/stdout.expected
798 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
799 echo '-nonexistent' >> $testroot/stdout.expected
800 echo '\ No newline at end of file' >> $testroot/stdout.expected
801 echo 'blob - /dev/null' >> $testroot/stdout.expected
802 echo 'file + zeta.link (mode 120000)' >> $testroot/stdout.expected
803 echo '--- /dev/null' >> $testroot/stdout.expected
804 echo '+++ zeta.link' >> $testroot/stdout.expected
805 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
806 echo '+epsilon/zeta' >> $testroot/stdout.expected
807 echo '\ No newline at end of file' >> $testroot/stdout.expected
809 cmp -s $testroot/stdout.expected $testroot/stdout
810 ret=$?
811 if [ $ret -ne 0 ]; then
812 diff -u $testroot/stdout.expected $testroot/stdout
813 fi
814 test_done "$testroot" "$ret"
817 test_diff_symlinks_in_repo() {
818 local testroot=`test_init diff_symlinks_in_repo`
820 (cd $testroot/repo && ln -s alpha alpha.link)
821 (cd $testroot/repo && ln -s epsilon epsilon.link)
822 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
823 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
824 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
825 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
826 (cd $testroot/repo && git add .)
827 git_commit $testroot/repo -m "add symlinks"
828 local commit_id1=`git_show_head $testroot/repo`
830 (cd $testroot/repo && ln -sf beta alpha.link)
831 (cd $testroot/repo && ln -sfh gamma epsilon.link)
832 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
833 (cd $testroot/repo && ln -sf .got/bar $testroot/repo/dotgotfoo.link)
834 (cd $testroot/repo && git rm -q nonexistent.link)
835 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
836 (cd $testroot/repo && git add .)
837 git_commit $testroot/repo -m "change symlinks"
838 local commit_id2=`git_show_head $testroot/repo`
840 got diff -r $testroot/repo $commit_id1 $commit_id2 > $testroot/stdout
842 echo "diff $commit_id1 $commit_id2" > $testroot/stdout.expected
843 echo "commit - $commit_id1" >> $testroot/stdout.expected
844 echo "commit + $commit_id2" >> $testroot/stdout.expected
845 echo -n 'blob - ' >> $testroot/stdout.expected
846 got tree -r $testroot/repo -c $commit_id1 -i | \
847 grep 'alpha.link@ -> alpha$' | \
848 cut -d' ' -f 1 >> $testroot/stdout.expected
849 echo -n 'blob + ' >> $testroot/stdout.expected
850 got tree -r $testroot/repo -c $commit_id2 -i | \
851 grep 'alpha.link@ -> beta$' | \
852 cut -d' ' -f 1 >> $testroot/stdout.expected
853 echo '--- alpha.link' >> $testroot/stdout.expected
854 echo '+++ alpha.link' >> $testroot/stdout.expected
855 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
856 echo '-alpha' >> $testroot/stdout.expected
857 echo '\ No newline at end of file' >> $testroot/stdout.expected
858 echo '+beta' >> $testroot/stdout.expected
859 echo '\ No newline at end of file' >> $testroot/stdout.expected
860 echo -n 'blob - ' >> $testroot/stdout.expected
861 got tree -r $testroot/repo -c $commit_id1 -i | \
862 grep 'dotgotfoo.link@ -> .got/foo$' | \
863 cut -d' ' -f 1 >> $testroot/stdout.expected
864 echo -n 'blob + ' >> $testroot/stdout.expected
865 got tree -r $testroot/repo -c $commit_id2 -i | \
866 grep 'dotgotfoo.link@ -> .got/bar$' | \
867 cut -d' ' -f 1 >> $testroot/stdout.expected
868 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
869 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
870 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
871 echo '-.got/foo' >> $testroot/stdout.expected
872 echo '\ No newline at end of file' >> $testroot/stdout.expected
873 echo '+.got/bar' >> $testroot/stdout.expected
874 echo '\ No newline at end of file' >> $testroot/stdout.expected
875 echo -n 'blob - ' >> $testroot/stdout.expected
876 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
877 grep 'beta.link@ -> ../beta$' | \
878 cut -d' ' -f 1 >> $testroot/stdout.expected
879 echo -n 'blob + ' >> $testroot/stdout.expected
880 got tree -r $testroot/repo -c $commit_id2 -i epsilon | \
881 grep 'beta.link@ -> ../gamma/delta$' | \
882 cut -d' ' -f 1 >> $testroot/stdout.expected
883 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
884 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
885 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
886 echo '-../beta' >> $testroot/stdout.expected
887 echo '\ No newline at end of file' >> $testroot/stdout.expected
888 echo '+../gamma/delta' >> $testroot/stdout.expected
889 echo '\ No newline at end of file' >> $testroot/stdout.expected
890 echo -n 'blob - ' >> $testroot/stdout.expected
891 got tree -r $testroot/repo -c $commit_id1 -i | \
892 grep 'epsilon.link@ -> epsilon$' | \
893 cut -d' ' -f 1 >> $testroot/stdout.expected
894 echo -n 'blob + ' >> $testroot/stdout.expected
895 got tree -r $testroot/repo -c $commit_id2 -i | \
896 grep 'epsilon.link@ -> gamma$' | \
897 cut -d' ' -f 1 >> $testroot/stdout.expected
898 echo '--- epsilon.link' >> $testroot/stdout.expected
899 echo '+++ epsilon.link' >> $testroot/stdout.expected
900 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
901 echo '-epsilon' >> $testroot/stdout.expected
902 echo '\ No newline at end of file' >> $testroot/stdout.expected
903 echo '+gamma' >> $testroot/stdout.expected
904 echo '\ No newline at end of file' >> $testroot/stdout.expected
905 echo -n 'blob - ' >> $testroot/stdout.expected
906 got tree -r $testroot/repo -c $commit_id1 -i | \
907 grep 'nonexistent.link@ -> nonexistent$' | \
908 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
909 >> $testroot/stdout.expected
910 echo 'blob + /dev/null' >> $testroot/stdout.expected
911 echo '--- nonexistent.link' >> $testroot/stdout.expected
912 echo '+++ /dev/null' >> $testroot/stdout.expected
913 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
914 echo '-nonexistent' >> $testroot/stdout.expected
915 echo '\ No newline at end of file' >> $testroot/stdout.expected
916 echo 'blob - /dev/null' >> $testroot/stdout.expected
917 echo -n 'blob + ' >> $testroot/stdout.expected
918 got tree -r $testroot/repo -c $commit_id2 -i | \
919 grep 'zeta.link@ -> epsilon/zeta$' | \
920 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
921 >> $testroot/stdout.expected
922 echo '--- /dev/null' >> $testroot/stdout.expected
923 echo '+++ zeta.link' >> $testroot/stdout.expected
924 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
925 echo '+epsilon/zeta' >> $testroot/stdout.expected
926 echo '\ No newline at end of file' >> $testroot/stdout.expected
928 cmp -s $testroot/stdout.expected $testroot/stdout
929 ret=$?
930 if [ $ret -ne 0 ]; then
931 diff -u $testroot/stdout.expected $testroot/stdout
932 fi
933 test_done "$testroot" "$ret"
936 test_diff_binary_files() {
937 local testroot=`test_init diff_binary_files`
938 local head_rev=`git_show_head $testroot/repo`
940 got checkout $testroot/repo $testroot/wt > /dev/null
941 ret=$?
942 if [ $ret -ne 0 ]; then
943 test_done "$testroot" "$ret"
944 return 1
945 fi
947 printf '\377\377\0\0\377\377\0\0' > $testroot/wt/foo
948 (cd $testroot/wt && got add foo >/dev/null)
950 echo "diff $testroot/wt" > $testroot/stdout.expected
951 echo "commit - $head_rev" >> $testroot/stdout.expected
952 echo "path + $testroot/wt" >> $testroot/stdout.expected
953 echo 'blob - /dev/null' >> $testroot/stdout.expected
954 echo 'file + foo (mode 644)' >> $testroot/stdout.expected
955 echo "Binary files /dev/null and foo differ" \
956 >> $testroot/stdout.expected
958 (cd $testroot/wt && got diff > $testroot/stdout)
959 cmp -s $testroot/stdout.expected $testroot/stdout
960 ret=$?
961 if [ $ret -ne 0 ]; then
962 diff -a -u $testroot/stdout.expected $testroot/stdout
963 test_done "$testroot" "$ret"
964 return 1
965 fi
967 echo "diff $testroot/wt" > $testroot/stdout.expected
968 echo "commit - $head_rev" >> $testroot/stdout.expected
969 echo "path + $testroot/wt" >> $testroot/stdout.expected
970 echo 'blob - /dev/null' >> $testroot/stdout.expected
971 echo 'file + foo (mode 644)' >> $testroot/stdout.expected
972 echo '--- /dev/null' >> $testroot/stdout.expected
973 echo '+++ foo' >> $testroot/stdout.expected
974 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
975 printf '+\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
976 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
978 (cd $testroot/wt && got diff -a > $testroot/stdout)
979 cmp -s $testroot/stdout.expected $testroot/stdout
980 ret=$?
981 if [ $ret -ne 0 ]; then
982 diff -a -u $testroot/stdout.expected $testroot/stdout
983 test_done "$testroot" "$ret"
984 return 1
985 fi
987 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
988 local head_rev=`git_show_head $testroot/repo`
990 printf '\377\200\0\0\377\200\0\0' > $testroot/wt/foo
992 echo "diff $testroot/wt" > $testroot/stdout.expected
993 echo "commit - $head_rev" >> $testroot/stdout.expected
994 echo "path + $testroot/wt" >> $testroot/stdout.expected
995 echo -n 'blob - ' >> $testroot/stdout.expected
996 got tree -r $testroot/repo -i | grep 'foo$' | cut -d' ' -f 1 \
997 >> $testroot/stdout.expected
998 echo 'file + foo' >> $testroot/stdout.expected
999 echo '--- foo' >> $testroot/stdout.expected
1000 echo '+++ foo' >> $testroot/stdout.expected
1001 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1002 printf -- '-\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
1003 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
1004 printf '+\377\200\0\0\377\200\0\0\n' >> $testroot/stdout.expected
1005 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
1007 (cd $testroot/wt && got diff -a > $testroot/stdout)
1008 cmp -s $testroot/stdout.expected $testroot/stdout
1009 ret=$?
1010 if [ $ret -ne 0 ]; then
1011 diff -a -u $testroot/stdout.expected $testroot/stdout
1013 test_done "$testroot" "$ret"
1016 test_diff_commits() {
1017 local testroot=`test_init diff_commits`
1018 local commit_id0=`git_show_head $testroot/repo`
1019 local alpha_id0=`get_blob_id $testroot/repo "" alpha`
1020 local beta_id0=`get_blob_id $testroot/repo "" beta`
1022 got checkout $testroot/repo $testroot/wt > /dev/null
1023 ret=$?
1024 if [ $ret -ne 0 ]; then
1025 test_done "$testroot" "$ret"
1026 return 1
1029 echo "modified alpha" > $testroot/wt/alpha
1030 (cd $testroot/wt && got rm beta >/dev/null)
1031 echo "new file" > $testroot/wt/new
1032 (cd $testroot/wt && got add new >/dev/null)
1033 (cd $testroot/wt && got commit -m 'committing changes' >/dev/null)
1034 local commit_id1=`git_show_head $testroot/repo`
1036 alpha_id1=`get_blob_id $testroot/repo "" alpha`
1037 new_id1=`get_blob_id $testroot/repo "" new`
1039 echo "diff $commit_id0 refs/heads/master" > $testroot/stdout.expected
1040 echo "commit - $commit_id0" >> $testroot/stdout.expected
1041 echo "commit + $commit_id1" >> $testroot/stdout.expected
1042 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1043 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1044 echo '--- alpha' >> $testroot/stdout.expected
1045 echo '+++ alpha' >> $testroot/stdout.expected
1046 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1047 echo '-alpha' >> $testroot/stdout.expected
1048 echo '+modified alpha' >> $testroot/stdout.expected
1049 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1050 echo 'blob + /dev/null' >> $testroot/stdout.expected
1051 echo '--- beta' >> $testroot/stdout.expected
1052 echo '+++ /dev/null' >> $testroot/stdout.expected
1053 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1054 echo '-beta' >> $testroot/stdout.expected
1055 echo 'blob - /dev/null' >> $testroot/stdout.expected
1056 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1057 echo '--- /dev/null' >> $testroot/stdout.expected
1058 echo '+++ new' >> $testroot/stdout.expected
1059 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1060 echo '+new file' >> $testroot/stdout.expected
1062 (cd $testroot/wt && got diff -c master > $testroot/stdout)
1063 cmp -s $testroot/stdout.expected $testroot/stdout
1064 ret=$?
1065 if [ $ret -ne 0 ]; then
1066 diff -u $testroot/stdout.expected $testroot/stdout
1067 test_done "$testroot" "$ret"
1068 return 1
1071 # same diff with explicit parent commit ID
1072 (cd $testroot/wt && got diff -c $commit_id0 -c master \
1073 > $testroot/stdout)
1074 cmp -s $testroot/stdout.expected $testroot/stdout
1075 ret=$?
1076 if [ $ret -ne 0 ]; then
1077 diff -u $testroot/stdout.expected $testroot/stdout
1078 test_done "$testroot" "$ret"
1079 return 1
1082 # same diff with commit object IDs
1083 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1084 echo "commit - $commit_id0" >> $testroot/stdout.expected
1085 echo "commit + $commit_id1" >> $testroot/stdout.expected
1086 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1087 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1088 echo '--- alpha' >> $testroot/stdout.expected
1089 echo '+++ alpha' >> $testroot/stdout.expected
1090 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1091 echo '-alpha' >> $testroot/stdout.expected
1092 echo '+modified alpha' >> $testroot/stdout.expected
1093 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1094 echo 'blob + /dev/null' >> $testroot/stdout.expected
1095 echo '--- beta' >> $testroot/stdout.expected
1096 echo '+++ /dev/null' >> $testroot/stdout.expected
1097 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1098 echo '-beta' >> $testroot/stdout.expected
1099 echo 'blob - /dev/null' >> $testroot/stdout.expected
1100 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1101 echo '--- /dev/null' >> $testroot/stdout.expected
1102 echo '+++ new' >> $testroot/stdout.expected
1103 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1104 echo '+new file' >> $testroot/stdout.expected
1105 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 \
1106 > $testroot/stdout)
1107 cmp -s $testroot/stdout.expected $testroot/stdout
1108 ret=$?
1109 if [ $ret -ne 0 ]; then
1110 diff -u $testroot/stdout.expected $testroot/stdout
1111 test_done "$testroot" "$ret"
1112 return 1
1115 # same diff, filtered by paths
1116 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1117 echo "commit - $commit_id0" >> $testroot/stdout.expected
1118 echo "commit + $commit_id1" >> $testroot/stdout.expected
1119 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1120 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1121 echo '--- alpha' >> $testroot/stdout.expected
1122 echo '+++ alpha' >> $testroot/stdout.expected
1123 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1124 echo '-alpha' >> $testroot/stdout.expected
1125 echo '+modified alpha' >> $testroot/stdout.expected
1126 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 alpha \
1127 > $testroot/stdout)
1128 cmp -s $testroot/stdout.expected $testroot/stdout
1129 ret=$?
1130 if [ $ret -ne 0 ]; then
1131 diff -u $testroot/stdout.expected $testroot/stdout
1132 test_done "$testroot" "$ret"
1133 return 1
1135 # same in a work tree
1136 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 alpha \
1137 > $testroot/stdout)
1138 cmp -s $testroot/stdout.expected $testroot/stdout
1139 ret=$?
1140 if [ $ret -ne 0 ]; then
1141 diff -u $testroot/stdout.expected $testroot/stdout
1142 test_done "$testroot" "$ret"
1143 return 1
1146 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1147 echo "commit - $commit_id0" >> $testroot/stdout.expected
1148 echo "commit + $commit_id1" >> $testroot/stdout.expected
1149 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1150 echo 'blob + /dev/null' >> $testroot/stdout.expected
1151 echo '--- beta' >> $testroot/stdout.expected
1152 echo '+++ /dev/null' >> $testroot/stdout.expected
1153 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1154 echo '-beta' >> $testroot/stdout.expected
1155 echo 'blob - /dev/null' >> $testroot/stdout.expected
1156 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1157 echo '--- /dev/null' >> $testroot/stdout.expected
1158 echo '+++ new' >> $testroot/stdout.expected
1159 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1160 echo '+new file' >> $testroot/stdout.expected
1161 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 \
1162 beta new > $testroot/stdout)
1163 cmp -s $testroot/stdout.expected $testroot/stdout
1164 ret=$?
1165 if [ $ret -ne 0 ]; then
1166 diff -u $testroot/stdout.expected $testroot/stdout
1167 test_done "$testroot" "$ret"
1168 return 1
1171 # more than two -c options are not allowed
1172 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 -c foo \
1173 2> $testroot/stderr)
1174 ret=$?
1175 if [ $ret -eq 0 ]; then
1176 echo "diff succeeded unexpectedly" >&2
1177 test_done "$testroot" "1"
1178 return 1
1180 echo "got: too many -c options used" > $testroot/stderr.expected
1181 cmp -s $testroot/stderr.expected $testroot/stderr
1182 ret=$?
1183 if [ $ret -ne 0 ]; then
1184 diff -u $testroot/stderr.expected $testroot/stderr
1185 test_done "$testroot" "$ret"
1186 return 1
1189 # use of -c options implies a repository diff; use with -P is an error
1190 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -P foo \
1191 2> $testroot/stderr)
1192 ret=$?
1193 if [ $ret -eq 0 ]; then
1194 echo "diff succeeded unexpectedly" >&2
1195 test_done "$testroot" "1"
1196 return 1
1198 echo "got: -P option can only be used when diffing a work tree" \
1199 > $testroot/stderr.expected
1200 cmp -s $testroot/stderr.expected $testroot/stderr
1201 ret=$?
1202 if [ $ret -ne 0 ]; then
1203 diff -u $testroot/stderr.expected $testroot/stderr
1204 test_done "$testroot" "$ret"
1205 return 1
1208 # use of -c options implies a repository diff; use with -s is an error
1209 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -s foo \
1210 2> $testroot/stderr)
1211 ret=$?
1212 if [ $ret -eq 0 ]; then
1213 echo "diff succeeded unexpectedly" >&2
1214 test_done "$testroot" "1"
1215 return 1
1217 echo "got: -s option can only be used when diffing a work tree" \
1218 > $testroot/stderr.expected
1219 cmp -s $testroot/stderr.expected $testroot/stderr
1220 ret=$?
1221 if [ $ret -ne 0 ]; then
1222 diff -u $testroot/stderr.expected $testroot/stderr
1223 test_done "$testroot" "$ret"
1224 return 1
1227 # three arguments imply use of path filtering (repository case)
1228 (cd $testroot/repo && got diff $commit_id0 $commit_id1 foo \
1229 2> $testroot/stderr)
1230 ret=$?
1231 if [ $ret -eq 0 ]; then
1232 echo "diff succeeded unexpectedly" >&2
1233 test_done "$testroot" "1"
1234 return 1
1236 echo "got: specified paths cannot be resolved: no got work tree found" \
1237 > $testroot/stderr.expected
1238 cmp -s $testroot/stderr.expected $testroot/stderr
1239 ret=$?
1240 if [ $ret -ne 0 ]; then
1241 diff -u $testroot/stderr.expected $testroot/stderr
1242 test_done "$testroot" "$ret"
1243 return 1
1246 # three arguments imply use of path filtering (work tree case)
1247 (cd $testroot/wt && got diff $commit_id0 master foo \
1248 2> $testroot/stderr)
1249 ret=$?
1250 if [ $ret -eq 0 ]; then
1251 echo "diff succeeded unexpectedly" >&2
1252 test_done "$testroot" "1"
1253 return 1
1255 echo "got: $commit_id0: No such file or directory" \
1256 > $testroot/stderr.expected
1257 cmp -s $testroot/stderr.expected $testroot/stderr
1258 ret=$?
1259 if [ $ret -ne 0 ]; then
1260 diff -u $testroot/stderr.expected $testroot/stderr
1262 test_done "$testroot" "$ret"
1265 test_diff_ignored_file() {
1266 local testroot=`test_init diff_ignored_file`
1268 got checkout $testroot/repo $testroot/wt > /dev/null
1269 ret=$?
1270 if [ $ret -ne 0 ]; then
1271 test_done "$testroot" "$ret"
1272 return 1
1275 echo 1 > $testroot/wt/number
1276 (cd $testroot/wt && got add number >/dev/null)
1277 (cd $testroot/wt && got commit -m 'add number' >/dev/null)
1279 echo "**/number" > $testroot/wt/.gitignore
1281 echo 2 > $testroot/wt/number
1282 (cd $testroot/wt && got diff number | sed '1,/^@@/d' > $testroot/stdout)
1284 echo "-1" > $testroot/stdout.expected
1285 echo "+2" >> $testroot/stdout.expected
1287 cmp -s $testroot/stdout.expected $testroot/stdout
1288 ret=$?
1289 if [ $ret -ne 0 ]; then
1290 diff -u $testroot/stdout.expected $testroot/stdout
1292 test_done "$testroot" "$ret"
1295 test_diff_crlf() {
1296 local testroot=`test_init diff_crlf`
1298 got checkout $testroot/repo $testroot/wt > /dev/null
1299 ret=$?
1300 if [ $ret -ne 0 ]; then
1301 test_done "$testroot" $ret
1302 return 1
1305 printf 'test\r\n' > $testroot/wt/crlf
1306 (cd $testroot/wt && got add crlf && got commit -m +crlf) >/dev/null
1307 ret=$?
1308 if [ $ret -ne 0 ]; then
1309 test_done "$testroot" $ret
1310 return 1
1313 printf 'test 2\r\n' > $testroot/wt/crlf
1314 (cd $testroot/wt && got diff | sed -n '/^---/,$p' > $testroot/stdout)
1315 cat <<EOF > $testroot/stdout.expected
1316 --- crlf
1317 +++ crlf
1318 @@ -1 +1 @@
1319 -test
1320 +test 2
1321 EOF
1323 cmp -s $testroot/stdout.expected $testroot/stdout
1324 ret=$?
1325 if [ $ret -ne 0 ]; then
1326 diff -u $testroot/stdout.expected $testroot/stdout
1328 test_done "$testroot" $ret
1331 test_diff_worktree_newfile_xbit() {
1332 local testroot=`test_init diff_worktree_newfile_xbit`
1334 got checkout $testroot/repo $testroot/wt > /dev/null
1335 ret=$?
1336 if [ $ret -ne 0 ]; then
1337 test_done "$testroot" $ret
1338 return 1
1341 echo xfile > $testroot/wt/xfile
1342 chmod +x $testroot/wt/xfile
1343 (cd $testroot/wt && got add xfile) > /dev/null
1344 ret=$?
1345 if [ $ret -ne 0 ]; then
1346 test_done "$testroot" $ret
1347 return 1
1349 (cd $testroot/wt && got diff) > $testroot/stdout
1350 ret=$?
1351 if [ $ret -ne 0 ]; then
1352 test_done "$testroot" $ret
1353 return 1
1356 local commit_id=`git_show_head $testroot/repo`
1357 cat <<EOF > $testroot/stdout.expected
1358 diff $testroot/wt
1359 commit - $commit_id
1360 path + $testroot/wt
1361 blob - /dev/null
1362 file + xfile (mode 755)
1363 --- /dev/null
1364 +++ xfile
1365 @@ -0,0 +1 @@
1366 +xfile
1367 EOF
1369 cmp -s $testroot/stdout.expected $testroot/stdout
1370 ret=$?
1371 if [ $ret -ne 0 ]; then
1372 echo "failed to record mode 755"
1373 diff -u $testroot/stdout.expected $testroot/stdout
1375 test_done "$testroot" $ret
1378 test_diff_commit_diffstat() {
1379 local testroot=`test_init diff_commit_diffstat`
1380 local commit_id0=`git_show_head $testroot/repo`
1381 local alpha_id0=`get_blob_id $testroot/repo "" alpha`
1382 local beta_id0=`get_blob_id $testroot/repo "" beta`
1384 got checkout $testroot/repo $testroot/wt > /dev/null
1385 ret=$?
1386 if [ $ret -ne 0 ]; then
1387 test_done "$testroot" "$ret"
1388 return 1
1391 echo "modified alpha" > $testroot/wt/alpha
1392 (cd $testroot/wt && got rm beta >/dev/null)
1393 echo "new file" > $testroot/wt/new
1394 (cd $testroot/wt && got add new >/dev/null)
1395 (cd $testroot/wt && got commit -m 'committing changes' >/dev/null)
1396 local commit_id1=`git_show_head $testroot/repo`
1398 local alpha_id1=`get_blob_id $testroot/repo "" alpha`
1399 local new_id1=`get_blob_id $testroot/repo "" new`
1401 cat <<EOF >$testroot/stdout.expected
1402 diffstat $commit_id0 refs/heads/master
1403 M alpha | 1+ 1-
1404 D beta | 0+ 1-
1405 A new | 1+ 0-
1407 3 files changed, 2 insertions(+), 2 deletions(-)
1409 EOF
1411 echo "diff $commit_id0 refs/heads/master" >> $testroot/stdout.expected
1412 echo "commit - $commit_id0" >> $testroot/stdout.expected
1413 echo "commit + $commit_id1" >> $testroot/stdout.expected
1414 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1415 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1416 echo '--- alpha' >> $testroot/stdout.expected
1417 echo '+++ alpha' >> $testroot/stdout.expected
1418 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1419 echo '-alpha' >> $testroot/stdout.expected
1420 echo '+modified alpha' >> $testroot/stdout.expected
1421 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1422 echo 'blob + /dev/null' >> $testroot/stdout.expected
1423 echo '--- beta' >> $testroot/stdout.expected
1424 echo '+++ /dev/null' >> $testroot/stdout.expected
1425 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1426 echo '-beta' >> $testroot/stdout.expected
1427 echo 'blob - /dev/null' >> $testroot/stdout.expected
1428 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1429 echo '--- /dev/null' >> $testroot/stdout.expected
1430 echo '+++ new' >> $testroot/stdout.expected
1431 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1432 echo '+new file' >> $testroot/stdout.expected
1434 (cd $testroot/wt && got diff -d -c master > $testroot/stdout)
1435 cmp -s $testroot/stdout.expected $testroot/stdout
1436 ret=$?
1437 if [ $ret -ne 0 ]; then
1438 diff -u $testroot/stdout.expected $testroot/stdout
1439 test_done "$testroot" "$ret"
1440 return 1
1443 # same diffstat with explicit parent commit ID
1444 (cd $testroot/wt && got diff -d -c $commit_id0 -c master \
1445 > $testroot/stdout)
1446 cmp -s $testroot/stdout.expected $testroot/stdout
1447 ret=$?
1448 if [ $ret -ne 0 ]; then
1449 diff -u $testroot/stdout.expected $testroot/stdout
1450 test_done "$testroot" "$ret"
1451 return 1
1454 cat <<EOF >$testroot/stdout.expected
1455 diffstat $commit_id0 $commit_id1
1456 M alpha | 1+ 1-
1457 D beta | 0+ 1-
1458 A new | 1+ 0-
1460 3 files changed, 2 insertions(+), 2 deletions(-)
1462 EOF
1464 # same diffstat with commit object IDs
1465 echo "diff $commit_id0 $commit_id1" >> $testroot/stdout.expected
1466 echo "commit - $commit_id0" >> $testroot/stdout.expected
1467 echo "commit + $commit_id1" >> $testroot/stdout.expected
1468 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1469 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1470 echo '--- alpha' >> $testroot/stdout.expected
1471 echo '+++ alpha' >> $testroot/stdout.expected
1472 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1473 echo '-alpha' >> $testroot/stdout.expected
1474 echo '+modified alpha' >> $testroot/stdout.expected
1475 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1476 echo 'blob + /dev/null' >> $testroot/stdout.expected
1477 echo '--- beta' >> $testroot/stdout.expected
1478 echo '+++ /dev/null' >> $testroot/stdout.expected
1479 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1480 echo '-beta' >> $testroot/stdout.expected
1481 echo 'blob - /dev/null' >> $testroot/stdout.expected
1482 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1483 echo '--- /dev/null' >> $testroot/stdout.expected
1484 echo '+++ new' >> $testroot/stdout.expected
1485 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1486 echo '+new file' >> $testroot/stdout.expected
1487 (cd $testroot/wt && got diff -d -c $commit_id0 -c $commit_id1 \
1488 > $testroot/stdout)
1489 cmp -s $testroot/stdout.expected $testroot/stdout
1490 ret=$?
1491 if [ $ret -ne 0 ]; then
1492 diff -u $testroot/stdout.expected $testroot/stdout
1493 test_done "$testroot" "$ret"
1494 return 1
1497 cat <<EOF >$testroot/stdout.expected
1498 diffstat $commit_id0 $commit_id1
1499 M alpha | 1+ 1-
1501 1 file changed, 1 insertion(+), 1 deletion(-)
1503 EOF
1505 # same diffstat filtered by path "alpha"
1506 echo "diff $commit_id0 $commit_id1" >> $testroot/stdout.expected
1507 echo "commit - $commit_id0" >> $testroot/stdout.expected
1508 echo "commit + $commit_id1" >> $testroot/stdout.expected
1509 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1510 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1511 echo '--- alpha' >> $testroot/stdout.expected
1512 echo '+++ alpha' >> $testroot/stdout.expected
1513 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1514 echo '-alpha' >> $testroot/stdout.expected
1515 echo '+modified alpha' >> $testroot/stdout.expected
1516 (cd $testroot/repo && got diff -d -c $commit_id0 -c $commit_id1 alpha \
1517 > $testroot/stdout)
1518 cmp -s $testroot/stdout.expected $testroot/stdout
1519 ret=$?
1520 if [ $ret -ne 0 ]; then
1521 diff -u $testroot/stdout.expected $testroot/stdout
1522 test_done "$testroot" "$ret"
1523 return 1
1525 # same diffstat in work tree
1526 (cd $testroot/wt && got diff -d -c $commit_id0 -c $commit_id1 alpha \
1527 > $testroot/stdout)
1528 cmp -s $testroot/stdout.expected $testroot/stdout
1529 ret=$?
1530 if [ $ret -ne 0 ]; then
1531 diff -u $testroot/stdout.expected $testroot/stdout
1532 test_done "$testroot" "$ret"
1533 return 1
1536 cat <<EOF >$testroot/stdout.expected
1537 diffstat $commit_id0 $commit_id1
1538 D beta | 0+ 1-
1539 A new | 1+ 0-
1541 2 files changed, 1 insertion(+), 1 deletion(-)
1543 EOF
1545 # same diffstat filtered by paths "beta" and "new"
1546 echo "diff $commit_id0 $commit_id1" >> $testroot/stdout.expected
1547 echo "commit - $commit_id0" >> $testroot/stdout.expected
1548 echo "commit + $commit_id1" >> $testroot/stdout.expected
1549 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1550 echo 'blob + /dev/null' >> $testroot/stdout.expected
1551 echo '--- beta' >> $testroot/stdout.expected
1552 echo '+++ /dev/null' >> $testroot/stdout.expected
1553 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1554 echo '-beta' >> $testroot/stdout.expected
1555 echo 'blob - /dev/null' >> $testroot/stdout.expected
1556 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1557 echo '--- /dev/null' >> $testroot/stdout.expected
1558 echo '+++ new' >> $testroot/stdout.expected
1559 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1560 echo '+new file' >> $testroot/stdout.expected
1561 (cd $testroot/repo && got diff -d -c $commit_id0 -c $commit_id1 \
1562 beta new > $testroot/stdout)
1563 cmp -s $testroot/stdout.expected $testroot/stdout
1564 ret=$?
1565 if [ $ret -ne 0 ]; then
1566 diff -u $testroot/stdout.expected $testroot/stdout
1568 test_done "$testroot" "$ret"
1571 test_diff_worktree_diffstat() {
1572 local testroot=`test_init diff_worktree_diffstat`
1573 local head_rev=`git_show_head $testroot/repo`
1574 local alpha_blobid=`get_blob_id $testroot/repo "" alpha`
1576 got checkout $testroot/repo $testroot/wt > /dev/null
1577 ret=$?
1578 if [ $ret -ne 0 ]; then
1579 test_done "$testroot" "$ret"
1580 return 1
1583 echo "modified alpha" > $testroot/wt/alpha
1584 (cd $testroot/wt && got rm beta >/dev/null)
1585 echo "new file" > $testroot/wt/new
1586 (cd $testroot/wt && got add new >/dev/null)
1588 cat <<EOF >$testroot/stdout.expected
1589 diffstat $testroot/wt
1590 M alpha | 1+ 1-
1591 D beta | 0+ 1-
1592 A new | 1+ 0-
1594 3 files changed, 2 insertions(+), 2 deletions(-)
1596 EOF
1598 echo "diff $testroot/wt" >> $testroot/stdout.expected
1599 echo "commit - $head_rev" >> $testroot/stdout.expected
1600 echo "path + $testroot/wt" >> $testroot/stdout.expected
1601 echo -n 'blob - ' >> $testroot/stdout.expected
1602 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
1603 >> $testroot/stdout.expected
1604 echo 'file + alpha' >> $testroot/stdout.expected
1605 echo '--- alpha' >> $testroot/stdout.expected
1606 echo '+++ alpha' >> $testroot/stdout.expected
1607 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1608 echo '-alpha' >> $testroot/stdout.expected
1609 echo '+modified alpha' >> $testroot/stdout.expected
1610 echo -n 'blob - ' >> $testroot/stdout.expected
1611 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1612 >> $testroot/stdout.expected
1613 echo 'file + /dev/null' >> $testroot/stdout.expected
1614 echo '--- beta' >> $testroot/stdout.expected
1615 echo '+++ /dev/null' >> $testroot/stdout.expected
1616 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1617 echo '-beta' >> $testroot/stdout.expected
1618 echo 'blob - /dev/null' >> $testroot/stdout.expected
1619 echo 'file + new (mode 644)' >> $testroot/stdout.expected
1620 echo '--- /dev/null' >> $testroot/stdout.expected
1621 echo '+++ new' >> $testroot/stdout.expected
1622 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1623 echo '+new file' >> $testroot/stdout.expected
1625 (cd $testroot/wt && got diff -d > $testroot/stdout)
1626 cmp -s $testroot/stdout.expected $testroot/stdout
1627 ret=$?
1628 if [ $ret -ne 0 ]; then
1629 diff -u $testroot/stdout.expected $testroot/stdout
1630 test_done "$testroot" "$ret"
1631 return 1
1634 echo "modified zeta" > $testroot/wt/epsilon/zeta
1636 cat <<EOF >$testroot/stdout.expected
1637 diffstat $testroot/wt
1638 M alpha | 1+ 1-
1639 D beta | 0+ 1-
1640 M epsilon/zeta | 1+ 1-
1641 A new | 1+ 0-
1643 4 files changed, 3 insertions(+), 3 deletions(-)
1645 EOF
1647 # specify paths to diffstat
1648 echo "diff $testroot/wt" >> $testroot/stdout.expected
1649 echo "commit - $head_rev" >> $testroot/stdout.expected
1650 echo "path + $testroot/wt" >> $testroot/stdout.expected
1651 echo -n 'blob - ' >> $testroot/stdout.expected
1652 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
1653 >> $testroot/stdout.expected
1654 echo 'file + alpha' >> $testroot/stdout.expected
1655 echo '--- alpha' >> $testroot/stdout.expected
1656 echo '+++ alpha' >> $testroot/stdout.expected
1657 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1658 echo '-alpha' >> $testroot/stdout.expected
1659 echo '+modified alpha' >> $testroot/stdout.expected
1660 echo -n 'blob - ' >> $testroot/stdout.expected
1661 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1662 >> $testroot/stdout.expected
1663 echo 'file + /dev/null' >> $testroot/stdout.expected
1664 echo '--- beta' >> $testroot/stdout.expected
1665 echo '+++ /dev/null' >> $testroot/stdout.expected
1666 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1667 echo '-beta' >> $testroot/stdout.expected
1668 echo -n 'blob - ' >> $testroot/stdout.expected
1669 got tree -r $testroot/repo -i epsilon | grep 'zeta$' | cut -d' ' -f 1 \
1670 >> $testroot/stdout.expected
1671 echo 'file + epsilon/zeta' >> $testroot/stdout.expected
1672 echo '--- epsilon/zeta' >> $testroot/stdout.expected
1673 echo '+++ epsilon/zeta' >> $testroot/stdout.expected
1674 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1675 echo '-zeta' >> $testroot/stdout.expected
1676 echo '+modified zeta' >> $testroot/stdout.expected
1677 echo 'blob - /dev/null' >> $testroot/stdout.expected
1678 echo 'file + new (mode 644)' >> $testroot/stdout.expected
1679 echo '--- /dev/null' >> $testroot/stdout.expected
1680 echo '+++ new' >> $testroot/stdout.expected
1681 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1682 echo '+new file' >> $testroot/stdout.expected
1684 (cd $testroot/wt && got diff -d new alpha epsilon beta > $testroot/stdout)
1685 cmp -s $testroot/stdout.expected $testroot/stdout
1686 ret=$?
1687 if [ $ret -ne 0 ]; then
1688 diff -u $testroot/stdout.expected $testroot/stdout
1689 test_done "$testroot" "$ret"
1690 return 1
1693 # same diff irrespective of argument order
1694 (cd $testroot/wt && got diff -d alpha new epsilon beta \
1695 > $testroot/stdout 2> $testroot/stderr)
1696 ret=$?
1697 if [ $ret -ne 0 ]; then
1698 echo "diff failed unexpectedly" >&2
1699 test_done "$testroot" "1"
1700 return 1
1702 cmp -s $testroot/stdout.expected $testroot/stdout
1703 ret=$?
1704 if [ $ret -ne 0 ]; then
1705 diff -u $testroot/stdout.expected $testroot/stdout
1706 test_done "$testroot" "$ret"
1707 return 1
1710 # force paths with -P
1711 echo master > $testroot/wt/master
1712 (cd $testroot/wt && got add master > /dev/null)
1713 (cd $testroot/wt && got diff -d -P new master > $testroot/stdout)
1714 ret=$?
1715 if [ $ret -ne 0 ]; then
1716 echo "diff failed unexpectedly" >&2
1717 test_done "$testroot" "1"
1718 return 1
1721 cat <<EOF >$testroot/stdout.expected
1722 diffstat $testroot/wt
1723 A master | 1+ 0-
1724 A new | 1+ 0-
1726 2 files changed, 2 insertions(+), 0 deletions(-)
1728 EOF
1730 echo "diff $testroot/wt" >> $testroot/stdout.expected
1731 echo "commit - $head_rev" >> $testroot/stdout.expected
1732 echo "path + $testroot/wt" >> $testroot/stdout.expected
1733 echo 'blob - /dev/null' >> $testroot/stdout.expected
1734 echo 'file + master (mode 644)' >> $testroot/stdout.expected
1735 echo '--- /dev/null' >> $testroot/stdout.expected
1736 echo '+++ master' >> $testroot/stdout.expected
1737 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1738 echo '+master' >> $testroot/stdout.expected
1739 echo 'blob - /dev/null' >> $testroot/stdout.expected
1740 echo 'file + new (mode 644)' >> $testroot/stdout.expected
1741 echo '--- /dev/null' >> $testroot/stdout.expected
1742 echo '+++ new' >> $testroot/stdout.expected
1743 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1744 echo '+new file' >> $testroot/stdout.expected
1745 cmp -s $testroot/stdout.expected $testroot/stdout
1746 ret=$?
1747 if [ $ret -ne 0 ]; then
1748 diff -u $testroot/stdout.expected $testroot/stdout
1749 test_done "$testroot" "$ret"
1750 return 1
1753 # diff two blob ids
1754 (cd $testroot/wt && got commit -m 'edit' alpha >/dev/null)
1755 local alpha_new_blobid=`get_blob_id $testroot/repo "" alpha`
1756 (cd $testroot/wt && got diff -d $alpha_blobid $alpha_new_blobid) \
1757 > $testroot/stdout
1758 ret=$?
1759 if [ $ret -ne 0 ]; then
1760 echo "diff failed unexpectedly" >&2
1761 test_done "$testroot" "$ret"
1762 return 1
1765 short_alpha_id=$(printf '%.10s' $alpha_blobid)
1766 short_alpha_new_id=$(printf '%.10s' $alpha_new_blobid)
1767 cat <<EOF >$testroot/stdout.expected
1768 diffstat $alpha_blobid $alpha_new_blobid
1769 M $short_alpha_id -> $short_alpha_new_id | 1+ 1-
1771 1 file changed, 1 insertion(+), 1 deletion(-)
1773 blob - $alpha_blobid
1774 blob + $alpha_new_blobid
1775 --- $alpha_blobid
1776 +++ $alpha_new_blobid
1777 @@ -1 +1 @@
1778 -alpha
1779 +modified alpha
1780 EOF
1782 cmp -s $testroot/stdout.expected $testroot/stdout
1783 ret=$?
1784 if [ $ret -ne 0 ]; then
1785 diff -u $testroot/stdout.expected $testroot/stdout
1787 test_done "$testroot" "$ret"
1790 test_parseargs "$@"
1791 run_test test_diff_basic
1792 run_test test_diff_shows_conflict
1793 run_test test_diff_tag
1794 run_test test_diff_lightweight_tag
1795 run_test test_diff_ignore_whitespace
1796 run_test test_diff_submodule_of_same_repo
1797 run_test test_diff_symlinks_in_work_tree
1798 run_test test_diff_symlinks_in_repo
1799 run_test test_diff_binary_files
1800 run_test test_diff_commits
1801 run_test test_diff_ignored_file
1802 run_test test_diff_crlf
1803 run_test test_diff_worktree_newfile_xbit
1804 run_test test_diff_commit_diffstat
1805 run_test test_diff_worktree_diffstat