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`
23 got checkout $testroot/repo $testroot/wt > /dev/null
24 ret=$?
25 if [ $ret -ne 0 ]; then
26 test_done "$testroot" "$ret"
27 return 1
28 fi
30 echo "modified alpha" > $testroot/wt/alpha
31 (cd $testroot/wt && got rm beta >/dev/null)
32 echo "new file" > $testroot/wt/new
33 (cd $testroot/wt && got add new >/dev/null)
35 echo "diff $testroot/wt" > $testroot/stdout.expected
36 echo "commit - $head_rev" >> $testroot/stdout.expected
37 echo "path + $testroot/wt" >> $testroot/stdout.expected
38 echo -n 'blob - ' >> $testroot/stdout.expected
39 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
40 >> $testroot/stdout.expected
41 echo 'file + alpha' >> $testroot/stdout.expected
42 echo '--- alpha' >> $testroot/stdout.expected
43 echo '+++ alpha' >> $testroot/stdout.expected
44 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
45 echo '-alpha' >> $testroot/stdout.expected
46 echo '+modified alpha' >> $testroot/stdout.expected
47 echo -n 'blob - ' >> $testroot/stdout.expected
48 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
49 >> $testroot/stdout.expected
50 echo 'file + /dev/null' >> $testroot/stdout.expected
51 echo '--- beta' >> $testroot/stdout.expected
52 echo '+++ /dev/null' >> $testroot/stdout.expected
53 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
54 echo '-beta' >> $testroot/stdout.expected
55 echo 'blob - /dev/null' >> $testroot/stdout.expected
56 echo 'file + new' >> $testroot/stdout.expected
57 echo '--- /dev/null' >> $testroot/stdout.expected
58 echo '+++ new' >> $testroot/stdout.expected
59 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
60 echo '+new file' >> $testroot/stdout.expected
62 (cd $testroot/wt && got diff > $testroot/stdout)
63 cmp -s $testroot/stdout.expected $testroot/stdout
64 ret=$?
65 if [ $ret -ne 0 ]; then
66 diff -u $testroot/stdout.expected $testroot/stdout
67 test_done "$testroot" "$ret"
68 return 1
69 fi
71 # 'got diff' in a repository without any arguments is an error
72 (cd $testroot/repo && got diff 2> $testroot/stderr)
73 echo "got: no got work tree found" > $testroot/stderr.expected
74 cmp -s $testroot/stderr.expected $testroot/stderr
75 ret=$?
76 if [ $ret -ne 0 ]; then
77 diff -u $testroot/stderr.expected $testroot/stderr
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 # 'got diff' in a repository with two arguments requires that
83 # both named objects exist
84 (cd $testroot/repo && got diff $head_rev foo 2> $testroot/stderr)
85 echo "got: foo: object not found" > $testroot/stderr.expected
86 cmp -s $testroot/stderr.expected $testroot/stderr
87 ret=$?
88 if [ $ret -ne 0 ]; then
89 diff -u $testroot/stderr.expected $testroot/stderr
90 test_done "$testroot" "$ret"
91 return 1
92 fi
94 # diff non-existent path
95 (cd $testroot/wt && got diff nonexistent > $testroot/stdout \
96 2> $testroot/stderr)
98 echo -n > $testroot/stdout.expected
99 cmp -s $testroot/stdout.expected $testroot/stdout
100 ret=$?
101 if [ $ret -ne 0 ]; then
102 diff -u $testroot/stdout.expected $testroot/stdout
103 test_done "$testroot" "$ret"
104 return 1
105 fi
107 echo "got: nonexistent: No such file or directory" \
108 > $testroot/stderr.expected
109 cmp -s $testroot/stderr.expected $testroot/stderr
110 ret=$?
111 if [ $ret -ne 0 ]; then
112 diff -u $testroot/stderr.expected $testroot/stderr
113 test_done "$testroot" "$ret"
114 return 1
115 fi
117 echo "modified zeta" > $testroot/wt/epsilon/zeta
119 # diff several paths in a work tree
120 echo "diff $testroot/wt" > $testroot/stdout.expected
121 echo "commit - $head_rev" >> $testroot/stdout.expected
122 echo "path + $testroot/wt" >> $testroot/stdout.expected
123 echo -n 'blob - ' >> $testroot/stdout.expected
124 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
125 >> $testroot/stdout.expected
126 echo 'file + alpha' >> $testroot/stdout.expected
127 echo '--- alpha' >> $testroot/stdout.expected
128 echo '+++ alpha' >> $testroot/stdout.expected
129 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
130 echo '-alpha' >> $testroot/stdout.expected
131 echo '+modified alpha' >> $testroot/stdout.expected
132 echo -n 'blob - ' >> $testroot/stdout.expected
133 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
134 >> $testroot/stdout.expected
135 echo 'file + /dev/null' >> $testroot/stdout.expected
136 echo '--- beta' >> $testroot/stdout.expected
137 echo '+++ /dev/null' >> $testroot/stdout.expected
138 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
139 echo '-beta' >> $testroot/stdout.expected
140 echo -n 'blob - ' >> $testroot/stdout.expected
141 got tree -r $testroot/repo -i epsilon | grep 'zeta$' | cut -d' ' -f 1 \
142 >> $testroot/stdout.expected
143 echo 'file + epsilon/zeta' >> $testroot/stdout.expected
144 echo '--- epsilon/zeta' >> $testroot/stdout.expected
145 echo '+++ epsilon/zeta' >> $testroot/stdout.expected
146 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
147 echo '-zeta' >> $testroot/stdout.expected
148 echo '+modified zeta' >> $testroot/stdout.expected
149 echo 'blob - /dev/null' >> $testroot/stdout.expected
150 echo 'file + new' >> $testroot/stdout.expected
151 echo '--- /dev/null' >> $testroot/stdout.expected
152 echo '+++ new' >> $testroot/stdout.expected
153 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
154 echo '+new file' >> $testroot/stdout.expected
156 (cd $testroot/wt && got diff new alpha epsilon beta > $testroot/stdout)
157 cmp -s $testroot/stdout.expected $testroot/stdout
158 ret=$?
159 if [ $ret -ne 0 ]; then
160 diff -u $testroot/stdout.expected $testroot/stdout
161 test_done "$testroot" "$ret"
162 return 1
163 fi
165 # different order of arguments results in same output order
166 (cd $testroot/wt && got diff alpha new epsilon beta \
167 > $testroot/stdout 2> $testroot/stderr)
168 ret=$?
169 if [ $ret -ne 0 ]; then
170 echo "diff failed unexpectedly" >&2
171 test_done "$testroot" "1"
172 return 1
173 fi
174 cmp -s $testroot/stdout.expected $testroot/stdout
175 ret=$?
176 if [ $ret -ne 0 ]; then
177 diff -u $testroot/stdout.expected $testroot/stdout
178 test_done "$testroot" "$ret"
179 return 1
180 fi
182 # a branch 'new' should not collide with path 'new' if more
183 # than two arguments are passed
184 got br -r $testroot/repo -c master new > /dev/null
185 (cd $testroot/wt && got diff new alpha epsilon beta \
186 > $testroot/stdout 2> $testroot/stderr)
187 ret=$?
188 if [ $ret -ne 0 ]; then
189 echo "diff failed unexpectedly" >&2
190 test_done "$testroot" "1"
191 return 1
192 fi
193 cmp -s $testroot/stdout.expected $testroot/stdout
194 ret=$?
195 if [ $ret -ne 0 ]; then
196 diff -u $testroot/stdout.expected $testroot/stdout
197 test_done "$testroot" "$ret"
198 return 1
199 fi
201 # Two arguments are interpreted as objects if a colliding path exists
202 echo master > $testroot/wt/master
203 (cd $testroot/wt && got add master > /dev/null)
204 (cd $testroot/wt && got diff master new > $testroot/stdout)
205 ret=$?
206 if [ $ret -ne 0 ]; then
207 echo "diff failed unexpectedly" >&2
208 test_done "$testroot" "1"
209 return 1
210 fi
211 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
212 echo "commit - $head_rev" >> $testroot/stdout.expected
213 echo "commit + $head_rev" >> $testroot/stdout.expected
214 # diff between the branches is empty
215 cmp -s $testroot/stdout.expected $testroot/stdout
216 ret=$?
217 if [ $ret -ne 0 ]; then
218 diff -u $testroot/stdout.expected $testroot/stdout
219 test_done "$testroot" "$ret"
220 return 1
221 fi
222 # same without a work tree
223 (cd $testroot/repo && got diff master new > $testroot/stdout)
224 ret=$?
225 if [ $ret -ne 0 ]; then
226 echo "diff failed unexpectedly" >&2
227 test_done "$testroot" "1"
228 return 1
229 fi
230 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
231 echo "commit - $head_rev" >> $testroot/stdout.expected
232 echo "commit + $head_rev" >> $testroot/stdout.expected
233 cmp -s $testroot/stdout.expected $testroot/stdout
234 ret=$?
235 if [ $ret -ne 0 ]; then
236 diff -u $testroot/stdout.expected $testroot/stdout
237 test_done "$testroot" "$ret"
238 return 1
239 fi
240 # same with -r argument
241 got diff -r $testroot/repo master new > $testroot/stdout
242 ret=$?
243 if [ $ret -ne 0 ]; then
244 echo "diff failed unexpectedly" >&2
245 test_done "$testroot" "1"
246 return 1
247 fi
248 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
249 echo "commit - $head_rev" >> $testroot/stdout.expected
250 echo "commit + $head_rev" >> $testroot/stdout.expected
251 cmp -s $testroot/stdout.expected $testroot/stdout
252 ret=$?
253 if [ $ret -ne 0 ]; then
254 diff -u $testroot/stdout.expected $testroot/stdout
255 test_done "$testroot" "$ret"
256 return 1
257 fi
259 # -P can be used to force use of paths
260 (cd $testroot/wt && got diff -P new master > $testroot/stdout)
261 ret=$?
262 if [ $ret -ne 0 ]; then
263 echo "diff failed unexpectedly" >&2
264 test_done "$testroot" "1"
265 return 1
266 fi
267 echo "diff $testroot/wt" > $testroot/stdout.expected
268 echo "commit - $head_rev" >> $testroot/stdout.expected
269 echo "path + $testroot/wt" >> $testroot/stdout.expected
270 echo 'blob - /dev/null' >> $testroot/stdout.expected
271 echo 'file + master' >> $testroot/stdout.expected
272 echo '--- /dev/null' >> $testroot/stdout.expected
273 echo '+++ master' >> $testroot/stdout.expected
274 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
275 echo '+master' >> $testroot/stdout.expected
276 echo 'blob - /dev/null' >> $testroot/stdout.expected
277 echo 'file + new' >> $testroot/stdout.expected
278 echo '--- /dev/null' >> $testroot/stdout.expected
279 echo '+++ new' >> $testroot/stdout.expected
280 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
281 echo '+new file' >> $testroot/stdout.expected
282 cmp -s $testroot/stdout.expected $testroot/stdout
283 ret=$?
284 if [ $ret -ne 0 ]; then
285 diff -u $testroot/stdout.expected $testroot/stdout
286 test_done "$testroot" "$ret"
287 return 1
288 fi
290 # -P can only be used in a work tree
291 got diff -r $testroot/repo -P new master 2> $testroot/stderr
292 ret=$?
293 if [ $ret -eq 0 ]; then
294 echo "diff succeeded unexpectedly" >&2
295 test_done "$testroot" "1"
296 return 1
297 fi
298 echo "got: -P option can only be used when diffing a work tree" \
299 > $testroot/stderr.expected
300 cmp -s $testroot/stderr.expected $testroot/stderr
301 ret=$?
302 if [ $ret -ne 0 ]; then
303 diff -u $testroot/stderr.expected $testroot/stderr
304 test_done "$testroot" "$ret"
305 return 1
306 fi
308 # a single argument which can be resolved to a path is not ambiguous
309 echo "diff $testroot/wt" > $testroot/stdout.expected
310 echo "commit - $head_rev" >> $testroot/stdout.expected
311 echo "path + $testroot/wt" >> $testroot/stdout.expected
312 echo 'blob - /dev/null' >> $testroot/stdout.expected
313 echo 'file + new' >> $testroot/stdout.expected
314 echo '--- /dev/null' >> $testroot/stdout.expected
315 echo '+++ new' >> $testroot/stdout.expected
316 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
317 echo '+new file' >> $testroot/stdout.expected
318 (cd $testroot/wt && got diff new > $testroot/stdout)
319 ret=$?
320 if [ $ret -ne 0 ]; then
321 echo "diff failed unexpectedly" >&2
322 test_done "$testroot" "1"
323 return 1
324 fi
325 cmp -s $testroot/stdout.expected $testroot/stdout
326 ret=$?
327 if [ $ret -ne 0 ]; then
328 diff -u $testroot/stdout.expected $testroot/stdout
329 test_done "$testroot" "$ret"
330 return 1
331 fi
333 # diff with just one object ID argument results in
334 # interpretation of argument as a path
335 (cd $testroot/wt && got diff $head_rev 2> $testroot/stderr)
336 ret=$?
337 if [ $ret -eq 0 ]; then
338 echo "diff succeeded unexpectedly" >&2
339 test_done "$testroot" "1"
340 return 1
341 fi
342 echo "got: $head_rev: No such file or directory" \
343 > $testroot/stderr.expected
344 cmp -s $testroot/stderr.expected $testroot/stderr
345 ret=$?
346 if [ $ret -ne 0 ]; then
347 diff -u $testroot/stderr.expected $testroot/stderr
348 test_done "$testroot" "$ret"
349 return 1
350 fi
352 # diff with more than two object arguments results in
353 # interpretation of arguments as paths
354 (cd $testroot/wt && got diff new $head_rev master \
355 > $testroot/stout 2> $testroot/stderr)
356 ret=$?
357 if [ $ret -eq 0 ]; then
358 echo "diff succeeded unexpectedly" >&2
359 test_done "$testroot" "1"
360 return 1
361 fi
363 echo "diff $testroot/wt" > $testroot/stdout.expected
364 echo "commit - $head_rev" >> $testroot/stdout.expected
365 echo "path + $testroot/wt" >> $testroot/stdout.expected
366 echo 'blob - /dev/null' >> $testroot/stdout.expected
367 echo 'file + new' >> $testroot/stdout.expected
368 echo '--- /dev/null' >> $testroot/stdout.expected
369 echo '+++ new' >> $testroot/stdout.expected
370 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
371 echo '+new file' >> $testroot/stdout.expected
372 cmp -s $testroot/stdout.expected $testroot/stdout
373 ret=$?
374 if [ $ret -ne 0 ]; then
375 diff -u $testroot/stdout.expected $testroot/stdout
376 test_done "$testroot" "$ret"
377 return 1
378 fi
380 echo "got: $head_rev: No such file or directory" \
381 > $testroot/stderr.expected
382 cmp -s $testroot/stderr.expected $testroot/stderr
383 ret=$?
384 if [ $ret -ne 0 ]; then
385 diff -u $testroot/stderr.expected $testroot/stderr
386 return 1
387 fi
388 test_done "$testroot" "$ret"
391 test_diff_shows_conflict() {
392 local testroot=`test_init diff_shows_conflict 1`
394 echo "1" > $testroot/repo/numbers
395 echo "2" >> $testroot/repo/numbers
396 echo "3" >> $testroot/repo/numbers
397 echo "4" >> $testroot/repo/numbers
398 echo "5" >> $testroot/repo/numbers
399 echo "6" >> $testroot/repo/numbers
400 echo "7" >> $testroot/repo/numbers
401 echo "8" >> $testroot/repo/numbers
402 (cd $testroot/repo && git add numbers)
403 git_commit $testroot/repo -m "added numbers file"
404 local base_commit=`git_show_head $testroot/repo`
406 got checkout $testroot/repo $testroot/wt > /dev/null
407 ret=$?
408 if [ $ret -ne 0 ]; then
409 test_done "$testroot" "$ret"
410 return 1
411 fi
413 sed -i 's/2/22/' $testroot/repo/numbers
414 sed -i 's/8/33/' $testroot/repo/numbers
415 git_commit $testroot/repo -m "modified line 2"
416 local head_rev=`git_show_head $testroot/repo`
418 # modify lines 2 and 8 in conflicting ways
419 sed -i 's/2/77/' $testroot/wt/numbers
420 sed -i 's/8/88/' $testroot/wt/numbers
422 echo "C numbers" > $testroot/stdout.expected
423 echo -n "Updated to refs/heads/master: $head_rev" \
424 >> $testroot/stdout.expected
425 echo >> $testroot/stdout.expected
426 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
428 (cd $testroot/wt && got update > $testroot/stdout)
430 cmp -s $testroot/stdout.expected $testroot/stdout
431 ret=$?
432 if [ $ret -ne 0 ]; then
433 diff -u $testroot/stdout.expected $testroot/stdout
434 test_done "$testroot" "$ret"
435 return 1
436 fi
438 echo "diff $testroot/wt" > $testroot/stdout.expected
439 echo "commit - $head_rev" >> $testroot/stdout.expected
440 echo "path + $testroot/wt" >> $testroot/stdout.expected
441 echo -n 'blob - ' >> $testroot/stdout.expected
442 got tree -r $testroot/repo -i | grep 'numbers$' | cut -d' ' -f 1 \
443 >> $testroot/stdout.expected
444 echo 'file + numbers' >> $testroot/stdout.expected
445 echo '--- numbers' >> $testroot/stdout.expected
446 echo '+++ numbers' >> $testroot/stdout.expected
447 echo '@@ -1,8 +1,20 @@' >> $testroot/stdout.expected
448 echo ' 1' >> $testroot/stdout.expected
449 echo "+<<<<<<< merged change: commit $head_rev" \
450 >> $testroot/stdout.expected
451 echo ' 22' >> $testroot/stdout.expected
452 echo "+||||||| 3-way merge base: commit $base_commit" \
453 >> $testroot/stdout.expected
454 echo '+2' >> $testroot/stdout.expected
455 echo '+=======' >> $testroot/stdout.expected
456 echo '+77' >> $testroot/stdout.expected
457 echo '+>>>>>>>' >> $testroot/stdout.expected
458 echo ' 3' >> $testroot/stdout.expected
459 echo ' 4' >> $testroot/stdout.expected
460 echo ' 5' >> $testroot/stdout.expected
461 echo ' 6' >> $testroot/stdout.expected
462 echo ' 7' >> $testroot/stdout.expected
463 echo "+<<<<<<< merged change: commit $head_rev" \
464 >> $testroot/stdout.expected
465 echo ' 33' >> $testroot/stdout.expected
466 echo "+||||||| 3-way merge base: commit $base_commit" \
467 >> $testroot/stdout.expected
468 echo '+8' >> $testroot/stdout.expected
469 echo '+=======' >> $testroot/stdout.expected
470 echo '+88' >> $testroot/stdout.expected
471 echo '+>>>>>>>' >> $testroot/stdout.expected
473 (cd $testroot/wt && got diff > $testroot/stdout)
475 cmp -s $testroot/stdout.expected $testroot/stdout
476 ret=$?
477 if [ $ret -ne 0 ]; then
478 diff -u $testroot/stdout.expected $testroot/stdout
479 fi
480 test_done "$testroot" "$ret"
483 test_diff_tag() {
484 local testroot=`test_init diff_tag`
485 local commit_id0=`git_show_head $testroot/repo`
486 local tag1=1.0.0
487 local tag2=2.0.0
489 echo "modified alpha" > $testroot/repo/alpha
490 git_commit $testroot/repo -m "changed alpha"
491 local commit_id1=`git_show_head $testroot/repo`
493 (cd $testroot/repo && git tag -m "test" $tag1)
495 echo "new file" > $testroot/repo/new
496 (cd $testroot/repo && git add new)
497 git_commit $testroot/repo -m "new file"
498 local commit_id2=`git_show_head $testroot/repo`
500 (cd $testroot/repo && git tag -m "test" $tag2)
502 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
503 echo "commit - $commit_id0" >> $testroot/stdout.expected
504 echo "commit + $commit_id1" >> $testroot/stdout.expected
505 echo -n 'blob - ' >> $testroot/stdout.expected
506 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
507 cut -d' ' -f 1 >> $testroot/stdout.expected
508 echo -n 'blob + ' >> $testroot/stdout.expected
509 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
510 >> $testroot/stdout.expected
511 echo '--- alpha' >> $testroot/stdout.expected
512 echo '+++ alpha' >> $testroot/stdout.expected
513 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
514 echo '-alpha' >> $testroot/stdout.expected
515 echo '+modified alpha' >> $testroot/stdout.expected
517 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
518 cmp -s $testroot/stdout.expected $testroot/stdout
519 ret=$?
520 if [ $ret -ne 0 ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 test_done "$testroot" "$ret"
523 return 1
524 fi
526 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
527 echo "commit - $commit_id1" >> $testroot/stdout.expected
528 echo "commit + $commit_id2" >> $testroot/stdout.expected
529 echo "blob - /dev/null" >> $testroot/stdout.expected
530 echo -n 'blob + ' >> $testroot/stdout.expected
531 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
532 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
533 echo " (mode 644)" >> $testroot/stdout.expected
534 echo '--- /dev/null' >> $testroot/stdout.expected
535 echo '+++ new' >> $testroot/stdout.expected
536 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
537 echo '+new file' >> $testroot/stdout.expected
539 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
540 cmp -s $testroot/stdout.expected $testroot/stdout
541 ret=$?
542 if [ $ret -ne 0 ]; then
543 diff -u $testroot/stdout.expected $testroot/stdout
544 fi
545 test_done "$testroot" "$ret"
548 test_diff_lightweight_tag() {
549 local testroot=`test_init diff_tag`
550 local commit_id0=`git_show_head $testroot/repo`
551 local tag1=1.0.0
552 local tag2=2.0.0
554 echo "modified alpha" > $testroot/repo/alpha
555 git_commit $testroot/repo -m "changed alpha"
556 local commit_id1=`git_show_head $testroot/repo`
558 (cd $testroot/repo && git tag $tag1)
560 echo "new file" > $testroot/repo/new
561 (cd $testroot/repo && git add new)
562 git_commit $testroot/repo -m "new file"
563 local commit_id2=`git_show_head $testroot/repo`
565 (cd $testroot/repo && git tag $tag2)
567 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
568 echo "commit - $commit_id0" >> $testroot/stdout.expected
569 echo "commit + $commit_id1" >> $testroot/stdout.expected
570 echo -n 'blob - ' >> $testroot/stdout.expected
571 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
572 cut -d' ' -f 1 >> $testroot/stdout.expected
573 echo -n 'blob + ' >> $testroot/stdout.expected
574 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
575 >> $testroot/stdout.expected
576 echo '--- alpha' >> $testroot/stdout.expected
577 echo '+++ alpha' >> $testroot/stdout.expected
578 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
579 echo '-alpha' >> $testroot/stdout.expected
580 echo '+modified alpha' >> $testroot/stdout.expected
582 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
583 cmp -s $testroot/stdout.expected $testroot/stdout
584 ret=$?
585 if [ $ret -ne 0 ]; then
586 diff -u $testroot/stdout.expected $testroot/stdout
587 test_done "$testroot" "$ret"
588 return 1
589 fi
591 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
592 echo "commit - $commit_id1" >> $testroot/stdout.expected
593 echo "commit + $commit_id2" >> $testroot/stdout.expected
594 echo "blob - /dev/null" >> $testroot/stdout.expected
595 echo -n 'blob + ' >> $testroot/stdout.expected
596 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
597 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
598 echo " (mode 644)" >> $testroot/stdout.expected
599 echo '--- /dev/null' >> $testroot/stdout.expected
600 echo '+++ new' >> $testroot/stdout.expected
601 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
602 echo '+new file' >> $testroot/stdout.expected
604 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
605 cmp -s $testroot/stdout.expected $testroot/stdout
606 ret=$?
607 if [ $ret -ne 0 ]; then
608 diff -u $testroot/stdout.expected $testroot/stdout
609 fi
610 test_done "$testroot" "$ret"
613 test_diff_ignore_whitespace() {
614 local testroot=`test_init diff_ignore_whitespace`
615 local commit_id0=`git_show_head $testroot/repo`
617 got checkout $testroot/repo $testroot/wt > /dev/null
618 ret=$?
619 if [ $ret -ne 0 ]; then
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 echo "alpha " > $testroot/wt/alpha
626 (cd $testroot/wt && got diff -w > $testroot/stdout)
628 echo "diff $testroot/wt" > $testroot/stdout.expected
629 echo "commit - $commit_id0" >> $testroot/stdout.expected
630 echo "path + $testroot/wt" >> $testroot/stdout.expected
631 echo -n 'blob - ' >> $testroot/stdout.expected
632 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
633 cut -d' ' -f 1 >> $testroot/stdout.expected
634 echo 'file + alpha' >> $testroot/stdout.expected
636 cmp -s $testroot/stdout.expected $testroot/stdout
637 ret=$?
638 if [ $ret -ne 0 ]; then
639 diff -u $testroot/stdout.expected $testroot/stdout
640 fi
641 test_done "$testroot" "$ret"
644 test_diff_submodule_of_same_repo() {
645 local testroot=`test_init diff_submodule_of_same_repo`
647 (cd $testroot && git clone -q repo repo2 >/dev/null)
648 (cd $testroot/repo && git submodule -q add ../repo2)
649 (cd $testroot/repo && git commit -q -m 'adding submodule')
651 epsilon_id=$(got tree -r $testroot/repo -i | grep 'epsilon/$' | \
652 cut -d ' ' -f 1)
653 submodule_id=$(got tree -r $testroot/repo -i | grep 'repo2\$$' | \
654 cut -d ' ' -f 1)
656 # Attempt a (nonsensical) diff between a tree object and a submodule.
657 # Currently fails with "wrong type of object" error
658 got diff -r $testroot/repo $epsilon_id $submodule_id \
659 > $testroot/stdout 2> $testroot/stderr
660 ret=$?
661 if [ $ret -eq 0 ]; then
662 echo "diff command succeeded unexpectedly" >&2
663 test_done "$testroot" "1"
664 return 1
665 fi
666 echo "got: wrong type of object" > $testroot/stderr.expected
668 cmp -s $testroot/stderr.expected $testroot/stderr
669 ret=$?
670 if [ $ret -ne 0 ]; then
671 diff -u $testroot/stderr.expected $testroot/stderr
672 return 1
673 fi
674 test_done "$testroot" "$ret"
677 test_diff_symlinks_in_work_tree() {
678 local testroot=`test_init diff_symlinks_in_work_tree`
680 (cd $testroot/repo && ln -s alpha alpha.link)
681 (cd $testroot/repo && ln -s epsilon epsilon.link)
682 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
683 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
684 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
685 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
686 (cd $testroot/repo && git add .)
687 git_commit $testroot/repo -m "add symlinks"
688 local commit_id1=`git_show_head $testroot/repo`
690 got checkout $testroot/repo $testroot/wt > /dev/null
691 ret=$?
692 if [ $ret -ne 0 ]; then
693 test_done "$testroot" "$ret"
694 return 1
695 fi
697 (cd $testroot/wt && ln -sf beta alpha.link)
698 (cd $testroot/wt && ln -sfh gamma epsilon.link)
699 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
700 echo -n '.got/bar' > $testroot/wt/dotgotfoo.link
701 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
702 (cd $testroot/wt && ln -sf epsilon/zeta zeta.link)
703 (cd $testroot/wt && got add zeta.link > /dev/null)
704 (cd $testroot/wt && got diff > $testroot/stdout)
706 echo "diff $testroot/wt" > $testroot/stdout.expected
707 echo "commit - $commit_id1" >> $testroot/stdout.expected
708 echo "path + $testroot/wt" >> $testroot/stdout.expected
709 echo -n 'blob - ' >> $testroot/stdout.expected
710 got tree -r $testroot/repo -c $commit_id1 -i | \
711 grep 'alpha.link@ -> alpha$' | \
712 cut -d' ' -f 1 >> $testroot/stdout.expected
713 echo 'file + alpha.link' >> $testroot/stdout.expected
714 echo '--- alpha.link' >> $testroot/stdout.expected
715 echo '+++ alpha.link' >> $testroot/stdout.expected
716 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
717 echo '-alpha' >> $testroot/stdout.expected
718 echo '\ No newline at end of file' >> $testroot/stdout.expected
719 echo '+beta' >> $testroot/stdout.expected
720 echo '\ No newline at end of file' >> $testroot/stdout.expected
721 echo -n 'blob - ' >> $testroot/stdout.expected
722 got tree -r $testroot/repo -c $commit_id1 -i | \
723 grep 'dotgotfoo.link@ -> .got/foo$' | \
724 cut -d' ' -f 1 >> $testroot/stdout.expected
725 echo 'file + dotgotfoo.link' >> $testroot/stdout.expected
726 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
727 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
728 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
729 echo '-.got/foo' >> $testroot/stdout.expected
730 echo '\ No newline at end of file' >> $testroot/stdout.expected
731 echo '+.got/bar' >> $testroot/stdout.expected
732 echo '\ No newline at end of file' >> $testroot/stdout.expected
733 echo -n 'blob - ' >> $testroot/stdout.expected
734 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
735 grep 'beta.link@ -> ../beta$' | \
736 cut -d' ' -f 1 >> $testroot/stdout.expected
737 echo 'file + epsilon/beta.link' >> $testroot/stdout.expected
738 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
739 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
740 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
741 echo '-../beta' >> $testroot/stdout.expected
742 echo '\ No newline at end of file' >> $testroot/stdout.expected
743 echo '+../gamma/delta' >> $testroot/stdout.expected
744 echo '\ No newline at end of file' >> $testroot/stdout.expected
745 echo -n 'blob - ' >> $testroot/stdout.expected
746 got tree -r $testroot/repo -c $commit_id1 -i | \
747 grep 'epsilon.link@ -> epsilon$' | \
748 cut -d' ' -f 1 >> $testroot/stdout.expected
749 echo 'file + epsilon.link' >> $testroot/stdout.expected
750 echo '--- epsilon.link' >> $testroot/stdout.expected
751 echo '+++ epsilon.link' >> $testroot/stdout.expected
752 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
753 echo '-epsilon' >> $testroot/stdout.expected
754 echo '\ No newline at end of file' >> $testroot/stdout.expected
755 echo '+gamma' >> $testroot/stdout.expected
756 echo '\ No newline at end of file' >> $testroot/stdout.expected
757 echo -n 'blob - ' >> $testroot/stdout.expected
758 got tree -r $testroot/repo -c $commit_id1 -i | \
759 grep 'nonexistent.link@ -> nonexistent$' | \
760 cut -d' ' -f 1 >> $testroot/stdout.expected
761 echo 'file + /dev/null' >> $testroot/stdout.expected
762 echo '--- nonexistent.link' >> $testroot/stdout.expected
763 echo '+++ /dev/null' >> $testroot/stdout.expected
764 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
765 echo '-nonexistent' >> $testroot/stdout.expected
766 echo '\ No newline at end of file' >> $testroot/stdout.expected
767 echo 'blob - /dev/null' >> $testroot/stdout.expected
768 echo 'file + zeta.link' >> $testroot/stdout.expected
769 echo '--- /dev/null' >> $testroot/stdout.expected
770 echo '+++ zeta.link' >> $testroot/stdout.expected
771 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
772 echo '+epsilon/zeta' >> $testroot/stdout.expected
773 echo '\ No newline at end of file' >> $testroot/stdout.expected
775 cmp -s $testroot/stdout.expected $testroot/stdout
776 ret=$?
777 if [ $ret -ne 0 ]; then
778 diff -u $testroot/stdout.expected $testroot/stdout
779 fi
780 test_done "$testroot" "$ret"
783 test_diff_symlinks_in_repo() {
784 local testroot=`test_init diff_symlinks_in_repo`
786 (cd $testroot/repo && ln -s alpha alpha.link)
787 (cd $testroot/repo && ln -s epsilon epsilon.link)
788 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
789 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
790 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
791 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
792 (cd $testroot/repo && git add .)
793 git_commit $testroot/repo -m "add symlinks"
794 local commit_id1=`git_show_head $testroot/repo`
796 (cd $testroot/repo && ln -sf beta alpha.link)
797 (cd $testroot/repo && ln -sfh gamma epsilon.link)
798 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
799 (cd $testroot/repo && ln -sf .got/bar $testroot/repo/dotgotfoo.link)
800 (cd $testroot/repo && git rm -q nonexistent.link)
801 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
802 (cd $testroot/repo && git add .)
803 git_commit $testroot/repo -m "change symlinks"
804 local commit_id2=`git_show_head $testroot/repo`
806 got diff -r $testroot/repo $commit_id1 $commit_id2 > $testroot/stdout
808 echo "diff $commit_id1 $commit_id2" > $testroot/stdout.expected
809 echo "commit - $commit_id1" >> $testroot/stdout.expected
810 echo "commit + $commit_id2" >> $testroot/stdout.expected
811 echo -n 'blob - ' >> $testroot/stdout.expected
812 got tree -r $testroot/repo -c $commit_id1 -i | \
813 grep 'alpha.link@ -> alpha$' | \
814 cut -d' ' -f 1 >> $testroot/stdout.expected
815 echo -n 'blob + ' >> $testroot/stdout.expected
816 got tree -r $testroot/repo -c $commit_id2 -i | \
817 grep 'alpha.link@ -> beta$' | \
818 cut -d' ' -f 1 >> $testroot/stdout.expected
819 echo '--- alpha.link' >> $testroot/stdout.expected
820 echo '+++ alpha.link' >> $testroot/stdout.expected
821 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
822 echo '-alpha' >> $testroot/stdout.expected
823 echo '\ No newline at end of file' >> $testroot/stdout.expected
824 echo '+beta' >> $testroot/stdout.expected
825 echo '\ No newline at end of file' >> $testroot/stdout.expected
826 echo -n 'blob - ' >> $testroot/stdout.expected
827 got tree -r $testroot/repo -c $commit_id1 -i | \
828 grep 'dotgotfoo.link@ -> .got/foo$' | \
829 cut -d' ' -f 1 >> $testroot/stdout.expected
830 echo -n 'blob + ' >> $testroot/stdout.expected
831 got tree -r $testroot/repo -c $commit_id2 -i | \
832 grep 'dotgotfoo.link@ -> .got/bar$' | \
833 cut -d' ' -f 1 >> $testroot/stdout.expected
834 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
835 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
836 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
837 echo '-.got/foo' >> $testroot/stdout.expected
838 echo '\ No newline at end of file' >> $testroot/stdout.expected
839 echo '+.got/bar' >> $testroot/stdout.expected
840 echo '\ No newline at end of file' >> $testroot/stdout.expected
841 echo -n 'blob - ' >> $testroot/stdout.expected
842 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
843 grep 'beta.link@ -> ../beta$' | \
844 cut -d' ' -f 1 >> $testroot/stdout.expected
845 echo -n 'blob + ' >> $testroot/stdout.expected
846 got tree -r $testroot/repo -c $commit_id2 -i epsilon | \
847 grep 'beta.link@ -> ../gamma/delta$' | \
848 cut -d' ' -f 1 >> $testroot/stdout.expected
849 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
850 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
851 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
852 echo '-../beta' >> $testroot/stdout.expected
853 echo '\ No newline at end of file' >> $testroot/stdout.expected
854 echo '+../gamma/delta' >> $testroot/stdout.expected
855 echo '\ No newline at end of file' >> $testroot/stdout.expected
856 echo -n 'blob - ' >> $testroot/stdout.expected
857 got tree -r $testroot/repo -c $commit_id1 -i | \
858 grep 'epsilon.link@ -> epsilon$' | \
859 cut -d' ' -f 1 >> $testroot/stdout.expected
860 echo -n 'blob + ' >> $testroot/stdout.expected
861 got tree -r $testroot/repo -c $commit_id2 -i | \
862 grep 'epsilon.link@ -> gamma$' | \
863 cut -d' ' -f 1 >> $testroot/stdout.expected
864 echo '--- epsilon.link' >> $testroot/stdout.expected
865 echo '+++ epsilon.link' >> $testroot/stdout.expected
866 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
867 echo '-epsilon' >> $testroot/stdout.expected
868 echo '\ No newline at end of file' >> $testroot/stdout.expected
869 echo '+gamma' >> $testroot/stdout.expected
870 echo '\ No newline at end of file' >> $testroot/stdout.expected
871 echo -n 'blob - ' >> $testroot/stdout.expected
872 got tree -r $testroot/repo -c $commit_id1 -i | \
873 grep 'nonexistent.link@ -> nonexistent$' | \
874 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
875 >> $testroot/stdout.expected
876 echo 'blob + /dev/null' >> $testroot/stdout.expected
877 echo '--- nonexistent.link' >> $testroot/stdout.expected
878 echo '+++ /dev/null' >> $testroot/stdout.expected
879 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
880 echo '-nonexistent' >> $testroot/stdout.expected
881 echo '\ No newline at end of file' >> $testroot/stdout.expected
882 echo 'blob - /dev/null' >> $testroot/stdout.expected
883 echo -n 'blob + ' >> $testroot/stdout.expected
884 got tree -r $testroot/repo -c $commit_id2 -i | \
885 grep 'zeta.link@ -> epsilon/zeta$' | \
886 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
887 >> $testroot/stdout.expected
888 echo '--- /dev/null' >> $testroot/stdout.expected
889 echo '+++ zeta.link' >> $testroot/stdout.expected
890 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
891 echo '+epsilon/zeta' >> $testroot/stdout.expected
892 echo '\ No newline at end of file' >> $testroot/stdout.expected
894 cmp -s $testroot/stdout.expected $testroot/stdout
895 ret=$?
896 if [ $ret -ne 0 ]; then
897 diff -u $testroot/stdout.expected $testroot/stdout
898 fi
899 test_done "$testroot" "$ret"
902 test_diff_binary_files() {
903 local testroot=`test_init diff_binary_files`
904 local head_rev=`git_show_head $testroot/repo`
906 got checkout $testroot/repo $testroot/wt > /dev/null
907 ret=$?
908 if [ $ret -ne 0 ]; then
909 test_done "$testroot" "$ret"
910 return 1
911 fi
913 printf '\377\377\0\0\377\377\0\0' > $testroot/wt/foo
914 (cd $testroot/wt && got add foo >/dev/null)
916 echo "diff $testroot/wt" > $testroot/stdout.expected
917 echo "commit - $head_rev" >> $testroot/stdout.expected
918 echo "path + $testroot/wt" >> $testroot/stdout.expected
919 echo 'blob - /dev/null' >> $testroot/stdout.expected
920 echo 'file + foo' >> $testroot/stdout.expected
921 echo "Binary files /dev/null and foo differ" \
922 >> $testroot/stdout.expected
924 (cd $testroot/wt && got diff > $testroot/stdout)
925 cmp -s $testroot/stdout.expected $testroot/stdout
926 ret=$?
927 if [ $ret -ne 0 ]; then
928 diff -a -u $testroot/stdout.expected $testroot/stdout
929 test_done "$testroot" "$ret"
930 return 1
931 fi
933 echo "diff $testroot/wt" > $testroot/stdout.expected
934 echo "commit - $head_rev" >> $testroot/stdout.expected
935 echo "path + $testroot/wt" >> $testroot/stdout.expected
936 echo 'blob - /dev/null' >> $testroot/stdout.expected
937 echo 'file + foo' >> $testroot/stdout.expected
938 echo '--- /dev/null' >> $testroot/stdout.expected
939 echo '+++ foo' >> $testroot/stdout.expected
940 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
941 printf '+\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
942 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
944 (cd $testroot/wt && got diff -a > $testroot/stdout)
945 cmp -s $testroot/stdout.expected $testroot/stdout
946 ret=$?
947 if [ $ret -ne 0 ]; then
948 diff -a -u $testroot/stdout.expected $testroot/stdout
949 test_done "$testroot" "$ret"
950 return 1
951 fi
953 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
954 local head_rev=`git_show_head $testroot/repo`
956 printf '\377\200\0\0\377\200\0\0' > $testroot/wt/foo
958 echo "diff $testroot/wt" > $testroot/stdout.expected
959 echo "commit - $head_rev" >> $testroot/stdout.expected
960 echo "path + $testroot/wt" >> $testroot/stdout.expected
961 echo -n 'blob - ' >> $testroot/stdout.expected
962 got tree -r $testroot/repo -i | grep 'foo$' | cut -d' ' -f 1 \
963 >> $testroot/stdout.expected
964 echo 'file + foo' >> $testroot/stdout.expected
965 echo '--- foo' >> $testroot/stdout.expected
966 echo '+++ foo' >> $testroot/stdout.expected
967 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
968 printf -- '-\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
969 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
970 printf '+\377\200\0\0\377\200\0\0\n' >> $testroot/stdout.expected
971 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
973 (cd $testroot/wt && got diff -a > $testroot/stdout)
974 cmp -s $testroot/stdout.expected $testroot/stdout
975 ret=$?
976 if [ $ret -ne 0 ]; then
977 diff -a -u $testroot/stdout.expected $testroot/stdout
978 fi
979 test_done "$testroot" "$ret"
982 test_diff_commits() {
983 local testroot=`test_init diff_commits`
984 local commit_id0=`git_show_head $testroot/repo`
985 alpha_id0=`get_blob_id $testroot/repo "" alpha`
986 beta_id0=`get_blob_id $testroot/repo "" beta`
988 got checkout $testroot/repo $testroot/wt > /dev/null
989 ret=$?
990 if [ $ret -ne 0 ]; then
991 test_done "$testroot" "$ret"
992 return 1
993 fi
995 echo "modified alpha" > $testroot/wt/alpha
996 (cd $testroot/wt && got rm beta >/dev/null)
997 echo "new file" > $testroot/wt/new
998 (cd $testroot/wt && got add new >/dev/null)
999 (cd $testroot/wt && got commit -m 'committing changes' >/dev/null)
1000 local commit_id1=`git_show_head $testroot/repo`
1002 alpha_id1=`get_blob_id $testroot/repo "" alpha`
1003 new_id1=`get_blob_id $testroot/repo "" new`
1005 echo "diff $commit_id0 refs/heads/master" > $testroot/stdout.expected
1006 echo "commit - $commit_id0" >> $testroot/stdout.expected
1007 echo "commit + $commit_id1" >> $testroot/stdout.expected
1008 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1009 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1010 echo '--- alpha' >> $testroot/stdout.expected
1011 echo '+++ alpha' >> $testroot/stdout.expected
1012 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1013 echo '-alpha' >> $testroot/stdout.expected
1014 echo '+modified alpha' >> $testroot/stdout.expected
1015 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1016 echo 'blob + /dev/null' >> $testroot/stdout.expected
1017 echo '--- beta' >> $testroot/stdout.expected
1018 echo '+++ /dev/null' >> $testroot/stdout.expected
1019 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1020 echo '-beta' >> $testroot/stdout.expected
1021 echo 'blob - /dev/null' >> $testroot/stdout.expected
1022 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1023 echo '--- /dev/null' >> $testroot/stdout.expected
1024 echo '+++ new' >> $testroot/stdout.expected
1025 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1026 echo '+new file' >> $testroot/stdout.expected
1028 (cd $testroot/wt && got diff -c master > $testroot/stdout)
1029 cmp -s $testroot/stdout.expected $testroot/stdout
1030 ret=$?
1031 if [ $ret -ne 0 ]; then
1032 diff -u $testroot/stdout.expected $testroot/stdout
1033 test_done "$testroot" "$ret"
1034 return 1
1037 # same diff with explicit parent commit ID
1038 (cd $testroot/wt && got diff -c $commit_id0 -c master \
1039 > $testroot/stdout)
1040 cmp -s $testroot/stdout.expected $testroot/stdout
1041 ret=$?
1042 if [ $ret -ne 0 ]; then
1043 diff -u $testroot/stdout.expected $testroot/stdout
1044 test_done "$testroot" "$ret"
1045 return 1
1048 # same diff with commit object IDs
1049 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1050 echo "commit - $commit_id0" >> $testroot/stdout.expected
1051 echo "commit + $commit_id1" >> $testroot/stdout.expected
1052 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1053 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1054 echo '--- alpha' >> $testroot/stdout.expected
1055 echo '+++ alpha' >> $testroot/stdout.expected
1056 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1057 echo '-alpha' >> $testroot/stdout.expected
1058 echo '+modified alpha' >> $testroot/stdout.expected
1059 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1060 echo 'blob + /dev/null' >> $testroot/stdout.expected
1061 echo '--- beta' >> $testroot/stdout.expected
1062 echo '+++ /dev/null' >> $testroot/stdout.expected
1063 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1064 echo '-beta' >> $testroot/stdout.expected
1065 echo 'blob - /dev/null' >> $testroot/stdout.expected
1066 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1067 echo '--- /dev/null' >> $testroot/stdout.expected
1068 echo '+++ new' >> $testroot/stdout.expected
1069 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1070 echo '+new file' >> $testroot/stdout.expected
1071 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 \
1072 > $testroot/stdout)
1073 cmp -s $testroot/stdout.expected $testroot/stdout
1074 ret=$?
1075 if [ $ret -ne 0 ]; then
1076 diff -u $testroot/stdout.expected $testroot/stdout
1077 test_done "$testroot" "$ret"
1078 return 1
1081 # same diff, filtered by paths
1082 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1083 echo "commit - $commit_id0" >> $testroot/stdout.expected
1084 echo "commit + $commit_id1" >> $testroot/stdout.expected
1085 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1086 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1087 echo '--- alpha' >> $testroot/stdout.expected
1088 echo '+++ alpha' >> $testroot/stdout.expected
1089 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1090 echo '-alpha' >> $testroot/stdout.expected
1091 echo '+modified alpha' >> $testroot/stdout.expected
1092 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 alpha \
1093 > $testroot/stdout)
1094 cmp -s $testroot/stdout.expected $testroot/stdout
1095 ret=$?
1096 if [ $ret -ne 0 ]; then
1097 diff -u $testroot/stdout.expected $testroot/stdout
1098 test_done "$testroot" "$ret"
1099 return 1
1101 # same in a work tree
1102 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 alpha \
1103 > $testroot/stdout)
1104 cmp -s $testroot/stdout.expected $testroot/stdout
1105 ret=$?
1106 if [ $ret -ne 0 ]; then
1107 diff -u $testroot/stdout.expected $testroot/stdout
1108 test_done "$testroot" "$ret"
1109 return 1
1112 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1113 echo "commit - $commit_id0" >> $testroot/stdout.expected
1114 echo "commit + $commit_id1" >> $testroot/stdout.expected
1115 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1116 echo 'blob + /dev/null' >> $testroot/stdout.expected
1117 echo '--- beta' >> $testroot/stdout.expected
1118 echo '+++ /dev/null' >> $testroot/stdout.expected
1119 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1120 echo '-beta' >> $testroot/stdout.expected
1121 echo 'blob - /dev/null' >> $testroot/stdout.expected
1122 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1123 echo '--- /dev/null' >> $testroot/stdout.expected
1124 echo '+++ new' >> $testroot/stdout.expected
1125 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1126 echo '+new file' >> $testroot/stdout.expected
1127 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 \
1128 beta new > $testroot/stdout)
1129 cmp -s $testroot/stdout.expected $testroot/stdout
1130 ret=$?
1131 if [ $ret -ne 0 ]; then
1132 diff -u $testroot/stdout.expected $testroot/stdout
1133 test_done "$testroot" "$ret"
1134 return 1
1137 # more than two -c options are not allowed
1138 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 -c foo \
1139 2> $testroot/stderr)
1140 ret=$?
1141 if [ $ret -eq 0 ]; then
1142 echo "diff succeeded unexpectedly" >&2
1143 test_done "$testroot" "1"
1144 return 1
1146 echo "got: too many -c options used" > $testroot/stderr.expected
1147 cmp -s $testroot/stderr.expected $testroot/stderr
1148 ret=$?
1149 if [ $ret -ne 0 ]; then
1150 diff -u $testroot/stderr.expected $testroot/stderr
1151 test_done "$testroot" "$ret"
1152 return 1
1155 # use of -c options implies a repository diff; use with -P is an error
1156 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -P foo \
1157 2> $testroot/stderr)
1158 ret=$?
1159 if [ $ret -eq 0 ]; then
1160 echo "diff succeeded unexpectedly" >&2
1161 test_done "$testroot" "1"
1162 return 1
1164 echo "got: -P option can only be used when diffing a work tree" \
1165 > $testroot/stderr.expected
1166 cmp -s $testroot/stderr.expected $testroot/stderr
1167 ret=$?
1168 if [ $ret -ne 0 ]; then
1169 diff -u $testroot/stderr.expected $testroot/stderr
1170 test_done "$testroot" "$ret"
1171 return 1
1174 # use of -c options implies a repository diff; use with -s is an error
1175 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -s foo \
1176 2> $testroot/stderr)
1177 ret=$?
1178 if [ $ret -eq 0 ]; then
1179 echo "diff succeeded unexpectedly" >&2
1180 test_done "$testroot" "1"
1181 return 1
1183 echo "got: -s option can only be used when diffing a work tree" \
1184 > $testroot/stderr.expected
1185 cmp -s $testroot/stderr.expected $testroot/stderr
1186 ret=$?
1187 if [ $ret -ne 0 ]; then
1188 diff -u $testroot/stderr.expected $testroot/stderr
1189 test_done "$testroot" "$ret"
1190 return 1
1193 # three arguments imply use of path filtering (repository case)
1194 (cd $testroot/repo && got diff $commit_id0 $commit_id1 foo \
1195 2> $testroot/stderr)
1196 ret=$?
1197 if [ $ret -eq 0 ]; then
1198 echo "diff succeeded unexpectedly" >&2
1199 test_done "$testroot" "1"
1200 return 1
1202 echo "got: specified paths cannot be resolved: no got work tree found" \
1203 > $testroot/stderr.expected
1204 cmp -s $testroot/stderr.expected $testroot/stderr
1205 ret=$?
1206 if [ $ret -ne 0 ]; then
1207 diff -u $testroot/stderr.expected $testroot/stderr
1208 test_done "$testroot" "$ret"
1209 return 1
1212 # three arguments imply use of path filtering (work tree case)
1213 (cd $testroot/wt && got diff $commit_id0 master foo \
1214 2> $testroot/stderr)
1215 ret=$?
1216 if [ $ret -eq 0 ]; then
1217 echo "diff succeeded unexpectedly" >&2
1218 test_done "$testroot" "1"
1219 return 1
1221 echo "got: $commit_id0: No such file or directory" \
1222 > $testroot/stderr.expected
1223 cmp -s $testroot/stderr.expected $testroot/stderr
1224 ret=$?
1225 if [ $ret -ne 0 ]; then
1226 diff -u $testroot/stderr.expected $testroot/stderr
1228 test_done "$testroot" "$ret"
1231 test_diff_ignored_file() {
1232 local testroot=`test_init diff_ignored_file`
1234 got checkout $testroot/repo $testroot/wt > /dev/null
1235 ret=$?
1236 if [ $ret -ne 0 ]; then
1237 test_done "$testroot" "$ret"
1238 return 1
1241 echo 1 > $testroot/wt/number
1242 (cd $testroot/wt && got add number >/dev/null)
1243 (cd $testroot/wt && got commit -m 'add number' >/dev/null)
1245 echo "**/number" > $testroot/wt/.gitignore
1247 echo 2 > $testroot/wt/number
1248 (cd $testroot/wt && got diff number | sed '1,/^@@/d' > $testroot/stdout)
1250 echo "-1" > $testroot/stdout.expected
1251 echo "+2" >> $testroot/stdout.expected
1253 cmp -s $testroot/stdout.expected $testroot/stdout
1254 ret=$?
1255 if [ $ret -ne 0 ]; then
1256 diff -u $testroot/stdout.expected $testroot/stdout
1258 test_done "$testroot" "$ret"
1261 test_parseargs "$@"
1262 run_test test_diff_basic
1263 run_test test_diff_shows_conflict
1264 run_test test_diff_tag
1265 run_test test_diff_lightweight_tag
1266 run_test test_diff_ignore_whitespace
1267 run_test test_diff_submodule_of_same_repo
1268 run_test test_diff_symlinks_in_work_tree
1269 run_test test_diff_symlinks_in_repo
1270 run_test test_diff_binary_files
1271 run_test test_diff_commits
1272 run_test test_diff_ignored_file