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" != "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" != "0" ]; then
64 diff -u $testroot/stdout.expected $testroot/stdout
65 test_done "$testroot" "$ret"
66 return 1
67 fi
69 # diff non-existent path
70 (cd $testroot/wt && got diff nonexistent > $testroot/stdout \
71 2> $testroot/stderr)
73 echo -n > $testroot/stdout.expected
74 cmp -s $testroot/stdout.expected $testroot/stdout
75 ret="$?"
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 echo "got: nonexistent: No such file or directory" \
83 > $testroot/stderr.expected
84 cmp -s $testroot/stderr.expected $testroot/stderr
85 ret="$?"
86 if [ "$ret" != "0" ]; then
87 diff -u $testroot/stderr.expected $testroot/stderr
88 fi
89 test_done "$testroot" "$ret"
90 }
92 test_diff_shows_conflict() {
93 local testroot=`test_init diff_shows_conflict 1`
95 echo "1" > $testroot/repo/numbers
96 echo "2" >> $testroot/repo/numbers
97 echo "3" >> $testroot/repo/numbers
98 echo "4" >> $testroot/repo/numbers
99 echo "5" >> $testroot/repo/numbers
100 echo "6" >> $testroot/repo/numbers
101 echo "7" >> $testroot/repo/numbers
102 echo "8" >> $testroot/repo/numbers
103 (cd $testroot/repo && git add numbers)
104 git_commit $testroot/repo -m "added numbers file"
105 local base_commit=`git_show_head $testroot/repo`
107 got checkout $testroot/repo $testroot/wt > /dev/null
108 ret="$?"
109 if [ "$ret" != "0" ]; then
110 test_done "$testroot" "$ret"
111 return 1
112 fi
114 sed -i 's/2/22/' $testroot/repo/numbers
115 sed -i 's/8/33/' $testroot/repo/numbers
116 git_commit $testroot/repo -m "modified line 2"
117 local head_rev=`git_show_head $testroot/repo`
119 # modify lines 2 and 8 in conflicting ways
120 sed -i 's/2/77/' $testroot/wt/numbers
121 sed -i 's/8/88/' $testroot/wt/numbers
123 echo "C numbers" > $testroot/stdout.expected
124 echo -n "Updated to refs/heads/master: $head_rev" \
125 >> $testroot/stdout.expected
126 echo >> $testroot/stdout.expected
127 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
129 (cd $testroot/wt && got update > $testroot/stdout)
131 cmp -s $testroot/stdout.expected $testroot/stdout
132 ret="$?"
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/stdout.expected $testroot/stdout
135 test_done "$testroot" "$ret"
136 return 1
137 fi
139 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
140 echo -n 'blob - ' >> $testroot/stdout.expected
141 got tree -r $testroot/repo -i | grep 'numbers$' | cut -d' ' -f 1 \
142 >> $testroot/stdout.expected
143 echo 'file + numbers' >> $testroot/stdout.expected
144 echo '--- numbers' >> $testroot/stdout.expected
145 echo '+++ numbers' >> $testroot/stdout.expected
146 echo '@@ -1,8 +1,20 @@' >> $testroot/stdout.expected
147 echo ' 1' >> $testroot/stdout.expected
148 echo "+<<<<<<< merged change: commit $head_rev" \
149 >> $testroot/stdout.expected
150 echo ' 22' >> $testroot/stdout.expected
151 echo "+||||||| 3-way merge base: commit $base_commit" \
152 >> $testroot/stdout.expected
153 echo '+2' >> $testroot/stdout.expected
154 echo '+=======' >> $testroot/stdout.expected
155 echo '+77' >> $testroot/stdout.expected
156 echo '+>>>>>>>' >> $testroot/stdout.expected
157 echo ' 3' >> $testroot/stdout.expected
158 echo ' 4' >> $testroot/stdout.expected
159 echo ' 5' >> $testroot/stdout.expected
160 echo ' 6' >> $testroot/stdout.expected
161 echo ' 7' >> $testroot/stdout.expected
162 echo "+<<<<<<< merged change: commit $head_rev" \
163 >> $testroot/stdout.expected
164 echo ' 33' >> $testroot/stdout.expected
165 echo "+||||||| 3-way merge base: commit $base_commit" \
166 >> $testroot/stdout.expected
167 echo '+8' >> $testroot/stdout.expected
168 echo '+=======' >> $testroot/stdout.expected
169 echo '+88' >> $testroot/stdout.expected
170 echo '+>>>>>>>' >> $testroot/stdout.expected
172 (cd $testroot/wt && got diff > $testroot/stdout)
174 cmp -s $testroot/stdout.expected $testroot/stdout
175 ret="$?"
176 if [ "$ret" != "0" ]; then
177 diff -u $testroot/stdout.expected $testroot/stdout
178 fi
179 test_done "$testroot" "$ret"
182 test_diff_tag() {
183 local testroot=`test_init diff_tag`
184 local commit_id0=`git_show_head $testroot/repo`
185 local tag1=1.0.0
186 local tag2=2.0.0
188 echo "modified alpha" > $testroot/repo/alpha
189 git_commit $testroot/repo -m "changed alpha"
190 local commit_id1=`git_show_head $testroot/repo`
192 (cd $testroot/repo && git tag -m "test" $tag1)
194 echo "new file" > $testroot/repo/new
195 (cd $testroot/repo && git add new)
196 git_commit $testroot/repo -m "new file"
197 local commit_id2=`git_show_head $testroot/repo`
199 (cd $testroot/repo && git tag -m "test" $tag2)
201 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
202 echo -n 'blob - ' >> $testroot/stdout.expected
203 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
204 cut -d' ' -f 1 >> $testroot/stdout.expected
205 echo -n 'blob + ' >> $testroot/stdout.expected
206 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
207 >> $testroot/stdout.expected
208 echo '--- alpha' >> $testroot/stdout.expected
209 echo '+++ alpha' >> $testroot/stdout.expected
210 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
211 echo '-alpha' >> $testroot/stdout.expected
212 echo '+modified alpha' >> $testroot/stdout.expected
214 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
215 cmp -s $testroot/stdout.expected $testroot/stdout
216 ret="$?"
217 if [ "$ret" != "0" ]; then
218 diff -u $testroot/stdout.expected $testroot/stdout
219 test_done "$testroot" "$ret"
220 return 1
221 fi
223 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
224 echo "blob - /dev/null" >> $testroot/stdout.expected
225 echo -n 'blob + ' >> $testroot/stdout.expected
226 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
227 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
228 echo " (mode 644)" >> $testroot/stdout.expected
229 echo '--- /dev/null' >> $testroot/stdout.expected
230 echo '+++ new' >> $testroot/stdout.expected
231 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
232 echo '+new file' >> $testroot/stdout.expected
234 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
235 cmp -s $testroot/stdout.expected $testroot/stdout
236 ret="$?"
237 if [ "$ret" != "0" ]; then
238 diff -u $testroot/stdout.expected $testroot/stdout
239 fi
240 test_done "$testroot" "$ret"
243 test_diff_lightweight_tag() {
244 local testroot=`test_init diff_tag`
245 local commit_id0=`git_show_head $testroot/repo`
246 local tag1=1.0.0
247 local tag2=2.0.0
249 echo "modified alpha" > $testroot/repo/alpha
250 git_commit $testroot/repo -m "changed alpha"
251 local commit_id1=`git_show_head $testroot/repo`
253 (cd $testroot/repo && git tag $tag1)
255 echo "new file" > $testroot/repo/new
256 (cd $testroot/repo && git add new)
257 git_commit $testroot/repo -m "new file"
258 local commit_id2=`git_show_head $testroot/repo`
260 (cd $testroot/repo && git tag $tag2)
262 echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
263 echo -n 'blob - ' >> $testroot/stdout.expected
264 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
265 cut -d' ' -f 1 >> $testroot/stdout.expected
266 echo -n 'blob + ' >> $testroot/stdout.expected
267 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
268 >> $testroot/stdout.expected
269 echo '--- alpha' >> $testroot/stdout.expected
270 echo '+++ alpha' >> $testroot/stdout.expected
271 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
272 echo '-alpha' >> $testroot/stdout.expected
273 echo '+modified alpha' >> $testroot/stdout.expected
275 got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
276 cmp -s $testroot/stdout.expected $testroot/stdout
277 ret="$?"
278 if [ "$ret" != "0" ]; then
279 diff -u $testroot/stdout.expected $testroot/stdout
280 test_done "$testroot" "$ret"
281 return 1
282 fi
284 echo "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
285 echo "blob - /dev/null" >> $testroot/stdout.expected
286 echo -n 'blob + ' >> $testroot/stdout.expected
287 got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
288 cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
289 echo " (mode 644)" >> $testroot/stdout.expected
290 echo '--- /dev/null' >> $testroot/stdout.expected
291 echo '+++ new' >> $testroot/stdout.expected
292 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
293 echo '+new file' >> $testroot/stdout.expected
295 got diff -r $testroot/repo $tag1 $tag2 > $testroot/stdout
296 cmp -s $testroot/stdout.expected $testroot/stdout
297 ret="$?"
298 if [ "$ret" != "0" ]; then
299 diff -u $testroot/stdout.expected $testroot/stdout
300 fi
301 test_done "$testroot" "$ret"
304 test_diff_ignore_whitespace() {
305 local testroot=`test_init diff_ignore_whitespace`
306 local commit_id0=`git_show_head $testroot/repo`
308 got checkout $testroot/repo $testroot/wt > /dev/null
309 ret="$?"
310 if [ "$ret" != "0" ]; then
311 test_done "$testroot" "$ret"
312 return 1
313 fi
315 echo "alpha " > $testroot/wt/alpha
317 (cd $testroot/wt && got diff -w > $testroot/stdout)
319 echo "diff $commit_id0 $testroot/wt" > $testroot/stdout.expected
320 echo -n 'blob - ' >> $testroot/stdout.expected
321 got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
322 cut -d' ' -f 1 >> $testroot/stdout.expected
323 echo 'file + alpha' >> $testroot/stdout.expected
325 cmp -s $testroot/stdout.expected $testroot/stdout
326 ret="$?"
327 if [ "$ret" != "0" ]; then
328 diff -u $testroot/stdout.expected $testroot/stdout
329 fi
330 test_done "$testroot" "$ret"
333 test_diff_submodule_of_same_repo() {
334 local testroot=`test_init diff_submodule_of_same_repo`
336 (cd $testroot && git clone -q repo repo2 >/dev/null)
337 (cd $testroot/repo && git submodule -q add ../repo2)
338 (cd $testroot/repo && git commit -q -m 'adding submodule')
340 epsilon_id=$(got tree -r $testroot/repo -i | grep 'epsilon/$' | \
341 cut -d ' ' -f 1)
342 submodule_id=$(got tree -r $testroot/repo -i | grep 'repo2\$$' | \
343 cut -d ' ' -f 1)
345 # Attempt a (nonsensical) diff between a tree object and a submodule.
346 # Currently fails with "wrong type of object" error
347 got diff -r $testroot/repo $epsilon_id $submodule_id \
348 > $testroot/stdout 2> $testroot/stderr
349 ret="$?"
350 if [ "$ret" = "0" ]; then
351 echo "diff command succeeded unexpectedly" >&2
352 test_done "$testroot" "1"
353 return 1
354 fi
355 echo "got: wrong type of object" > $testroot/stderr.expected
357 cmp -s $testroot/stderr.expected $testroot/stderr
358 ret="$?"
359 if [ "$ret" != "0" ]; then
360 diff -u $testroot/stderr.expected $testroot/stderr
361 return 1
362 fi
363 test_done "$testroot" "$ret"
366 test_diff_symlinks_in_work_tree() {
367 local testroot=`test_init diff_symlinks_in_work_tree`
369 (cd $testroot/repo && ln -s alpha alpha.link)
370 (cd $testroot/repo && ln -s epsilon epsilon.link)
371 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
372 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
373 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
374 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
375 (cd $testroot/repo && git add .)
376 git_commit $testroot/repo -m "add symlinks"
377 local commit_id1=`git_show_head $testroot/repo`
379 got checkout $testroot/repo $testroot/wt > /dev/null
380 ret="$?"
381 if [ "$ret" != "0" ]; then
382 test_done "$testroot" "$ret"
383 return 1
384 fi
386 (cd $testroot/wt && ln -sf beta alpha.link)
387 (cd $testroot/wt && ln -sfT gamma epsilon.link)
388 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
389 echo -n '.got/bar' > $testroot/wt/dotgotfoo.link
390 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
391 (cd $testroot/wt && ln -sf epsilon/zeta zeta.link)
392 (cd $testroot/wt && got add zeta.link > /dev/null)
393 (cd $testroot/wt && got diff > $testroot/stdout)
395 echo "diff $commit_id1 $testroot/wt" > $testroot/stdout.expected
396 echo -n 'blob - ' >> $testroot/stdout.expected
397 got tree -r $testroot/repo -c $commit_id1 -i | \
398 grep 'alpha.link@ -> alpha$' | \
399 cut -d' ' -f 1 >> $testroot/stdout.expected
400 echo 'file + alpha.link' >> $testroot/stdout.expected
401 echo '--- alpha.link' >> $testroot/stdout.expected
402 echo '+++ alpha.link' >> $testroot/stdout.expected
403 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
404 echo '-alpha' >> $testroot/stdout.expected
405 echo '\ No newline at end of file' >> $testroot/stdout.expected
406 echo '+beta' >> $testroot/stdout.expected
407 echo '\ No newline at end of file' >> $testroot/stdout.expected
408 echo -n 'blob - ' >> $testroot/stdout.expected
409 got tree -r $testroot/repo -c $commit_id1 -i | \
410 grep 'dotgotfoo.link@ -> .got/foo$' | \
411 cut -d' ' -f 1 >> $testroot/stdout.expected
412 echo 'file + dotgotfoo.link' >> $testroot/stdout.expected
413 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
414 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
415 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
416 echo '-.got/foo' >> $testroot/stdout.expected
417 echo '\ No newline at end of file' >> $testroot/stdout.expected
418 echo '+.got/bar' >> $testroot/stdout.expected
419 echo '\ No newline at end of file' >> $testroot/stdout.expected
420 echo -n 'blob - ' >> $testroot/stdout.expected
421 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
422 grep 'beta.link@ -> ../beta$' | \
423 cut -d' ' -f 1 >> $testroot/stdout.expected
424 echo 'file + epsilon/beta.link' >> $testroot/stdout.expected
425 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
426 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
427 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
428 echo '-../beta' >> $testroot/stdout.expected
429 echo '\ No newline at end of file' >> $testroot/stdout.expected
430 echo '+../gamma/delta' >> $testroot/stdout.expected
431 echo '\ No newline at end of file' >> $testroot/stdout.expected
432 echo -n 'blob - ' >> $testroot/stdout.expected
433 got tree -r $testroot/repo -c $commit_id1 -i | \
434 grep 'epsilon.link@ -> epsilon$' | \
435 cut -d' ' -f 1 >> $testroot/stdout.expected
436 echo 'file + epsilon.link' >> $testroot/stdout.expected
437 echo '--- epsilon.link' >> $testroot/stdout.expected
438 echo '+++ epsilon.link' >> $testroot/stdout.expected
439 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
440 echo '-epsilon' >> $testroot/stdout.expected
441 echo '\ No newline at end of file' >> $testroot/stdout.expected
442 echo '+gamma' >> $testroot/stdout.expected
443 echo '\ No newline at end of file' >> $testroot/stdout.expected
444 echo -n 'blob - ' >> $testroot/stdout.expected
445 got tree -r $testroot/repo -c $commit_id1 -i | \
446 grep 'nonexistent.link@ -> nonexistent$' | \
447 cut -d' ' -f 1 >> $testroot/stdout.expected
448 echo 'file + /dev/null' >> $testroot/stdout.expected
449 echo '--- nonexistent.link' >> $testroot/stdout.expected
450 echo '+++ /dev/null' >> $testroot/stdout.expected
451 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
452 echo '-nonexistent' >> $testroot/stdout.expected
453 echo '\ No newline at end of file' >> $testroot/stdout.expected
454 echo 'blob - /dev/null' >> $testroot/stdout.expected
455 echo 'file + zeta.link' >> $testroot/stdout.expected
456 echo '--- /dev/null' >> $testroot/stdout.expected
457 echo '+++ zeta.link' >> $testroot/stdout.expected
458 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
459 echo '+epsilon/zeta' >> $testroot/stdout.expected
460 echo '\ No newline at end of file' >> $testroot/stdout.expected
462 cmp -s $testroot/stdout.expected $testroot/stdout
463 ret="$?"
464 if [ "$ret" != "0" ]; then
465 diff -u $testroot/stdout.expected $testroot/stdout
466 fi
467 test_done "$testroot" "$ret"
470 test_diff_symlinks_in_repo() {
471 local testroot=`test_init diff_symlinks_in_repo`
473 (cd $testroot/repo && ln -s alpha alpha.link)
474 (cd $testroot/repo && ln -s epsilon epsilon.link)
475 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
476 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
477 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
478 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
479 (cd $testroot/repo && git add .)
480 git_commit $testroot/repo -m "add symlinks"
481 local commit_id1=`git_show_head $testroot/repo`
483 (cd $testroot/repo && ln -sf beta alpha.link)
484 (cd $testroot/repo && ln -sfT gamma epsilon.link)
485 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
486 (cd $testroot/repo && ln -sf .got/bar $testroot/repo/dotgotfoo.link)
487 (cd $testroot/repo && git rm -q nonexistent.link)
488 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
489 (cd $testroot/repo && git add .)
490 git_commit $testroot/repo -m "change symlinks"
491 local commit_id2=`git_show_head $testroot/repo`
493 got diff -r $testroot/repo $commit_id1 $commit_id2 > $testroot/stdout
495 echo "diff $commit_id1 $commit_id2" > $testroot/stdout.expected
496 echo -n 'blob - ' >> $testroot/stdout.expected
497 got tree -r $testroot/repo -c $commit_id1 -i | \
498 grep 'alpha.link@ -> alpha$' | \
499 cut -d' ' -f 1 >> $testroot/stdout.expected
500 echo -n 'blob + ' >> $testroot/stdout.expected
501 got tree -r $testroot/repo -c $commit_id2 -i | \
502 grep 'alpha.link@ -> beta$' | \
503 cut -d' ' -f 1 >> $testroot/stdout.expected
504 echo '--- alpha.link' >> $testroot/stdout.expected
505 echo '+++ alpha.link' >> $testroot/stdout.expected
506 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
507 echo '-alpha' >> $testroot/stdout.expected
508 echo '\ No newline at end of file' >> $testroot/stdout.expected
509 echo '+beta' >> $testroot/stdout.expected
510 echo '\ No newline at end of file' >> $testroot/stdout.expected
511 echo -n 'blob - ' >> $testroot/stdout.expected
512 got tree -r $testroot/repo -c $commit_id1 -i | \
513 grep 'dotgotfoo.link@ -> .got/foo$' | \
514 cut -d' ' -f 1 >> $testroot/stdout.expected
515 echo -n 'blob + ' >> $testroot/stdout.expected
516 got tree -r $testroot/repo -c $commit_id2 -i | \
517 grep 'dotgotfoo.link@ -> .got/bar$' | \
518 cut -d' ' -f 1 >> $testroot/stdout.expected
519 echo '--- dotgotfoo.link' >> $testroot/stdout.expected
520 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
521 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
522 echo '-.got/foo' >> $testroot/stdout.expected
523 echo '\ No newline at end of file' >> $testroot/stdout.expected
524 echo '+.got/bar' >> $testroot/stdout.expected
525 echo '\ No newline at end of file' >> $testroot/stdout.expected
526 echo -n 'blob - ' >> $testroot/stdout.expected
527 got tree -r $testroot/repo -c $commit_id1 -i epsilon | \
528 grep 'beta.link@ -> ../beta$' | \
529 cut -d' ' -f 1 >> $testroot/stdout.expected
530 echo -n 'blob + ' >> $testroot/stdout.expected
531 got tree -r $testroot/repo -c $commit_id2 -i epsilon | \
532 grep 'beta.link@ -> ../gamma/delta$' | \
533 cut -d' ' -f 1 >> $testroot/stdout.expected
534 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
535 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
536 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
537 echo '-../beta' >> $testroot/stdout.expected
538 echo '\ No newline at end of file' >> $testroot/stdout.expected
539 echo '+../gamma/delta' >> $testroot/stdout.expected
540 echo '\ No newline at end of file' >> $testroot/stdout.expected
541 echo -n 'blob - ' >> $testroot/stdout.expected
542 got tree -r $testroot/repo -c $commit_id1 -i | \
543 grep 'epsilon.link@ -> epsilon$' | \
544 cut -d' ' -f 1 >> $testroot/stdout.expected
545 echo -n 'blob + ' >> $testroot/stdout.expected
546 got tree -r $testroot/repo -c $commit_id2 -i | \
547 grep 'epsilon.link@ -> gamma$' | \
548 cut -d' ' -f 1 >> $testroot/stdout.expected
549 echo '--- epsilon.link' >> $testroot/stdout.expected
550 echo '+++ epsilon.link' >> $testroot/stdout.expected
551 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
552 echo '-epsilon' >> $testroot/stdout.expected
553 echo '\ No newline at end of file' >> $testroot/stdout.expected
554 echo '+gamma' >> $testroot/stdout.expected
555 echo '\ No newline at end of file' >> $testroot/stdout.expected
556 echo -n 'blob - ' >> $testroot/stdout.expected
557 got tree -r $testroot/repo -c $commit_id1 -i | \
558 grep 'nonexistent.link@ -> nonexistent$' | \
559 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
560 >> $testroot/stdout.expected
561 echo 'blob + /dev/null' >> $testroot/stdout.expected
562 echo '--- nonexistent.link' >> $testroot/stdout.expected
563 echo '+++ /dev/null' >> $testroot/stdout.expected
564 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
565 echo '-nonexistent' >> $testroot/stdout.expected
566 echo '\ No newline at end of file' >> $testroot/stdout.expected
567 echo 'blob - /dev/null' >> $testroot/stdout.expected
568 echo -n 'blob + ' >> $testroot/stdout.expected
569 got tree -r $testroot/repo -c $commit_id2 -i | \
570 grep 'zeta.link@ -> epsilon/zeta$' | \
571 cut -d' ' -f 1 | sed -e 's/$/ (mode 120000)/' \
572 >> $testroot/stdout.expected
573 echo '--- /dev/null' >> $testroot/stdout.expected
574 echo '+++ zeta.link' >> $testroot/stdout.expected
575 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
576 echo '+epsilon/zeta' >> $testroot/stdout.expected
577 echo '\ No newline at end of file' >> $testroot/stdout.expected
579 cmp -s $testroot/stdout.expected $testroot/stdout
580 ret="$?"
581 if [ "$ret" != "0" ]; then
582 diff -u $testroot/stdout.expected $testroot/stdout
583 fi
584 test_done "$testroot" "$ret"
587 test_diff_binary_files() {
588 local testroot=`test_init diff_binary_files`
589 local head_rev=`git_show_head $testroot/repo`
591 got checkout $testroot/repo $testroot/wt > /dev/null
592 ret="$?"
593 if [ "$ret" != "0" ]; then
594 test_done "$testroot" "$ret"
595 return 1
596 fi
598 printf '\377\377\0\0\377\377\0\0' > $testroot/wt/foo
599 (cd $testroot/wt && got add foo >/dev/null)
601 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
602 echo 'blob - /dev/null' >> $testroot/stdout.expected
603 echo 'file + foo' >> $testroot/stdout.expected
604 echo "Binary files /dev/null and foo differ" \
605 >> $testroot/stdout.expected
607 (cd $testroot/wt && got diff > $testroot/stdout)
608 cmp -s $testroot/stdout.expected $testroot/stdout
609 ret="$?"
610 if [ "$ret" != "0" ]; then
611 diff -a -u $testroot/stdout.expected $testroot/stdout
612 test_done "$testroot" "$ret"
613 return 1
614 fi
616 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
617 echo 'blob - /dev/null' >> $testroot/stdout.expected
618 echo 'file + foo' >> $testroot/stdout.expected
619 echo '--- /dev/null' >> $testroot/stdout.expected
620 echo '+++ foo' >> $testroot/stdout.expected
621 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
622 printf '+\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
623 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
625 (cd $testroot/wt && got diff -a > $testroot/stdout)
626 cmp -s $testroot/stdout.expected $testroot/stdout
627 ret="$?"
628 if [ "$ret" != "0" ]; then
629 diff -a -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
631 return 1
632 fi
634 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
635 local head_rev=`git_show_head $testroot/repo`
637 printf '\377\200\0\0\377\200\0\0' > $testroot/wt/foo
639 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
640 echo -n 'blob - ' >> $testroot/stdout.expected
641 got tree -r $testroot/repo -i | grep 'foo$' | cut -d' ' -f 1 \
642 >> $testroot/stdout.expected
643 echo 'file + foo' >> $testroot/stdout.expected
644 echo '--- foo' >> $testroot/stdout.expected
645 echo '+++ foo' >> $testroot/stdout.expected
646 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
647 printf -- '-\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
648 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
649 printf '+\377\200\0\0\377\200\0\0\n' >> $testroot/stdout.expected
650 printf '\\ No newline at end of file\n' >> $testroot/stdout.expected
652 (cd $testroot/wt && got diff -a > $testroot/stdout)
653 cmp -s $testroot/stdout.expected $testroot/stdout
654 ret="$?"
655 if [ "$ret" != "0" ]; then
656 diff -a -u $testroot/stdout.expected $testroot/stdout
657 fi
658 test_done "$testroot" "$ret"
661 test_parseargs "$@"
662 run_test test_diff_basic
663 run_test test_diff_shows_conflict
664 run_test test_diff_tag
665 run_test test_diff_lightweight_tag
666 run_test test_diff_ignore_whitespace
667 run_test test_diff_submodule_of_same_repo
668 run_test test_diff_symlinks_in_work_tree
669 run_test test_diff_symlinks_in_repo
670 run_test test_diff_binary_files