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