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 # '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" != "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" != "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" != "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" != "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 '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
154 ret="$?"
155 if [ "$ret" != "0" ]; then
156 diff -u $testroot/stdout.expected $testroot/stdout
157 test_done "$testroot" "$ret"
158 return 1
159 fi
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)
166 ret="$?"
167 if [ "$ret" != "0" ]; then
168 echo "diff failed unexpectedly" >&2
169 test_done "$testroot" "1"
170 return 1
171 fi
172 cmp -s $testroot/stdout.expected $testroot/stdout
173 ret="$?"
174 if [ "$ret" != "0" ]; then
175 diff -u $testroot/stdout.expected $testroot/stdout
176 test_done "$testroot" "$ret"
177 return 1
178 fi
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)
216 ret="$?"
217 if [ "$ret" != "0" ]; then
218 echo "diff failed unexpectedly" >&2
219 test_done "$testroot" "1"
220 return 1
221 fi
222 cmp -s $testroot/stdout.expected $testroot/stdout
223 ret="$?"
224 if [ "$ret" != "0" ]; then
225 diff -u $testroot/stdout.expected $testroot/stdout
226 test_done "$testroot" "$ret"
227 return 1
228 fi
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)
234 ret="$?"
235 if [ "$ret" != "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 # diff between the branches is empty
242 cmp -s $testroot/stdout.expected $testroot/stdout
243 ret="$?"
244 if [ "$ret" != "0" ]; then
245 diff -u $testroot/stdout.expected $testroot/stdout
246 test_done "$testroot" "$ret"
247 return 1
248 fi
249 # same without a work tree
250 (cd $testroot/repo && got diff master new > $testroot/stdout)
251 ret="$?"
252 if [ "$ret" != "0" ]; then
253 echo "diff failed unexpectedly" >&2
254 test_done "$testroot" "1"
255 return 1
256 fi
257 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
258 cmp -s $testroot/stdout.expected $testroot/stdout
259 ret="$?"
260 if [ "$ret" != "0" ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
262 test_done "$testroot" "$ret"
263 return 1
264 fi
265 # same with -r argument
266 got diff -r $testroot/repo master new > $testroot/stdout
267 ret="$?"
268 if [ "$ret" != "0" ]; then
269 echo "diff failed unexpectedly" >&2
270 test_done "$testroot" "1"
271 return 1
272 fi
273 echo "diff refs/heads/master refs/heads/new" > $testroot/stdout.expected
274 cmp -s $testroot/stdout.expected $testroot/stdout
275 ret="$?"
276 if [ "$ret" != "0" ]; then
277 diff -u $testroot/stdout.expected $testroot/stdout
278 test_done "$testroot" "$ret"
279 return 1
280 fi
282 # -P can be used to force use of paths
283 (cd $testroot/wt && got diff -P new master > $testroot/stdout)
284 ret="$?"
285 if [ "$ret" != "0" ]; then
286 echo "diff failed unexpectedly" >&2
287 test_done "$testroot" "1"
288 return 1
289 fi
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
304 ret="$?"
305 if [ "$ret" != "0" ]; then
306 diff -u $testroot/stdout.expected $testroot/stdout
307 test_done "$testroot" "$ret"
308 return 1
309 fi
311 # -P can only be used in a work tree
312 got diff -r $testroot/repo -P new master 2> $testroot/stderr
313 ret="$?"
314 if [ "$ret" == "0" ]; then
315 echo "diff succeeded unexpectedly" >&2
316 test_done "$testroot" "1"
317 return 1
318 fi
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
322 ret="$?"
323 if [ "$ret" != "0" ]; then
324 diff -u $testroot/stderr.expected $testroot/stderr
325 test_done "$testroot" "$ret"
326 return 1
327 fi
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)
338 ret="$?"
339 if [ "$ret" != "0" ]; then
340 echo "diff failed unexpectedly" >&2
341 test_done "$testroot" "1"
342 return 1
343 fi
344 cmp -s $testroot/stdout.expected $testroot/stdout
345 ret="$?"
346 if [ "$ret" != "0" ]; then
347 diff -u $testroot/stdout.expected $testroot/stdout
348 test_done "$testroot" "$ret"
349 return 1
350 fi
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)
355 ret="$?"
356 if [ "$ret" = "0" ]; then
357 echo "diff succeeded unexpectedly" >&2
358 test_done "$testroot" "1"
359 return 1
360 fi
361 echo "got: $head_rev: No such file or directory" \
362 > $testroot/stderr.expected
363 cmp -s $testroot/stderr.expected $testroot/stderr
364 ret="$?"
365 if [ "$ret" != "0" ]; then
366 diff -u $testroot/stderr.expected $testroot/stderr
367 test_done "$testroot" "$ret"
368 return 1
369 fi
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)
375 ret="$?"
376 if [ "$ret" = "0" ]; then
377 echo "diff succeeded unexpectedly" >&2
378 test_done "$testroot" "1"
379 return 1
380 fi
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
390 ret="$?"
391 if [ "$ret" != "0" ]; then
392 diff -u $testroot/stdout.expected $testroot/stdout
393 test_done "$testroot" "$ret"
394 return 1
395 fi
397 echo "got: $head_rev: No such file or directory" \
398 > $testroot/stderr.expected
399 cmp -s $testroot/stderr.expected $testroot/stderr
400 ret="$?"
401 if [ "$ret" != "0" ]; then
402 diff -u $testroot/stderr.expected $testroot/stderr
403 return 1
404 fi
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
424 ret="$?"
425 if [ "$ret" != "0" ]; then
426 test_done "$testroot" "$ret"
427 return 1
428 fi
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
448 ret="$?"
449 if [ "$ret" != "0" ]; then
450 diff -u $testroot/stdout.expected $testroot/stdout
451 test_done "$testroot" "$ret"
452 return 1
453 fi
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
491 ret="$?"
492 if [ "$ret" != "0" ]; then
493 diff -u $testroot/stdout.expected $testroot/stdout
494 fi
495 test_done "$testroot" "$ret"
498 test_diff_tag() {
499 local testroot=`test_init diff_tag`
500 local commit_id0=`git_show_head $testroot/repo`
501 local tag1=1.0.0
502 local tag2=2.0.0
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
532 ret="$?"
533 if [ "$ret" != "0" ]; then
534 diff -u $testroot/stdout.expected $testroot/stdout
535 test_done "$testroot" "$ret"
536 return 1
537 fi
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
552 ret="$?"
553 if [ "$ret" != "0" ]; then
554 diff -u $testroot/stdout.expected $testroot/stdout
555 fi
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`
562 local tag1=1.0.0
563 local tag2=2.0.0
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
593 ret="$?"
594 if [ "$ret" != "0" ]; then
595 diff -u $testroot/stdout.expected $testroot/stdout
596 test_done "$testroot" "$ret"
597 return 1
598 fi
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
613 ret="$?"
614 if [ "$ret" != "0" ]; then
615 diff -u $testroot/stdout.expected $testroot/stdout
616 fi
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
625 ret="$?"
626 if [ "$ret" != "0" ]; then
627 test_done "$testroot" "$ret"
628 return 1
629 fi
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
642 ret="$?"
643 if [ "$ret" != "0" ]; then
644 diff -u $testroot/stdout.expected $testroot/stdout
645 fi
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/$' | \
657 cut -d ' ' -f 1)
658 submodule_id=$(got tree -r $testroot/repo -i | grep 'repo2\$$' | \
659 cut -d ' ' -f 1)
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
665 ret="$?"
666 if [ "$ret" = "0" ]; then
667 echo "diff command succeeded unexpectedly" >&2
668 test_done "$testroot" "1"
669 return 1
670 fi
671 echo "got: wrong type of object" > $testroot/stderr.expected
673 cmp -s $testroot/stderr.expected $testroot/stderr
674 ret="$?"
675 if [ "$ret" != "0" ]; then
676 diff -u $testroot/stderr.expected $testroot/stderr
677 return 1
678 fi
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
696 ret="$?"
697 if [ "$ret" != "0" ]; then
698 test_done "$testroot" "$ret"
699 return 1
700 fi
702 (cd $testroot/wt && ln -sf beta alpha.link)
703 (cd $testroot/wt && ln -sfh 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
779 ret="$?"
780 if [ "$ret" != "0" ]; then
781 diff -u $testroot/stdout.expected $testroot/stdout
782 fi
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 -sfh 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
896 ret="$?"
897 if [ "$ret" != "0" ]; then
898 diff -u $testroot/stdout.expected $testroot/stdout
899 fi
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
908 ret="$?"
909 if [ "$ret" != "0" ]; then
910 test_done "$testroot" "$ret"
911 return 1
912 fi
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
925 ret="$?"
926 if [ "$ret" != "0" ]; then
927 diff -a -u $testroot/stdout.expected $testroot/stdout
928 test_done "$testroot" "$ret"
929 return 1
930 fi
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
943 ret="$?"
944 if [ "$ret" != "0" ]; then
945 diff -a -u $testroot/stdout.expected $testroot/stdout
946 test_done "$testroot" "$ret"
947 return 1
948 fi
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
970 ret="$?"
971 if [ "$ret" != "0" ]; then
972 diff -a -u $testroot/stdout.expected $testroot/stdout
973 fi
974 test_done "$testroot" "$ret"
977 test_diff_commits() {
978 local testroot=`test_init diff_commits`
979 local commit_id0=`git_show_head $testroot/repo`
980 alpha_id0=`get_blob_id $testroot/repo "" alpha`
981 beta_id0=`get_blob_id $testroot/repo "" beta`
983 got checkout $testroot/repo $testroot/wt > /dev/null
984 ret="$?"
985 if [ "$ret" != "0" ]; then
986 test_done "$testroot" "$ret"
987 return 1
988 fi
990 echo "modified alpha" > $testroot/wt/alpha
991 (cd $testroot/wt && got rm beta >/dev/null)
992 echo "new file" > $testroot/wt/new
993 (cd $testroot/wt && got add new >/dev/null)
994 (cd $testroot/wt && got commit -m 'committing changes' >/dev/null)
995 local commit_id1=`git_show_head $testroot/repo`
997 alpha_id1=`get_blob_id $testroot/repo "" alpha`
998 new_id1=`get_blob_id $testroot/repo "" new`
1000 echo "diff $commit_id0 refs/heads/master" > $testroot/stdout.expected
1001 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1002 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1003 echo '--- alpha' >> $testroot/stdout.expected
1004 echo '+++ alpha' >> $testroot/stdout.expected
1005 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1006 echo '-alpha' >> $testroot/stdout.expected
1007 echo '+modified alpha' >> $testroot/stdout.expected
1008 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1009 echo 'blob + /dev/null' >> $testroot/stdout.expected
1010 echo '--- beta' >> $testroot/stdout.expected
1011 echo '+++ /dev/null' >> $testroot/stdout.expected
1012 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1013 echo '-beta' >> $testroot/stdout.expected
1014 echo 'blob - /dev/null' >> $testroot/stdout.expected
1015 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1016 echo '--- /dev/null' >> $testroot/stdout.expected
1017 echo '+++ new' >> $testroot/stdout.expected
1018 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1019 echo '+new file' >> $testroot/stdout.expected
1021 (cd $testroot/wt && got diff -c master > $testroot/stdout)
1022 cmp -s $testroot/stdout.expected $testroot/stdout
1023 ret="$?"
1024 if [ "$ret" != "0" ]; then
1025 diff -u $testroot/stdout.expected $testroot/stdout
1026 test_done "$testroot" "$ret"
1027 return 1
1030 # same diff with explicit parent commit ID
1031 (cd $testroot/wt && got diff -c $commit_id0 -c master \
1032 > $testroot/stdout)
1033 cmp -s $testroot/stdout.expected $testroot/stdout
1034 ret="$?"
1035 if [ "$ret" != "0" ]; then
1036 diff -u $testroot/stdout.expected $testroot/stdout
1037 test_done "$testroot" "$ret"
1038 return 1
1041 # same diff with commit object IDs
1042 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1043 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1044 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1045 echo '--- alpha' >> $testroot/stdout.expected
1046 echo '+++ alpha' >> $testroot/stdout.expected
1047 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1048 echo '-alpha' >> $testroot/stdout.expected
1049 echo '+modified alpha' >> $testroot/stdout.expected
1050 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1051 echo 'blob + /dev/null' >> $testroot/stdout.expected
1052 echo '--- beta' >> $testroot/stdout.expected
1053 echo '+++ /dev/null' >> $testroot/stdout.expected
1054 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1055 echo '-beta' >> $testroot/stdout.expected
1056 echo 'blob - /dev/null' >> $testroot/stdout.expected
1057 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1058 echo '--- /dev/null' >> $testroot/stdout.expected
1059 echo '+++ new' >> $testroot/stdout.expected
1060 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1061 echo '+new file' >> $testroot/stdout.expected
1062 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 \
1063 > $testroot/stdout)
1064 cmp -s $testroot/stdout.expected $testroot/stdout
1065 ret="$?"
1066 if [ "$ret" != "0" ]; then
1067 diff -u $testroot/stdout.expected $testroot/stdout
1068 test_done "$testroot" "$ret"
1069 return 1
1072 # same diff, filtered by paths
1073 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1074 echo "blob - $alpha_id0" >> $testroot/stdout.expected
1075 echo "blob + $alpha_id1" >> $testroot/stdout.expected
1076 echo '--- alpha' >> $testroot/stdout.expected
1077 echo '+++ alpha' >> $testroot/stdout.expected
1078 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1079 echo '-alpha' >> $testroot/stdout.expected
1080 echo '+modified alpha' >> $testroot/stdout.expected
1081 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 alpha \
1082 > $testroot/stdout)
1083 cmp -s $testroot/stdout.expected $testroot/stdout
1084 ret="$?"
1085 if [ "$ret" != "0" ]; then
1086 diff -u $testroot/stdout.expected $testroot/stdout
1087 test_done "$testroot" "$ret"
1088 return 1
1090 # same in a work tree
1091 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 alpha \
1092 > $testroot/stdout)
1093 cmp -s $testroot/stdout.expected $testroot/stdout
1094 ret="$?"
1095 if [ "$ret" != "0" ]; then
1096 diff -u $testroot/stdout.expected $testroot/stdout
1097 test_done "$testroot" "$ret"
1098 return 1
1101 echo "diff $commit_id0 $commit_id1" > $testroot/stdout.expected
1102 echo "blob - $beta_id0 (mode 644)" >> $testroot/stdout.expected
1103 echo 'blob + /dev/null' >> $testroot/stdout.expected
1104 echo '--- beta' >> $testroot/stdout.expected
1105 echo '+++ /dev/null' >> $testroot/stdout.expected
1106 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1107 echo '-beta' >> $testroot/stdout.expected
1108 echo 'blob - /dev/null' >> $testroot/stdout.expected
1109 echo "blob + $new_id1 (mode 644)" >> $testroot/stdout.expected
1110 echo '--- /dev/null' >> $testroot/stdout.expected
1111 echo '+++ new' >> $testroot/stdout.expected
1112 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1113 echo '+new file' >> $testroot/stdout.expected
1114 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 \
1115 beta new > $testroot/stdout)
1116 cmp -s $testroot/stdout.expected $testroot/stdout
1117 ret="$?"
1118 if [ "$ret" != "0" ]; then
1119 diff -u $testroot/stdout.expected $testroot/stdout
1120 test_done "$testroot" "$ret"
1121 return 1
1124 # more than two -c options are not allowed
1125 (cd $testroot/repo && got diff -c $commit_id0 -c $commit_id1 -c foo \
1126 2> $testroot/stderr)
1127 ret="$?"
1128 if [ "$ret" == "0" ]; then
1129 echo "diff succeeded unexpectedly" >&2
1130 test_done "$testroot" "1"
1131 return 1
1133 echo "got: too many -c options used" > $testroot/stderr.expected
1134 cmp -s $testroot/stderr.expected $testroot/stderr
1135 ret="$?"
1136 if [ "$ret" != "0" ]; then
1137 diff -u $testroot/stderr.expected $testroot/stderr
1138 test_done "$testroot" "$ret"
1139 return 1
1142 # use of -c options implies a repository diff; use with -P is an error
1143 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -P foo \
1144 2> $testroot/stderr)
1145 ret="$?"
1146 if [ "$ret" == "0" ]; then
1147 echo "diff succeeded unexpectedly" >&2
1148 test_done "$testroot" "1"
1149 return 1
1151 echo "got: -P option can only be used when diffing a work tree" \
1152 > $testroot/stderr.expected
1153 cmp -s $testroot/stderr.expected $testroot/stderr
1154 ret="$?"
1155 if [ "$ret" != "0" ]; then
1156 diff -u $testroot/stderr.expected $testroot/stderr
1157 test_done "$testroot" "$ret"
1158 return 1
1161 # use of -c options implies a repository diff; use with -s is an error
1162 (cd $testroot/wt && got diff -c $commit_id0 -c $commit_id1 -s foo \
1163 2> $testroot/stderr)
1164 ret="$?"
1165 if [ "$ret" == "0" ]; then
1166 echo "diff succeeded unexpectedly" >&2
1167 test_done "$testroot" "1"
1168 return 1
1170 echo "got: -s option can only be used when diffing a work tree" \
1171 > $testroot/stderr.expected
1172 cmp -s $testroot/stderr.expected $testroot/stderr
1173 ret="$?"
1174 if [ "$ret" != "0" ]; then
1175 diff -u $testroot/stderr.expected $testroot/stderr
1176 test_done "$testroot" "$ret"
1177 return 1
1180 # three arguments imply use of path filtering (repository case)
1181 (cd $testroot/repo && got diff $commit_id0 $commit_id1 foo \
1182 2> $testroot/stderr)
1183 ret="$?"
1184 if [ "$ret" == "0" ]; then
1185 echo "diff succeeded unexpectedly" >&2
1186 test_done "$testroot" "1"
1187 return 1
1189 echo "got: specified paths cannot be resolved: no got work tree found" \
1190 > $testroot/stderr.expected
1191 cmp -s $testroot/stderr.expected $testroot/stderr
1192 ret="$?"
1193 if [ "$ret" != "0" ]; then
1194 diff -u $testroot/stderr.expected $testroot/stderr
1195 test_done "$testroot" "$ret"
1196 return 1
1199 # three arguments imply use of path filtering (work tree case)
1200 (cd $testroot/wt && got diff $commit_id0 $commit_id1 foo \
1201 2> $testroot/stderr)
1202 ret="$?"
1203 if [ "$ret" == "0" ]; then
1204 echo "diff succeeded unexpectedly" >&2
1205 test_done "$testroot" "1"
1206 return 1
1208 echo "got: $commit_id0: No such file or directory" \
1209 > $testroot/stderr.expected
1210 cmp -s $testroot/stderr.expected $testroot/stderr
1211 ret="$?"
1212 if [ "$ret" != "0" ]; then
1213 diff -u $testroot/stderr.expected $testroot/stderr
1215 test_done "$testroot" "$ret"
1218 test_parseargs "$@"
1219 run_test test_diff_basic
1220 run_test test_diff_shows_conflict
1221 run_test test_diff_tag
1222 run_test test_diff_lightweight_tag
1223 run_test test_diff_ignore_whitespace
1224 run_test test_diff_submodule_of_same_repo
1225 run_test test_diff_symlinks_in_work_tree
1226 run_test test_diff_symlinks_in_repo
1227 run_test test_diff_binary_files
1228 run_test test_diff_commits