3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
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
25 if [ "$ret" != "0" ]; then
26 test_done
"$testroot" "$ret"
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
63 if [ "$ret" != "0" ]; then
64 diff -u $testroot/stdout.expected
$testroot/stdout
65 test_done
"$testroot" "$ret"
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
74 if [ "$ret" != "0" ]; then
75 diff -u $testroot/stderr.expected
$testroot/stderr
76 test_done
"$testroot" "$ret"
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
86 if [ "$ret" != "0" ]; then
87 diff -u $testroot/stderr.expected
$testroot/stderr
88 test_done
"$testroot" "$ret"
92 # diff non-existent path
93 (cd $testroot/wt
&& got
diff nonexistent
> $testroot/stdout \
96 echo -n > $testroot/stdout.expected
97 cmp -s $testroot/stdout.expected
$testroot/stdout
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/stdout.expected
$testroot/stdout
101 test_done
"$testroot" "$ret"
105 echo "got: nonexistent: No such file or directory" \
106 > $testroot/stderr.expected
107 cmp -s $testroot/stderr.expected
$testroot/stderr
109 if [ "$ret" != "0" ]; then
110 diff -u $testroot/stderr.expected
$testroot/stderr
111 test_done
"$testroot" "$ret"
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 'blob - /dev/null' >> $testroot/stdout.expected
120 echo 'file + new' >> $testroot/stdout.expected
121 echo '--- /dev/null' >> $testroot/stdout.expected
122 echo '+++ new' >> $testroot/stdout.expected
123 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
124 echo '+new file' >> $testroot/stdout.expected
125 echo -n 'blob - ' >> $testroot/stdout.expected
126 got tree
-r $testroot/repo
-i |
grep 'alpha$' | cut
-d' ' -f 1 \
127 >> $testroot/stdout.expected
128 echo 'file + alpha' >> $testroot/stdout.expected
129 echo '--- alpha' >> $testroot/stdout.expected
130 echo '+++ alpha' >> $testroot/stdout.expected
131 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
132 echo '-alpha' >> $testroot/stdout.expected
133 echo '+modified alpha' >> $testroot/stdout.expected
134 echo -n 'blob - ' >> $testroot/stdout.expected
135 got tree
-r $testroot/repo
-i epsilon |
grep 'zeta$' | cut
-d' ' -f 1 \
136 >> $testroot/stdout.expected
137 echo 'file + epsilon/zeta' >> $testroot/stdout.expected
138 echo '--- epsilon/zeta' >> $testroot/stdout.expected
139 echo '+++ epsilon/zeta' >> $testroot/stdout.expected
140 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
141 echo '-zeta' >> $testroot/stdout.expected
142 echo '+modified zeta' >> $testroot/stdout.expected
143 echo -n 'blob - ' >> $testroot/stdout.expected
144 got tree
-r $testroot/repo
-i |
grep 'beta$' | cut
-d' ' -f 1 \
145 >> $testroot/stdout.expected
146 echo 'file + /dev/null' >> $testroot/stdout.expected
147 echo '--- beta' >> $testroot/stdout.expected
148 echo '+++ /dev/null' >> $testroot/stdout.expected
149 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
150 echo '-beta' >> $testroot/stdout.expected
152 (cd $testroot/wt
&& got
diff new alpha epsilon beta
> $testroot/stdout
)
153 cmp -s $testroot/stdout.expected
$testroot/stdout
155 if [ "$ret" != "0" ]; then
156 diff -u $testroot/stdout.expected
$testroot/stdout
157 test_done
"$testroot" "$ret"
161 # a branch 'new' should not collide with path 'new' if more
162 # than two arguments are passed
163 got br
-r $testroot/repo
-c master new
> /dev
/null
164 (cd $testroot/wt
&& got
diff new alpha epsilon beta \
165 > $testroot/stdout
2> $testroot/stderr
)
167 if [ "$ret" != "0" ]; then
168 echo "diff failed unexpectedly" >&2
169 test_done
"$testroot" "1"
172 cmp -s $testroot/stdout.expected
$testroot/stdout
174 if [ "$ret" != "0" ]; then
175 diff -u $testroot/stdout.expected
$testroot/stdout
176 test_done
"$testroot" "$ret"
180 # different order of arguments results in different output order
181 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
182 echo -n 'blob - ' >> $testroot/stdout.expected
183 got tree
-r $testroot/repo
-i |
grep 'alpha$' | cut
-d' ' -f 1 \
184 >> $testroot/stdout.expected
185 echo 'file + alpha' >> $testroot/stdout.expected
186 echo '--- alpha' >> $testroot/stdout.expected
187 echo '+++ alpha' >> $testroot/stdout.expected
188 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
189 echo '-alpha' >> $testroot/stdout.expected
190 echo '+modified alpha' >> $testroot/stdout.expected
191 echo 'blob - /dev/null' >> $testroot/stdout.expected
192 echo 'file + new' >> $testroot/stdout.expected
193 echo '--- /dev/null' >> $testroot/stdout.expected
194 echo '+++ new' >> $testroot/stdout.expected
195 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
196 echo '+new file' >> $testroot/stdout.expected
197 echo -n 'blob - ' >> $testroot/stdout.expected
198 got tree
-r $testroot/repo
-i epsilon |
grep 'zeta$' | cut
-d' ' -f 1 \
199 >> $testroot/stdout.expected
200 echo 'file + epsilon/zeta' >> $testroot/stdout.expected
201 echo '--- epsilon/zeta' >> $testroot/stdout.expected
202 echo '+++ epsilon/zeta' >> $testroot/stdout.expected
203 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
204 echo '-zeta' >> $testroot/stdout.expected
205 echo '+modified zeta' >> $testroot/stdout.expected
206 echo -n 'blob - ' >> $testroot/stdout.expected
207 got tree
-r $testroot/repo
-i |
grep 'beta$' | cut
-d' ' -f 1 \
208 >> $testroot/stdout.expected
209 echo 'file + /dev/null' >> $testroot/stdout.expected
210 echo '--- beta' >> $testroot/stdout.expected
211 echo '+++ /dev/null' >> $testroot/stdout.expected
212 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
213 echo '-beta' >> $testroot/stdout.expected
214 (cd $testroot/wt
&& got
diff alpha new epsilon beta \
215 > $testroot/stdout
2> $testroot/stderr
)
217 if [ "$ret" != "0" ]; then
218 echo "diff failed unexpectedly" >&2
219 test_done
"$testroot" "1"
222 cmp -s $testroot/stdout.expected
$testroot/stdout
224 if [ "$ret" != "0" ]; then
225 diff -u $testroot/stdout.expected
$testroot/stdout
226 test_done
"$testroot" "$ret"
230 # Two arguments are interpreted as objects if a colliding path exists
231 echo master
> $testroot/wt
/master
232 (cd $testroot/wt
&& got add master
> /dev
/null
)
233 (cd $testroot/wt
&& got
diff master new
> $testroot/stdout
)
235 if [ "$ret" != "0" ]; then
236 echo "diff failed unexpectedly" >&2
237 test_done
"$testroot" "1"
240 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
241 # diff between the branches is empty
242 cmp -s $testroot/stdout.expected
$testroot/stdout
244 if [ "$ret" != "0" ]; then
245 diff -u $testroot/stdout.expected
$testroot/stdout
246 test_done
"$testroot" "$ret"
249 # same without a work tree
250 (cd $testroot/repo
&& got
diff master new
> $testroot/stdout
)
252 if [ "$ret" != "0" ]; then
253 echo "diff failed unexpectedly" >&2
254 test_done
"$testroot" "1"
257 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
258 cmp -s $testroot/stdout.expected
$testroot/stdout
260 if [ "$ret" != "0" ]; then
261 diff -u $testroot/stdout.expected
$testroot/stdout
262 test_done
"$testroot" "$ret"
265 # same with -r argument
266 got
diff -r $testroot/repo master new
> $testroot/stdout
268 if [ "$ret" != "0" ]; then
269 echo "diff failed unexpectedly" >&2
270 test_done
"$testroot" "1"
273 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
274 cmp -s $testroot/stdout.expected
$testroot/stdout
276 if [ "$ret" != "0" ]; then
277 diff -u $testroot/stdout.expected
$testroot/stdout
278 test_done
"$testroot" "$ret"
282 # -P can be used to force use of paths
283 (cd $testroot/wt
&& got
diff -P new master
> $testroot/stdout
)
285 if [ "$ret" != "0" ]; then
286 echo "diff failed unexpectedly" >&2
287 test_done
"$testroot" "1"
290 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
291 echo 'blob - /dev/null' >> $testroot/stdout.expected
292 echo 'file + new' >> $testroot/stdout.expected
293 echo '--- /dev/null' >> $testroot/stdout.expected
294 echo '+++ new' >> $testroot/stdout.expected
295 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
296 echo '+new file' >> $testroot/stdout.expected
297 echo 'blob - /dev/null' >> $testroot/stdout.expected
298 echo 'file + master' >> $testroot/stdout.expected
299 echo '--- /dev/null' >> $testroot/stdout.expected
300 echo '+++ master' >> $testroot/stdout.expected
301 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
302 echo '+master' >> $testroot/stdout.expected
303 cmp -s $testroot/stdout.expected
$testroot/stdout
305 if [ "$ret" != "0" ]; then
306 diff -u $testroot/stdout.expected
$testroot/stdout
307 test_done
"$testroot" "$ret"
311 # -P can only be used in a work tree
312 got
diff -r $testroot/repo
-P new master
2> $testroot/stderr
314 if [ "$ret" == "0" ]; then
315 echo "diff succeeded unexpectedly" >&2
316 test_done
"$testroot" "1"
319 echo "got: -P option can only be used when diffing a work tree" \
320 > $testroot/stderr.expected
321 cmp -s $testroot/stderr.expected
$testroot/stderr
323 if [ "$ret" != "0" ]; then
324 diff -u $testroot/stderr.expected
$testroot/stderr
325 test_done
"$testroot" "$ret"
329 # a single argument which can be resolved to a path is not ambiguous
330 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
331 echo 'blob - /dev/null' >> $testroot/stdout.expected
332 echo 'file + new' >> $testroot/stdout.expected
333 echo '--- /dev/null' >> $testroot/stdout.expected
334 echo '+++ new' >> $testroot/stdout.expected
335 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
336 echo '+new file' >> $testroot/stdout.expected
337 (cd $testroot/wt
&& got
diff new
> $testroot/stdout
)
339 if [ "$ret" != "0" ]; then
340 echo "diff failed unexpectedly" >&2
341 test_done
"$testroot" "1"
344 cmp -s $testroot/stdout.expected
$testroot/stdout
346 if [ "$ret" != "0" ]; then
347 diff -u $testroot/stdout.expected
$testroot/stdout
348 test_done
"$testroot" "$ret"
352 # diff with just one object ID argument results in
353 # interpretation of argument as a path
354 (cd $testroot/wt
&& got
diff $head_rev 2> $testroot/stderr
)
356 if [ "$ret" = "0" ]; then
357 echo "diff succeeded unexpectedly" >&2
358 test_done
"$testroot" "1"
361 echo "got: $head_rev: No such file or directory" \
362 > $testroot/stderr.expected
363 cmp -s $testroot/stderr.expected
$testroot/stderr
365 if [ "$ret" != "0" ]; then
366 diff -u $testroot/stderr.expected
$testroot/stderr
367 test_done
"$testroot" "$ret"
371 # diff with more than two object arguments results in
372 # interpretation of arguments as paths
373 (cd $testroot/wt
&& got
diff new
$head_rev master \
374 > $testroot/stout
2> $testroot/stderr
)
376 if [ "$ret" = "0" ]; then
377 echo "diff succeeded unexpectedly" >&2
378 test_done
"$testroot" "1"
382 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
383 echo 'blob - /dev/null' >> $testroot/stdout.expected
384 echo 'file + new' >> $testroot/stdout.expected
385 echo '--- /dev/null' >> $testroot/stdout.expected
386 echo '+++ new' >> $testroot/stdout.expected
387 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
388 echo '+new file' >> $testroot/stdout.expected
389 cmp -s $testroot/stdout.expected
$testroot/stdout
391 if [ "$ret" != "0" ]; then
392 diff -u $testroot/stdout.expected
$testroot/stdout
393 test_done
"$testroot" "$ret"
397 echo "got: $head_rev: No such file or directory" \
398 > $testroot/stderr.expected
399 cmp -s $testroot/stderr.expected
$testroot/stderr
401 if [ "$ret" != "0" ]; then
402 diff -u $testroot/stderr.expected
$testroot/stderr
405 test_done
"$testroot" "$ret"
408 test_diff_shows_conflict
() {
409 local testroot
=`test_init diff_shows_conflict 1`
411 echo "1" > $testroot/repo
/numbers
412 echo "2" >> $testroot/repo
/numbers
413 echo "3" >> $testroot/repo
/numbers
414 echo "4" >> $testroot/repo
/numbers
415 echo "5" >> $testroot/repo
/numbers
416 echo "6" >> $testroot/repo
/numbers
417 echo "7" >> $testroot/repo
/numbers
418 echo "8" >> $testroot/repo
/numbers
419 (cd $testroot/repo
&& git add numbers
)
420 git_commit
$testroot/repo
-m "added numbers file"
421 local base_commit
=`git_show_head $testroot/repo`
423 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
425 if [ "$ret" != "0" ]; then
426 test_done
"$testroot" "$ret"
430 sed -i '' 's/2/22/' $testroot/repo
/numbers
431 sed -i '' 's/8/33/' $testroot/repo
/numbers
432 git_commit
$testroot/repo
-m "modified line 2"
433 local head_rev
=`git_show_head $testroot/repo`
435 # modify lines 2 and 8 in conflicting ways
436 sed -i '' 's/2/77/' $testroot/wt
/numbers
437 sed -i '' 's/8/88/' $testroot/wt
/numbers
439 echo "C numbers" > $testroot/stdout.expected
440 echo -n "Updated to refs/heads/master: $head_rev" \
441 >> $testroot/stdout.expected
442 echo >> $testroot/stdout.expected
443 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
445 (cd $testroot/wt
&& got update
> $testroot/stdout
)
447 cmp -s $testroot/stdout.expected
$testroot/stdout
449 if [ "$ret" != "0" ]; then
450 diff -u $testroot/stdout.expected
$testroot/stdout
451 test_done
"$testroot" "$ret"
455 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
456 echo -n 'blob - ' >> $testroot/stdout.expected
457 got tree
-r $testroot/repo
-i |
grep 'numbers$' | cut
-d' ' -f 1 \
458 >> $testroot/stdout.expected
459 echo 'file + numbers' >> $testroot/stdout.expected
460 echo '--- numbers' >> $testroot/stdout.expected
461 echo '+++ numbers' >> $testroot/stdout.expected
462 echo '@@ -1,8 +1,20 @@' >> $testroot/stdout.expected
463 echo ' 1' >> $testroot/stdout.expected
464 echo "+<<<<<<< merged change: commit $head_rev" \
465 >> $testroot/stdout.expected
466 echo ' 22' >> $testroot/stdout.expected
467 echo "+||||||| 3-way merge base: commit $base_commit" \
468 >> $testroot/stdout.expected
469 echo '+2' >> $testroot/stdout.expected
470 echo '+=======' >> $testroot/stdout.expected
471 echo '+77' >> $testroot/stdout.expected
472 echo '+>>>>>>>' >> $testroot/stdout.expected
473 echo ' 3' >> $testroot/stdout.expected
474 echo ' 4' >> $testroot/stdout.expected
475 echo ' 5' >> $testroot/stdout.expected
476 echo ' 6' >> $testroot/stdout.expected
477 echo ' 7' >> $testroot/stdout.expected
478 echo "+<<<<<<< merged change: commit $head_rev" \
479 >> $testroot/stdout.expected
480 echo ' 33' >> $testroot/stdout.expected
481 echo "+||||||| 3-way merge base: commit $base_commit" \
482 >> $testroot/stdout.expected
483 echo '+8' >> $testroot/stdout.expected
484 echo '+=======' >> $testroot/stdout.expected
485 echo '+88' >> $testroot/stdout.expected
486 echo '+>>>>>>>' >> $testroot/stdout.expected
488 (cd $testroot/wt
&& got
diff > $testroot/stdout
)
490 cmp -s $testroot/stdout.expected
$testroot/stdout
492 if [ "$ret" != "0" ]; then
493 diff -u $testroot/stdout.expected
$testroot/stdout
495 test_done
"$testroot" "$ret"
499 local testroot
=`test_init diff_tag`
500 local commit_id0
=`git_show_head $testroot/repo`
504 echo "modified alpha" > $testroot/repo
/alpha
505 git_commit
$testroot/repo
-m "changed alpha"
506 local commit_id1
=`git_show_head $testroot/repo`
508 (cd $testroot/repo
&& git tag
-m "test" $tag1)
510 echo "new file" > $testroot/repo
/new
511 (cd $testroot/repo
&& git add new
)
512 git_commit
$testroot/repo
-m "new file"
513 local commit_id2
=`git_show_head $testroot/repo`
515 (cd $testroot/repo
&& git tag
-m "test" $tag2)
517 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
518 echo -n 'blob - ' >> $testroot/stdout.expected
519 got tree
-r $testroot/repo
-c $commit_id0 -i |
grep 'alpha$' | \
520 cut
-d' ' -f 1 >> $testroot/stdout.expected
521 echo -n 'blob + ' >> $testroot/stdout.expected
522 got tree
-r $testroot/repo
-i |
grep 'alpha$' | cut
-d' ' -f 1 \
523 >> $testroot/stdout.expected
524 echo '--- alpha' >> $testroot/stdout.expected
525 echo '+++ alpha' >> $testroot/stdout.expected
526 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
527 echo '-alpha' >> $testroot/stdout.expected
528 echo '+modified alpha' >> $testroot/stdout.expected
530 got
diff -r $testroot/repo
$commit_id0 $tag1 > $testroot/stdout
531 cmp -s $testroot/stdout.expected
$testroot/stdout
533 if [ "$ret" != "0" ]; then
534 diff -u $testroot/stdout.expected
$testroot/stdout
535 test_done
"$testroot" "$ret"
539 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
540 echo "blob - /dev/null" >> $testroot/stdout.expected
541 echo -n 'blob + ' >> $testroot/stdout.expected
542 got tree
-r $testroot/repo
-i -c $commit_id2 |
grep 'new$' | \
543 cut
-d' ' -f 1 |
tr -d '\n' >> $testroot/stdout.expected
544 echo " (mode 644)" >> $testroot/stdout.expected
545 echo '--- /dev/null' >> $testroot/stdout.expected
546 echo '+++ new' >> $testroot/stdout.expected
547 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
548 echo '+new file' >> $testroot/stdout.expected
550 got
diff -r $testroot/repo
$tag1 $tag2 > $testroot/stdout
551 cmp -s $testroot/stdout.expected
$testroot/stdout
553 if [ "$ret" != "0" ]; then
554 diff -u $testroot/stdout.expected
$testroot/stdout
556 test_done
"$testroot" "$ret"
559 test_diff_lightweight_tag
() {
560 local testroot
=`test_init diff_tag`
561 local commit_id0
=`git_show_head $testroot/repo`
565 echo "modified alpha" > $testroot/repo
/alpha
566 git_commit
$testroot/repo
-m "changed alpha"
567 local commit_id1
=`git_show_head $testroot/repo`
569 (cd $testroot/repo
&& git tag
$tag1)
571 echo "new file" > $testroot/repo
/new
572 (cd $testroot/repo
&& git add new
)
573 git_commit
$testroot/repo
-m "new file"
574 local commit_id2
=`git_show_head $testroot/repo`
576 (cd $testroot/repo
&& git tag
$tag2)
578 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
579 echo -n 'blob - ' >> $testroot/stdout.expected
580 got tree
-r $testroot/repo
-c $commit_id0 -i |
grep 'alpha$' | \
581 cut
-d' ' -f 1 >> $testroot/stdout.expected
582 echo -n 'blob + ' >> $testroot/stdout.expected
583 got tree
-r $testroot/repo
-i |
grep 'alpha$' | cut
-d' ' -f 1 \
584 >> $testroot/stdout.expected
585 echo '--- alpha' >> $testroot/stdout.expected
586 echo '+++ alpha' >> $testroot/stdout.expected
587 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
588 echo '-alpha' >> $testroot/stdout.expected
589 echo '+modified alpha' >> $testroot/stdout.expected
591 got
diff -r $testroot/repo
$commit_id0 $tag1 > $testroot/stdout
592 cmp -s $testroot/stdout.expected
$testroot/stdout
594 if [ "$ret" != "0" ]; then
595 diff -u $testroot/stdout.expected
$testroot/stdout
596 test_done
"$testroot" "$ret"
600 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
601 echo "blob - /dev/null" >> $testroot/stdout.expected
602 echo -n 'blob + ' >> $testroot/stdout.expected
603 got tree
-r $testroot/repo
-i -c $commit_id2 |
grep 'new$' | \
604 cut
-d' ' -f 1 |
tr -d '\n' >> $testroot/stdout.expected
605 echo " (mode 644)" >> $testroot/stdout.expected
606 echo '--- /dev/null' >> $testroot/stdout.expected
607 echo '+++ new' >> $testroot/stdout.expected
608 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
609 echo '+new file' >> $testroot/stdout.expected
611 got
diff -r $testroot/repo
$tag1 $tag2 > $testroot/stdout
612 cmp -s $testroot/stdout.expected
$testroot/stdout
614 if [ "$ret" != "0" ]; then
615 diff -u $testroot/stdout.expected
$testroot/stdout
617 test_done
"$testroot" "$ret"
620 test_diff_ignore_whitespace
() {
621 local testroot
=`test_init diff_ignore_whitespace`
622 local commit_id0
=`git_show_head $testroot/repo`
624 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
626 if [ "$ret" != "0" ]; then
627 test_done
"$testroot" "$ret"
631 echo "alpha " > $testroot/wt
/alpha
633 (cd $testroot/wt
&& got
diff -w > $testroot/stdout
)
635 echo "diff $commit_id0 $testroot/wt" > $testroot/stdout.expected
636 echo -n 'blob - ' >> $testroot/stdout.expected
637 got tree
-r $testroot/repo
-c $commit_id0 -i |
grep 'alpha$' | \
638 cut
-d' ' -f 1 >> $testroot/stdout.expected
639 echo 'file + alpha' >> $testroot/stdout.expected
641 cmp -s $testroot/stdout.expected
$testroot/stdout
643 if [ "$ret" != "0" ]; then
644 diff -u $testroot/stdout.expected
$testroot/stdout
646 test_done
"$testroot" "$ret"
649 test_diff_submodule_of_same_repo
() {
650 local testroot
=`test_init diff_submodule_of_same_repo`
652 (cd $testroot && git clone
-q repo repo2
>/dev
/null
)
653 (cd $testroot/repo
&& git submodule
-q add ..
/repo2
)
654 (cd $testroot/repo
&& git commit
-q -m 'adding submodule')
656 epsilon_id
=$
(got tree
-r $testroot/repo
-i |
grep 'epsilon/$' | \
658 submodule_id
=$
(got tree
-r $testroot/repo
-i |
grep 'repo2\$$' | \
661 # Attempt a (nonsensical) diff between a tree object and a submodule.
662 # Currently fails with "wrong type of object" error
663 got
diff -r $testroot/repo
$epsilon_id $submodule_id \
664 > $testroot/stdout
2> $testroot/stderr
666 if [ "$ret" = "0" ]; then
667 echo "diff command succeeded unexpectedly" >&2
668 test_done
"$testroot" "1"
671 echo "got: wrong type of object" > $testroot/stderr.expected
673 cmp -s $testroot/stderr.expected
$testroot/stderr
675 if [ "$ret" != "0" ]; then
676 diff -u $testroot/stderr.expected
$testroot/stderr
679 test_done
"$testroot" "$ret"
682 test_diff_symlinks_in_work_tree
() {
683 local testroot
=`test_init diff_symlinks_in_work_tree`
685 (cd $testroot/repo
&& ln -s alpha alpha.link
)
686 (cd $testroot/repo
&& ln -s epsilon epsilon.link
)
687 (cd $testroot/repo
&& ln -s /etc
/passwd passwd.link
)
688 (cd $testroot/repo
&& ln -s ..
/beta epsilon
/beta.link
)
689 (cd $testroot/repo
&& ln -s nonexistent nonexistent.link
)
690 (cd $testroot/repo
&& ln -s .got
/foo dotgotfoo.link
)
691 (cd $testroot/repo
&& git add .
)
692 git_commit
$testroot/repo
-m "add symlinks"
693 local commit_id1
=`git_show_head $testroot/repo`
695 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
697 if [ "$ret" != "0" ]; then
698 test_done
"$testroot" "$ret"
702 (cd $testroot/wt
&& ln -sf beta alpha.link
)
703 (cd $testroot/wt
&& ln -sfT gamma epsilon.link
)
704 (cd $testroot/wt
&& ln -sf ..
/gamma
/delta epsilon
/beta.link
)
705 echo -n '.got/bar' > $testroot/wt
/dotgotfoo.link
706 (cd $testroot/wt
&& got
rm nonexistent.link
> /dev
/null
)
707 (cd $testroot/wt
&& ln -sf epsilon
/zeta zeta.link
)
708 (cd $testroot/wt
&& got add zeta.link
> /dev
/null
)
709 (cd $testroot/wt
&& got
diff > $testroot/stdout
)
711 echo "diff $commit_id1 $testroot/wt" > $testroot/stdout.expected
712 echo -n 'blob - ' >> $testroot/stdout.expected
713 got tree
-r $testroot/repo
-c $commit_id1 -i | \
714 grep 'alpha.link@ -> alpha$' | \
715 cut
-d' ' -f 1 >> $testroot/stdout.expected
716 echo 'file + alpha.link' >> $testroot/stdout.expected
717 echo '--- alpha.link' >> $testroot/stdout.expected
718 echo '+++ alpha.link' >> $testroot/stdout.expected
719 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
720 echo '-alpha' >> $testroot/stdout.expected
721 echo '\ No newline at end of file' >> $testroot/stdout.expected
722 echo '+beta' >> $testroot/stdout.expected
723 echo '\ No newline at end of file' >> $testroot/stdout.expected
724 echo -n 'blob - ' >> $testroot/stdout.expected
725 got tree
-r $testroot/repo
-c $commit_id1 -i | \
726 grep 'dotgotfoo.link@ -> .got/foo$' | \
727 cut
-d' ' -f 1 >> $testroot/stdout.expected
728 echo 'file + dotgotfoo.link' >> $testroot/stdout.expected
729 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
730 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
731 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
732 echo '-.got/foo' >> $testroot/stdout.expected
733 echo '\ No newline at end of file' >> $testroot/stdout.expected
734 echo '+.got/bar' >> $testroot/stdout.expected
735 echo '\ No newline at end of file' >> $testroot/stdout.expected
736 echo -n 'blob - ' >> $testroot/stdout.expected
737 got tree
-r $testroot/repo
-c $commit_id1 -i epsilon | \
738 grep 'beta.link@ -> ../beta$' | \
739 cut
-d' ' -f 1 >> $testroot/stdout.expected
740 echo 'file + epsilon/beta.link' >> $testroot/stdout.expected
741 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
742 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
743 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
744 echo '-../beta' >> $testroot/stdout.expected
745 echo '\ No newline at end of file' >> $testroot/stdout.expected
746 echo '+../gamma/delta' >> $testroot/stdout.expected
747 echo '\ No newline at end of file' >> $testroot/stdout.expected
748 echo -n 'blob - ' >> $testroot/stdout.expected
749 got tree
-r $testroot/repo
-c $commit_id1 -i | \
750 grep 'epsilon.link@ -> epsilon$' | \
751 cut
-d' ' -f 1 >> $testroot/stdout.expected
752 echo 'file + epsilon.link' >> $testroot/stdout.expected
753 echo '--- epsilon.link' >> $testroot/stdout.expected
754 echo '+++ epsilon.link' >> $testroot/stdout.expected
755 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
756 echo '-epsilon' >> $testroot/stdout.expected
757 echo '\ No newline at end of file' >> $testroot/stdout.expected
758 echo '+gamma' >> $testroot/stdout.expected
759 echo '\ No newline at end of file' >> $testroot/stdout.expected
760 echo -n 'blob - ' >> $testroot/stdout.expected
761 got tree
-r $testroot/repo
-c $commit_id1 -i | \
762 grep 'nonexistent.link@ -> nonexistent$' | \
763 cut
-d' ' -f 1 >> $testroot/stdout.expected
764 echo 'file + /dev/null' >> $testroot/stdout.expected
765 echo '--- nonexistent.link' >> $testroot/stdout.expected
766 echo '+++ /dev/null' >> $testroot/stdout.expected
767 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
768 echo '-nonexistent' >> $testroot/stdout.expected
769 echo '\ No newline at end of file' >> $testroot/stdout.expected
770 echo 'blob - /dev/null' >> $testroot/stdout.expected
771 echo 'file + zeta.link' >> $testroot/stdout.expected
772 echo '--- /dev/null' >> $testroot/stdout.expected
773 echo '+++ zeta.link' >> $testroot/stdout.expected
774 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
775 echo '+epsilon/zeta' >> $testroot/stdout.expected
776 echo '\ No newline at end of file' >> $testroot/stdout.expected
778 cmp -s $testroot/stdout.expected
$testroot/stdout
780 if [ "$ret" != "0" ]; then
781 diff -u $testroot/stdout.expected
$testroot/stdout
783 test_done
"$testroot" "$ret"
786 test_diff_symlinks_in_repo
() {
787 local testroot
=`test_init diff_symlinks_in_repo`
789 (cd $testroot/repo
&& ln -s alpha alpha.link
)
790 (cd $testroot/repo
&& ln -s epsilon epsilon.link
)
791 (cd $testroot/repo
&& ln -s /etc
/passwd passwd.link
)
792 (cd $testroot/repo
&& ln -s ..
/beta epsilon
/beta.link
)
793 (cd $testroot/repo
&& ln -s nonexistent nonexistent.link
)
794 (cd $testroot/repo
&& ln -s .got
/foo dotgotfoo.link
)
795 (cd $testroot/repo
&& git add .
)
796 git_commit
$testroot/repo
-m "add symlinks"
797 local commit_id1
=`git_show_head $testroot/repo`
799 (cd $testroot/repo
&& ln -sf beta alpha.link
)
800 (cd $testroot/repo
&& ln -sfT gamma epsilon.link
)
801 (cd $testroot/repo
&& ln -sf ..
/gamma
/delta epsilon
/beta.link
)
802 (cd $testroot/repo
&& ln -sf .got
/bar
$testroot/repo
/dotgotfoo.link
)
803 (cd $testroot/repo
&& git
rm -q nonexistent.link
)
804 (cd $testroot/repo
&& ln -sf epsilon
/zeta zeta.link
)
805 (cd $testroot/repo
&& git add .
)
806 git_commit
$testroot/repo
-m "change symlinks"
807 local commit_id2
=`git_show_head $testroot/repo`
809 got
diff -r $testroot/repo
$commit_id1 $commit_id2 > $testroot/stdout
811 echo "diff $commit_id1 $commit_id2" > $testroot/stdout.expected
812 echo -n 'blob - ' >> $testroot/stdout.expected
813 got tree
-r $testroot/repo
-c $commit_id1 -i | \
814 grep 'alpha.link@ -> alpha$' | \
815 cut
-d' ' -f 1 >> $testroot/stdout.expected
816 echo -n 'blob + ' >> $testroot/stdout.expected
817 got tree
-r $testroot/repo
-c $commit_id2 -i | \
818 grep 'alpha.link@ -> beta$' | \
819 cut
-d' ' -f 1 >> $testroot/stdout.expected
820 echo '--- alpha.link' >> $testroot/stdout.expected
821 echo '+++ alpha.link' >> $testroot/stdout.expected
822 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
823 echo '-alpha' >> $testroot/stdout.expected
824 echo '\ No newline at end of file' >> $testroot/stdout.expected
825 echo '+beta' >> $testroot/stdout.expected
826 echo '\ No newline at end of file' >> $testroot/stdout.expected
827 echo -n 'blob - ' >> $testroot/stdout.expected
828 got tree
-r $testroot/repo
-c $commit_id1 -i | \
829 grep 'dotgotfoo.link@ -> .got/foo$' | \
830 cut
-d' ' -f 1 >> $testroot/stdout.expected
831 echo -n 'blob + ' >> $testroot/stdout.expected
832 got tree
-r $testroot/repo
-c $commit_id2 -i | \
833 grep 'dotgotfoo.link@ -> .got/bar$' | \
834 cut
-d' ' -f 1 >> $testroot/stdout.expected
835 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
836 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
837 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
838 echo '-.got/foo' >> $testroot/stdout.expected
839 echo '\ No newline at end of file' >> $testroot/stdout.expected
840 echo '+.got/bar' >> $testroot/stdout.expected
841 echo '\ No newline at end of file' >> $testroot/stdout.expected
842 echo -n 'blob - ' >> $testroot/stdout.expected
843 got tree
-r $testroot/repo
-c $commit_id1 -i epsilon | \
844 grep 'beta.link@ -> ../beta$' | \
845 cut
-d' ' -f 1 >> $testroot/stdout.expected
846 echo -n 'blob + ' >> $testroot/stdout.expected
847 got tree
-r $testroot/repo
-c $commit_id2 -i epsilon | \
848 grep 'beta.link@ -> ../gamma/delta$' | \
849 cut
-d' ' -f 1 >> $testroot/stdout.expected
850 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
851 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
852 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
853 echo '-../beta' >> $testroot/stdout.expected
854 echo '\ No newline at end of file' >> $testroot/stdout.expected
855 echo '+../gamma/delta' >> $testroot/stdout.expected
856 echo '\ No newline at end of file' >> $testroot/stdout.expected
857 echo -n 'blob - ' >> $testroot/stdout.expected
858 got tree
-r $testroot/repo
-c $commit_id1 -i | \
859 grep 'epsilon.link@ -> epsilon$' | \
860 cut
-d' ' -f 1 >> $testroot/stdout.expected
861 echo -n 'blob + ' >> $testroot/stdout.expected
862 got tree
-r $testroot/repo
-c $commit_id2 -i | \
863 grep 'epsilon.link@ -> gamma$' | \
864 cut
-d' ' -f 1 >> $testroot/stdout.expected
865 echo '--- epsilon.link' >> $testroot/stdout.expected
866 echo '+++ epsilon.link' >> $testroot/stdout.expected
867 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
868 echo '-epsilon' >> $testroot/stdout.expected
869 echo '\ No newline at end of file' >> $testroot/stdout.expected
870 echo '+gamma' >> $testroot/stdout.expected
871 echo '\ No newline at end of file' >> $testroot/stdout.expected
872 echo -n 'blob - ' >> $testroot/stdout.expected
873 got tree
-r $testroot/repo
-c $commit_id1 -i | \
874 grep 'nonexistent.link@ -> nonexistent$' | \
875 cut
-d' ' -f 1 |
sed -e 's/$/ (mode 120000)/' \
876 >> $testroot/stdout.expected
877 echo 'blob + /dev/null' >> $testroot/stdout.expected
878 echo '--- nonexistent.link' >> $testroot/stdout.expected
879 echo '+++ /dev/null' >> $testroot/stdout.expected
880 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
881 echo '-nonexistent' >> $testroot/stdout.expected
882 echo '\ No newline at end of file' >> $testroot/stdout.expected
883 echo 'blob - /dev/null' >> $testroot/stdout.expected
884 echo -n 'blob + ' >> $testroot/stdout.expected
885 got tree
-r $testroot/repo
-c $commit_id2 -i | \
886 grep 'zeta.link@ -> epsilon/zeta$' | \
887 cut
-d' ' -f 1 |
sed -e 's/$/ (mode 120000)/' \
888 >> $testroot/stdout.expected
889 echo '--- /dev/null' >> $testroot/stdout.expected
890 echo '+++ zeta.link' >> $testroot/stdout.expected
891 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
892 echo '+epsilon/zeta' >> $testroot/stdout.expected
893 echo '\ No newline at end of file' >> $testroot/stdout.expected
895 cmp -s $testroot/stdout.expected
$testroot/stdout
897 if [ "$ret" != "0" ]; then
898 diff -u $testroot/stdout.expected
$testroot/stdout
900 test_done
"$testroot" "$ret"
903 test_diff_binary_files
() {
904 local testroot
=`test_init diff_binary_files`
905 local head_rev
=`git_show_head $testroot/repo`
907 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
909 if [ "$ret" != "0" ]; then
910 test_done
"$testroot" "$ret"
914 printf '\377\377\0\0\377\377\0\0' > $testroot/wt
/foo
915 (cd $testroot/wt
&& got add foo
>/dev
/null
)
917 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
918 echo 'blob - /dev/null' >> $testroot/stdout.expected
919 echo 'file + foo' >> $testroot/stdout.expected
920 echo "Binary files /dev/null and foo differ" \
921 >> $testroot/stdout.expected
923 (cd $testroot/wt
&& got
diff > $testroot/stdout
)
924 cmp -s $testroot/stdout.expected
$testroot/stdout
926 if [ "$ret" != "0" ]; then
927 diff -a -u $testroot/stdout.expected
$testroot/stdout
928 test_done
"$testroot" "$ret"
932 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
933 echo 'blob - /dev/null' >> $testroot/stdout.expected
934 echo 'file + foo' >> $testroot/stdout.expected
935 echo '--- /dev/null' >> $testroot/stdout.expected
936 echo '+++ foo' >> $testroot/stdout.expected
937 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
938 printf '+\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
939 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
941 (cd $testroot/wt
&& got
diff -a > $testroot/stdout
)
942 cmp -s $testroot/stdout.expected
$testroot/stdout
944 if [ "$ret" != "0" ]; then
945 diff -a -u $testroot/stdout.expected
$testroot/stdout
946 test_done
"$testroot" "$ret"
950 (cd $testroot/wt
&& got commit
-m 'add binary file' > /dev
/null
)
951 local head_rev
=`git_show_head $testroot/repo`
953 printf '\377\200\0\0\377\200\0\0' > $testroot/wt
/foo
955 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
956 echo -n 'blob - ' >> $testroot/stdout.expected
957 got tree
-r $testroot/repo
-i |
grep 'foo$' | cut
-d' ' -f 1 \
958 >> $testroot/stdout.expected
959 echo 'file + foo' >> $testroot/stdout.expected
960 echo '--- foo' >> $testroot/stdout.expected
961 echo '+++ foo' >> $testroot/stdout.expected
962 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
963 printf -- '-\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
964 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
965 printf '+\377\200\0\0\377\200\0\0\n' >> $testroot/stdout.expected
966 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
968 (cd $testroot/wt
&& got
diff -a > $testroot/stdout
)
969 cmp -s $testroot/stdout.expected
$testroot/stdout
971 if [ "$ret" != "0" ]; then
972 diff -a -u $testroot/stdout.expected
$testroot/stdout
974 test_done
"$testroot" "$ret"
978 run_test test_diff_basic
979 run_test test_diff_shows_conflict
980 run_test test_diff_tag
981 run_test test_diff_lightweight_tag
982 run_test test_diff_ignore_whitespace
983 run_test test_diff_submodule_of_same_repo
984 run_test test_diff_symlinks_in_work_tree
985 run_test test_diff_symlinks_in_repo
986 run_test test_diff_binary_files