Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019, 2020 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_log_in_repo() {
20 local testroot=`test_init log_in_repo`
21 local head_rev=`git_show_head $testroot/repo`
23 echo "commit $head_rev (master)" > $testroot/stdout.expected
25 for p in "" "." alpha epsilon epsilon/zeta; do
26 (cd $testroot/repo && got log $p | \
27 grep ^commit > $testroot/stdout)
28 cmp -s $testroot/stdout.expected $testroot/stdout
29 ret=$?
30 if [ $ret -ne 0 ]; then
31 diff -u $testroot/stdout.expected $testroot/stdout
32 test_done "$testroot" "$ret"
33 return 1
34 fi
35 done
37 for p in "" "." zeta; do
38 (cd $testroot/repo/epsilon && got log $p | \
39 grep ^commit > $testroot/stdout)
40 cmp -s $testroot/stdout.expected $testroot/stdout
41 ret=$?
42 if [ $ret -ne 0 ]; then
43 diff -u $testroot/stdout.expected $testroot/stdout
44 test_done "$testroot" "$ret"
45 return 1
46 fi
47 done
49 test_done "$testroot" "0"
50 }
52 test_log_in_bare_repo() {
53 local testroot=`test_init log_in_bare_repo`
54 local head_rev=`git_show_head $testroot/repo`
56 echo "commit $head_rev (master)" > $testroot/stdout.expected
58 for p in "" "." alpha epsilon epsilon/zeta; do
59 (cd $testroot/repo/.git && got log $p | \
60 grep ^commit > $testroot/stdout)
61 cmp -s $testroot/stdout.expected $testroot/stdout
62 ret=$?
63 if [ $ret -ne 0 ]; then
64 diff -u $testroot/stdout.expected $testroot/stdout
65 test_done "$testroot" "$ret"
66 return 1
67 fi
68 done
70 test_done "$testroot" "0"
71 }
73 test_log_in_worktree() {
74 local testroot=`test_init log_in_worktree 1`
76 make_test_tree $testroot/repo
77 mkdir -p $testroot/repo/epsilon/d
78 echo foo > $testroot/repo/epsilon/d/foo
79 (cd $testroot/repo && git add .)
80 git_commit $testroot/repo -m "adding the test tree"
81 local head_commit=`git_show_head $testroot/repo`
83 got checkout $testroot/repo $testroot/wt > /dev/null
84 ret=$?
85 if [ $ret -ne 0 ]; then
86 test_done "$testroot" "$ret"
87 return 1
88 fi
90 echo "commit $head_commit (master)" > $testroot/stdout.expected
92 for p in "" "." alpha epsilon; do
93 (cd $testroot/wt && got log $p | \
94 grep ^commit > $testroot/stdout)
95 cmp -s $testroot/stdout.expected $testroot/stdout
96 ret=$?
97 if [ $ret -ne 0 ]; then
98 diff -u $testroot/stdout.expected $testroot/stdout
99 test_done "$testroot" "$ret"
100 return 1
101 fi
102 done
104 for p in "" "." zeta; do
105 (cd $testroot/wt/epsilon && got log $p | \
106 grep ^commit > $testroot/stdout)
107 cmp -s $testroot/stdout.expected $testroot/stdout
108 ret=$?
109 if [ $ret -ne 0 ]; then
110 diff -u $testroot/stdout.expected $testroot/stdout
111 test_done "$testroot" "$ret"
112 return 1
113 fi
114 done
116 for p in "" "." foo; do
117 (cd $testroot/wt/epsilon && got log d/$p | \
118 grep ^commit > $testroot/stdout)
119 cmp -s $testroot/stdout.expected $testroot/stdout
120 ret=$?
121 if [ $ret -ne 0 ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 test_done "$testroot" "$ret"
124 return 1
125 fi
126 done
128 test_done "$testroot" "0"
131 test_log_in_worktree_with_path_prefix() {
132 local testroot=`test_init log_in_worktree_with_path_prefix`
133 local head_rev=`git_show_head $testroot/repo`
135 echo "modified zeta" > $testroot/repo/epsilon/zeta
136 git_commit $testroot/repo -m "modified zeta"
137 local zeta_rev=`git_show_head $testroot/repo`
139 echo "modified delta" > $testroot/repo/gamma/delta
140 git_commit $testroot/repo -m "modified delta"
141 local delta_rev=`git_show_head $testroot/repo`
143 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
144 ret=$?
145 if [ $ret -ne 0 ]; then
146 test_done "$testroot" "$ret"
147 return 1
148 fi
150 echo "commit $delta_rev (master)" > $testroot/stdout.expected
151 echo "commit $zeta_rev" >> $testroot/stdout.expected
152 echo "commit $head_rev" >> $testroot/stdout.expected
154 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
155 cmp -s $testroot/stdout.expected $testroot/stdout
156 ret=$?
157 if [ $ret -ne 0 ]; then
158 diff -u $testroot/stdout.expected $testroot/stdout
159 test_done "$testroot" "$ret"
160 return 1
161 fi
163 echo "commit $zeta_rev" > $testroot/stdout.expected
164 echo "commit $head_rev" >> $testroot/stdout.expected
166 for p in "." zeta; do
167 (cd $testroot/wt && got log $p | \
168 grep ^commit > $testroot/stdout)
169 cmp -s $testroot/stdout.expected $testroot/stdout
170 ret=$?
171 if [ $ret -ne 0 ]; then
172 diff -u $testroot/stdout.expected $testroot/stdout
173 test_done "$testroot" "$ret"
174 return 1
175 fi
176 done
178 test_done "$testroot" "0"
181 test_log_tag() {
182 local testroot=`test_init log_tag`
183 local commit_id=`git_show_head $testroot/repo`
184 local tag="1.0.0"
185 local tag2="2.0.0"
187 got checkout $testroot/repo $testroot/wt > /dev/null
188 ret=$?
189 if [ $ret -ne 0 ]; then
190 test_done "$testroot" "$ret"
191 return 1
192 fi
194 (cd $testroot/repo && git tag -a -m "test" $tag)
196 echo "commit $commit_id (master, tags/$tag)" > $testroot/stdout.expected
197 (cd $testroot/wt && got log -l1 -c $tag | grep ^commit \
198 > $testroot/stdout)
199 cmp -s $testroot/stdout.expected $testroot/stdout
200 ret=$?
201 if [ $ret -ne 0 ]; then
202 diff -u $testroot/stdout.expected $testroot/stdout
203 test_done "$testroot" "$ret"
204 return 1
205 fi
207 # test a "lightweight" tag
208 (cd $testroot/repo && git tag $tag2)
210 echo "commit $commit_id (master, tags/$tag, tags/$tag2)" \
211 > $testroot/stdout.expected
212 (cd $testroot/wt && got log -l1 -c $tag2 | grep ^commit \
213 > $testroot/stdout)
214 cmp -s $testroot/stdout.expected $testroot/stdout
215 ret=$?
216 if [ $ret -ne 0 ]; then
217 diff -u $testroot/stdout.expected $testroot/stdout
218 fi
219 test_done "$testroot" "$ret"
222 test_log_limit() {
223 local testroot=`test_init log_limit`
224 local commit_id0=`git_show_head $testroot/repo`
226 got checkout $testroot/repo $testroot/wt > /dev/null
227 ret=$?
228 if [ $ret -ne 0 ]; then
229 test_done "$testroot" "$ret"
230 return 1
231 fi
233 echo "modified alpha" > $testroot/wt/alpha
234 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
235 local commit_id1=`git_show_head $testroot/repo`
237 (cd $testroot/wt && got rm beta >/dev/null)
238 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
239 local commit_id2=`git_show_head $testroot/repo`
241 echo "new file" > $testroot/wt/new
242 (cd $testroot/wt && got add new >/dev/null)
243 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
244 local commit_id3=`git_show_head $testroot/repo`
246 # -l1 should print the first commit only
247 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
248 (cd $testroot/wt && got log -l1 | grep ^commit > $testroot/stdout)
249 cmp -s $testroot/stdout.expected $testroot/stdout
250 ret=$?
251 if [ $ret -ne 0 ]; then
252 diff -u $testroot/stdout.expected $testroot/stdout
253 test_done "$testroot" "$ret"
254 return 1
255 fi
257 # env var can be used to set a log limit without -l option
258 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
259 echo "commit $commit_id2" >> $testroot/stdout.expected
260 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=2 got log | \
261 grep ^commit > $testroot/stdout)
262 cmp -s $testroot/stdout.expected $testroot/stdout
263 ret=$?
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 # non-numeric env var is ignored
271 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=foobar got log | \
272 grep ^commit > $testroot/stdout)
273 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
274 echo "commit $commit_id2" >> $testroot/stdout.expected
275 echo "commit $commit_id1" >> $testroot/stdout.expected
276 echo "commit $commit_id0" >> $testroot/stdout.expected
277 cmp -s $testroot/stdout.expected $testroot/stdout
278 ret=$?
279 if [ $ret -ne 0 ]; then
280 diff -u $testroot/stdout.expected $testroot/stdout
281 test_done "$testroot" "$ret"
282 return 1
283 fi
285 # -l option takes precedence over env var
286 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
287 echo "commit $commit_id2" >> $testroot/stdout.expected
288 echo "commit $commit_id1" >> $testroot/stdout.expected
289 echo "commit $commit_id0" >> $testroot/stdout.expected
290 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=1 got log -l0 | \
291 grep ^commit > $testroot/stdout)
292 cmp -s $testroot/stdout.expected $testroot/stdout
293 ret=$?
294 if [ $ret -ne 0 ]; then
295 diff -u $testroot/stdout.expected $testroot/stdout
296 fi
297 test_done "$testroot" "0"
300 test_log_oneline() {
301 local testroot=`test_init log_oneline`
302 local commit_id0=`git_show_head $testroot/repo`
303 got checkout $testroot/repo $testroot/wt > /dev/null
304 ret=$?
305 if [ $ret -ne 0 ]; then
306 test_done "$testroot" "$ret"
307 return 1
308 fi
310 echo "modified alpha" > $testroot/wt/alpha
311 (cd $testroot/wt && got commit -m "test oneline
312 no" > /dev/null)
313 local commit_id1=`git_show_head $testroot/repo`
314 local author_time1=`git_show_author_time $testroot/repo`
316 echo "modified beta" > $testroot/wt/beta
317 (cd $testroot/wt && got commit -m " test oneline
318 no" > /dev/null)
319 local commit_id2=`git_show_head $testroot/repo`
320 local author_time2=`git_show_author_time $testroot/repo`
322 d=`date -u -r $author_time1 +"%G-%m-%d"`
323 printf "$d %-7s test oneline\n" master > $testroot/stdout.expected
324 d=`date -u -r $author_time2 +"%G-%m-%d"`
325 printf "$d %.7s test oneline\n" $commit_id1 >> $testroot/stdout.expected
327 (cd $testroot/repo && got log -s | head -n 2 > $testroot/stdout)
328 cmp -s $testroot/stdout.expected $testroot/stdout
329 ret=$?
330 if [ $ret -ne 0 ]; then
331 diff -u $testroot/stdout.expected $testroot/stdout
332 test_done "$testroot" "$ret"
333 return 1
334 fi
335 test_done "$testroot" "0"
338 test_log_patch_added_file() {
339 local testroot=`test_init log_patch_added_file`
340 local commit_id0=`git_show_head $testroot/repo`
342 got checkout $testroot/repo $testroot/wt > /dev/null
343 ret=$?
344 if [ $ret -ne 0 ]; then
345 test_done "$testroot" "$ret"
346 return 1
347 fi
349 echo "new file" > $testroot/wt/new
350 (cd $testroot/wt && got add new >/dev/null)
351 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
352 local commit_id1=`git_show_head $testroot/repo`
354 echo "commit $commit_id1 (master)" > $testroot/stdout.expected
355 echo "commit - $commit_id0" >> $testroot/stdout.expected
356 echo "commit + $commit_id1" >> $testroot/stdout.expected
357 # This used to fail with 'got: no such entry found in tree'
358 (cd $testroot/wt && got log -l1 -p new > $testroot/stdout.patch)
359 ret=$?
360 if [ $ret -ne 0 ]; then
361 echo "got log command failed unexpectedly" >&2
362 test_done "$testroot" "$ret"
363 return 1
364 fi
365 grep ^commit $testroot/stdout.patch > $testroot/stdout
366 cmp -s $testroot/stdout.expected $testroot/stdout
367 ret=$?
368 if [ $ret -ne 0 ]; then
369 diff -u $testroot/stdout.expected $testroot/stdout
370 fi
371 test_done "$testroot" "$ret"
374 test_log_nonexistent_path() {
375 local testroot=`test_init log_nonexistent_path`
376 local head_rev=`git_show_head $testroot/repo`
378 echo "commit $head_rev (master)" > $testroot/stdout.expected
380 (cd $testroot/repo && got log this/does/not/exist \
381 > $testroot/stdout 2> $testroot/stderr)
382 ret=$?
383 if [ $ret -eq 0 ]; then
384 echo "log command succeeded unexpectedly" >&2
385 test_done "$testroot" "1"
386 return 1
387 fi
389 echo -n > $testroot/stdout.expected
390 cmp -s $testroot/stdout.expected $testroot/stdout
391 ret=$?
392 if [ $ret -ne 0 ]; then
393 diff -u $testroot/stdout.expected $testroot/stdout
394 test_done "$testroot" "$ret"
395 return 1
396 fi
398 echo "got: this/does/not/exist: no such entry found in tree" \
399 > $testroot/stderr.expected
400 cmp -s $testroot/stderr.expected $testroot/stderr
401 ret=$?
402 if [ $ret -ne 0 ]; then
403 diff -u $testroot/stderr.expected $testroot/stderr
404 fi
405 test_done "$testroot" "$ret"
408 test_log_end_at_commit() {
409 local testroot=`test_init log_end_at_commit`
410 local commit_id0=`git_show_head $testroot/repo`
412 got checkout $testroot/repo $testroot/wt > /dev/null
413 ret=$?
414 if [ $ret -ne 0 ]; then
415 test_done "$testroot" "$ret"
416 return 1
417 fi
419 echo "modified alpha" > $testroot/wt/alpha
420 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
421 local commit_id1=`git_show_head $testroot/repo`
423 (cd $testroot/wt && got rm beta >/dev/null)
424 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
425 local commit_id2=`git_show_head $testroot/repo`
427 echo "new file" > $testroot/wt/new
428 (cd $testroot/wt && got add new >/dev/null)
429 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
430 local commit_id3=`git_show_head $testroot/repo`
432 # Print commit 3 only
433 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
434 (cd $testroot/wt && got log -x $commit_id3 | grep ^commit \
435 > $testroot/stdout)
436 cmp -s $testroot/stdout.expected $testroot/stdout
437 ret=$?
438 if [ $ret -ne 0 ]; then
439 diff -u $testroot/stdout.expected $testroot/stdout
440 test_done "$testroot" "$ret"
441 return 1
442 fi
444 # Print commit 3 up to commit 1 inclusive
445 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
446 echo "commit $commit_id2" >> $testroot/stdout.expected
447 echo "commit $commit_id1" >> $testroot/stdout.expected
448 (cd $testroot/wt && got log -c $commit_id3 -x $commit_id1 | \
449 grep ^commit > $testroot/stdout)
450 cmp -s $testroot/stdout.expected $testroot/stdout
451 ret=$?
452 if [ $ret -ne 0 ]; then
453 diff -u $testroot/stdout.expected $testroot/stdout
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 # Create commits on an unrelated branch
459 (cd $testroot/wt && got br foo > /dev/null)
460 echo bar >> $testroot/wt/alpha
461 (cd $testroot/wt && got commit -m "change on branch foo" >/dev/null)
462 local commit_id4=`git_show_branch_head $testroot/repo foo`
464 # Print commit 4 only (in work tree)
465 echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
466 (cd $testroot/wt && got log -x foo | grep ^commit \
467 > $testroot/stdout)
468 cmp -s $testroot/stdout.expected $testroot/stdout
469 ret=$?
470 if [ $ret -ne 0 ]; then
471 diff -u $testroot/stdout.expected $testroot/stdout
472 test_done "$testroot" "$ret"
473 return 1
474 fi
476 # Print commit 4 only (in repository)
477 echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
478 (cd $testroot/repo && got log -c foo -x foo | grep ^commit \
479 > $testroot/stdout)
480 cmp -s $testroot/stdout.expected $testroot/stdout
481 ret=$?
482 if [ $ret -ne 0 ]; then
483 diff -u $testroot/stdout.expected $testroot/stdout
484 test_done "$testroot" "$ret"
485 return 1
486 fi
488 # Repository's HEAD is on master branch so -x foo without an explicit
489 # '-c foo' start commit has no effect there
490 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
491 echo "commit $commit_id2" >> $testroot/stdout.expected
492 echo "commit $commit_id1" >> $testroot/stdout.expected
493 echo "commit $commit_id0" >> $testroot/stdout.expected
494 (cd $testroot/repo && got log -x foo | grep ^commit \
495 > $testroot/stdout)
496 cmp -s $testroot/stdout.expected $testroot/stdout
497 ret=$?
498 if [ $ret -ne 0 ]; then
499 diff -u $testroot/stdout.expected $testroot/stdout
500 test_done "$testroot" "$ret"
501 return 1
502 fi
504 # got will refuse -x with a non-existent commit
505 (cd $testroot/wt && got log -x nonexistent \
506 > $testroot/stdout 2> $testroot/stderr)
507 ret=$?
508 if [ $ret -eq 0 ]; then
509 echo "log command succeeded unexpectedly" >&2
510 test_done "$testroot" "1"
511 return 1
512 fi
513 echo -n > $testroot/stdout.expected
514 echo "got: reference nonexistent not found" \
515 > $testroot/stderr.expected
516 cmp -s $testroot/stderr.expected $testroot/stderr
517 ret=$?
518 if [ $ret -ne 0 ]; then
519 diff -u $testroot/stderr.expected $testroot/stderr
520 test_done "$testroot" "$ret"
521 return 1
522 fi
523 cmp -s $testroot/stdout.expected $testroot/stdout
524 ret=$?
525 if [ $ret -ne 0 ]; then
526 diff -u $testroot/stdout.expected $testroot/stdout
527 test_done "$testroot" "$ret"
528 return 1
529 fi
531 # try the same with the hash of an empty string which is very
532 # unlikely to match any object
533 local empty_sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709
534 (cd $testroot/wt && got log -x $empty_sha1 \
535 > $testroot/stdout 2> $testroot/stderr)
536 ret=$?
537 if [ $ret -eq 0 ]; then
538 echo "log command succeeded unexpectedly" >&2
539 test_done "$testroot" "1"
540 return 1
541 fi
542 echo -n > $testroot/stdout.expected
543 echo "got: commit $empty_sha1: object not found" \
544 > $testroot/stderr.expected
545 cmp -s $testroot/stderr.expected $testroot/stderr
546 ret=$?
547 if [ $ret -ne 0 ]; then
548 diff -u $testroot/stderr.expected $testroot/stderr
549 test_done "$testroot" "$ret"
550 return 1
551 fi
552 cmp -s $testroot/stdout.expected $testroot/stdout
553 ret=$?
554 if [ $ret -ne 0 ]; then
555 diff -u $testroot/stdout.expected $testroot/stdout
556 test_done "$testroot" "$ret"
557 return 1
558 fi
560 test_done "$testroot" "0"
563 test_log_reverse_display() {
564 local testroot=`test_init log_reverse_display`
565 local commit_id0=`git_show_head $testroot/repo`
567 got checkout $testroot/repo $testroot/wt > /dev/null
568 ret=$?
569 if [ $ret -ne 0 ]; then
570 test_done "$testroot" "$ret"
571 return 1
572 fi
574 echo "modified alpha" > $testroot/wt/alpha
575 (cd $testroot/wt && got commit -m 'commit1' > /dev/null)
576 local commit_id1=`git_show_head $testroot/repo`
578 (cd $testroot/wt && got rm beta >/dev/null)
579 (cd $testroot/wt && got commit -m 'commit2' > /dev/null)
580 local commit_id2=`git_show_head $testroot/repo`
582 echo "new file" > $testroot/wt/new
583 (cd $testroot/wt && got add new >/dev/null)
584 (cd $testroot/wt && got commit -m 'commit3' > /dev/null)
585 local commit_id3=`git_show_head $testroot/repo`
587 # -R alone should display all commits in reverse
588 echo "commit $commit_id0" > $testroot/stdout.expected
589 echo "commit $commit_id1" >> $testroot/stdout.expected
590 echo "commit $commit_id2" >> $testroot/stdout.expected
591 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
592 (cd $testroot/wt && got log -R | grep ^commit > $testroot/stdout)
593 cmp -s $testroot/stdout.expected $testroot/stdout
594 ret=$?
595 if [ $ret -ne 0 ]; then
596 diff -u $testroot/stdout.expected $testroot/stdout
597 test_done "$testroot" "$ret"
598 return 1
599 fi
601 # -R takes effect after the -l commit traversal limit
602 echo "commit $commit_id2" > $testroot/stdout.expected
603 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
604 (cd $testroot/wt && got log -R -l2 | grep ^commit > $testroot/stdout)
605 cmp -s $testroot/stdout.expected $testroot/stdout
606 ret=$?
607 if [ $ret -ne 0 ]; then
608 diff -u $testroot/stdout.expected $testroot/stdout
609 test_done "$testroot" "$ret"
610 return 1
611 fi
613 # -R works with commit ranges specified via -c and -x
614 echo "commit $commit_id1" > $testroot/stdout.expected
615 echo "commit $commit_id2" >> $testroot/stdout.expected
616 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
617 (cd $testroot/wt && got log -R -c $commit_id3 -x $commit_id1 | \
618 grep ^commit > $testroot/stdout)
619 cmp -s $testroot/stdout.expected $testroot/stdout
620 ret=$?
621 if [ $ret -ne 0 ]; then
622 diff -u $testroot/stdout.expected $testroot/stdout
623 test_done "$testroot" "$ret"
624 return 1
625 fi
627 # commit matching with -s applies before -R
628 echo "commit $commit_id1" > $testroot/stdout.expected
629 echo "commit $commit_id2" >> $testroot/stdout.expected
630 (cd $testroot/wt && got log -R -S 'commit[12]' | \
631 grep ^commit > $testroot/stdout)
632 cmp -s $testroot/stdout.expected $testroot/stdout
633 ret=$?
634 if [ $ret -ne 0 ]; then
635 diff -u $testroot/stdout.expected $testroot/stdout
636 test_done "$testroot" "$ret"
637 return 1
638 fi
640 # -R works in combination with -P
641 echo "" > $testroot/stdout.expected
642 (cd $testroot/wt && got log -R -P | grep -E '^(commit| [MDmA])' \
643 > $testroot/stdout)
644 echo "commit $commit_id0" > $testroot/stdout.expected
645 echo " A alpha" >> $testroot/stdout.expected
646 echo " A beta" >> $testroot/stdout.expected
647 echo " A epsilon/zeta" >> $testroot/stdout.expected
648 echo " A gamma/delta" >> $testroot/stdout.expected
649 echo "commit $commit_id1" >> $testroot/stdout.expected
650 echo " M alpha" >> $testroot/stdout.expected
651 echo "commit $commit_id2" >> $testroot/stdout.expected
652 echo " D beta" >> $testroot/stdout.expected
653 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
654 echo " A new" >> $testroot/stdout.expected
655 cmp -s $testroot/stdout.expected $testroot/stdout
656 ret=$?
657 if [ $ret -ne 0 ]; then
658 diff -u $testroot/stdout.expected $testroot/stdout
659 fi
660 test_done "$testroot" "$ret"
663 test_log_in_worktree_different_repo() {
664 local testroot=`test_init log_in_worktree_different_repo 1`
666 make_test_tree $testroot/repo
667 mkdir -p $testroot/repo/epsilon/d
668 echo foo > $testroot/repo/epsilon/d/foo
669 (cd $testroot/repo && git add .)
670 git_commit $testroot/repo -m "adding the test tree"
671 local head_commit=`git_show_head $testroot/repo`
673 gotadmin init $testroot/other-repo
674 mkdir -p $testroot/tree
675 make_test_tree $testroot/tree
676 got import -mm -b foo -r $testroot/other-repo $testroot/tree >/dev/null
677 got checkout -b foo $testroot/other-repo $testroot/wt > /dev/null
678 ret=$?
679 if [ $ret -ne 0 ]; then
680 test_done "$testroot" "$ret"
681 return 1
682 fi
684 echo "commit $head_commit (master)" > $testroot/stdout.expected
686 # 'got log' used to fail with "reference refs/heads/foo not found"
687 # even though that reference belongs to an unrelated repository
688 # found via a worktree via the current working directory
689 for p in "" alpha epsilon; do
690 (cd $testroot/wt && got log -r $testroot/repo $p | \
691 grep ^commit > $testroot/stdout)
692 cmp -s $testroot/stdout.expected $testroot/stdout
693 ret=$?
694 if [ $ret -ne 0 ]; then
695 diff -u $testroot/stdout.expected $testroot/stdout
696 test_done "$testroot" "$ret"
697 return 1
698 fi
699 done
701 for p in "" epsilon/zeta; do
702 (cd $testroot/wt/epsilon && got log -r $testroot/repo $p | \
703 grep ^commit > $testroot/stdout)
704 cmp -s $testroot/stdout.expected $testroot/stdout
705 ret=$?
706 if [ $ret -ne 0 ]; then
707 diff -u $testroot/stdout.expected $testroot/stdout
708 test_done "$testroot" "$ret"
709 return 1
710 fi
711 done
713 for p in "" foo; do
714 (cd $testroot/wt/epsilon && got log -r $testroot/repo epsilon/d/$p | \
715 grep ^commit > $testroot/stdout)
716 cmp -s $testroot/stdout.expected $testroot/stdout
717 ret=$?
718 if [ $ret -ne 0 ]; then
719 diff -u $testroot/stdout.expected $testroot/stdout
720 test_done "$testroot" "$ret"
721 return 1
722 fi
723 done
725 test_done "$testroot" "0"
728 test_log_changed_paths() {
729 local testroot=`test_init log_changed_paths`
730 local commit_id0=`git_show_head $testroot/repo`
732 got checkout $testroot/repo $testroot/wt > /dev/null
733 ret=$?
734 if [ $ret -ne 0 ]; then
735 test_done "$testroot" "$ret"
736 return 1
737 fi
739 echo "modified alpha" > $testroot/wt/alpha
740 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
741 local commit_id1=`git_show_head $testroot/repo`
743 (cd $testroot/wt && got rm beta >/dev/null)
744 (cd $testroot/wt && chmod +x epsilon/zeta >/dev/null)
745 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
746 local commit_id2=`git_show_head $testroot/repo`
748 echo "new file" > $testroot/wt/new
749 (cd $testroot/wt && got add new >/dev/null)
750 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
751 local commit_id3=`git_show_head $testroot/repo`
753 (cd $testroot/wt && got log -P | grep '^ [MDmA]' > $testroot/stdout)
755 echo " A new" > $testroot/stdout.expected
756 echo " D beta" >> $testroot/stdout.expected
757 echo " m epsilon/zeta" >> $testroot/stdout.expected
758 echo " M alpha" >> $testroot/stdout.expected
759 echo " A alpha" >> $testroot/stdout.expected
760 echo " A beta" >> $testroot/stdout.expected
761 echo " A epsilon/zeta" >> $testroot/stdout.expected
762 echo " A gamma/delta" >> $testroot/stdout.expected
764 cmp -s $testroot/stdout.expected $testroot/stdout
765 ret=$?
766 if [ $ret -ne 0 ]; then
767 diff -u $testroot/stdout.expected $testroot/stdout
768 fi
769 test_done "$testroot" "$ret"
772 test_log_submodule() {
773 local testroot=`test_init log_submodule`
775 make_single_file_repo $testroot/repo2 foo
777 (cd $testroot/repo && git -c protocol.file.allow=always \
778 submodule -q add ../repo2)
779 (cd $testroot/repo && git commit -q -m 'adding submodule')
780 local head_commit=`git_show_head $testroot/repo`
782 echo "commit $head_commit (master)" > $testroot/stdout.expected
784 got log -r $testroot/repo -l1 repo2 | grep ^commit > $testroot/stdout
785 cmp -s $testroot/stdout.expected $testroot/stdout
786 ret=$?
787 if [ $ret -ne 0 ]; then
788 diff -u $testroot/stdout.expected $testroot/stdout
789 test_done "$testroot" "$ret"
790 return 1
791 fi
793 echo " A .gitmodules" > $testroot/stdout.expected
795 got log -r $testroot/repo -l1 -P repo2 | grep '^ [MDmA]' \
796 > $testroot/stdout
797 cmp -s $testroot/stdout.expected $testroot/stdout
798 ret=$?
799 if [ $ret -ne 0 ]; then
800 diff -u $testroot/stdout.expected $testroot/stdout
801 test_done "$testroot" "$ret"
802 return 1
803 fi
805 got log -p -r $testroot/repo -l1 repo2 \
806 > $testroot/stdout 2> $testroot/stderr
807 ret=$?
808 if [ $ret -eq 0 ]; then
809 echo "log command succeeded unexpectedly" >&2
810 test_done "$testroot" "1"
811 return 1
812 fi
813 local submodule_id=$(got tree -r $testroot/repo -i | \
814 grep 'repo2\$$' | cut -d ' ' -f1)
815 echo "got: object $submodule_id not found" > $testroot/stderr.expected
817 cmp -s $testroot/stderr.expected $testroot/stderr
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/stderr.expected $testroot/stderr
821 test_done "$testroot" "$ret"
822 return 1
823 fi
825 echo "modified foo" > $testroot/repo2/foo
826 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
828 # Update the repo/repo2 submodule link
829 (cd $testroot/repo && git -C repo2 pull -q)
830 (cd $testroot/repo && git add repo2)
831 git_commit $testroot/repo -m "changed submodule link"
833 # log -P does not show the changed submodule path
834 got log -P -r $testroot/repo -l1 repo2 > $testroot/stdout.full
835 ret=$?
836 if [ $ret -ne 0 ]; then
837 echo "log command failed unexpectedly" >&2
838 test_done "$testroot" "1"
839 return 1
840 fi
841 grep '^ [MDmA]' $testroot/stdout.full > $testroot/stdout
843 echo -n > $testroot/stdout.expected
844 cmp -s $testroot/stdout.expected $testroot/stdout
845 ret=$?
846 if [ $ret -ne 0 ]; then
847 diff -u $testroot/stdout.expected $testroot/stdout
848 fi
849 test_done "$testroot" "$ret"
852 test_log_diffstat() {
853 local testroot=`test_init log_diffstat`
855 got checkout $testroot/repo $testroot/wt > /dev/null
856 ret=$?
857 if [ $ret -ne 0 ]; then
858 test_done "$testroot" "$ret"
859 return 1
860 fi
862 printf "modified\nalpha.\n" > $testroot/wt/alpha
863 (cd $testroot/wt && got commit -m 'log_diffstat mod file' > /dev/null)
865 (cd $testroot/wt && got rm beta >/dev/null)
866 (cd $testroot/wt && chmod +x epsilon/zeta >/dev/null)
867 (cd $testroot/wt && got commit -m 'log_diffstat rm file' > /dev/null)
869 echo "new file" > $testroot/wt/new
870 (cd $testroot/wt && got add new >/dev/null)
871 (cd $testroot/wt && got commit -m 'log_diffstat add file' > /dev/null)
873 (cd $testroot/wt && got log -d | grep -A2 '^ [MDmA]' | sed '/^--/d' > \
874 $testroot/stdout)
876 cat <<EOF >$testroot/stdout.expected
877 A new | 1+ 0-
879 1 file changed, 1 insertion(+), 0 deletions(-)
880 D beta | 0+ 1-
881 m epsilon/zeta | 0+ 0-
883 2 files changed, 0 insertions(+), 1 deletion(-)
884 M alpha | 2+ 1-
886 1 file changed, 2 insertions(+), 1 deletion(-)
887 A alpha | 1+ 0-
888 A beta | 1+ 0-
889 A epsilon/zeta | 1+ 0-
890 A gamma/delta | 1+ 0-
892 4 files changed, 4 insertions(+), 0 deletions(-)
893 EOF
895 cmp -s $testroot/stdout.expected $testroot/stdout
896 ret=$?
897 if [ $ret -ne 0 ]; then
898 diff -u $testroot/stdout.expected $testroot/stdout
899 fi
900 test_done "$testroot" "$ret"
903 test_parseargs "$@"
904 run_test test_log_in_repo
905 run_test test_log_in_bare_repo
906 run_test test_log_in_worktree
907 run_test test_log_in_worktree_with_path_prefix
908 run_test test_log_tag
909 run_test test_log_limit
910 run_test test_log_oneline
911 run_test test_log_patch_added_file
912 run_test test_log_nonexistent_path
913 run_test test_log_end_at_commit
914 run_test test_log_reverse_display
915 run_test test_log_in_worktree_different_repo
916 run_test test_log_changed_paths
917 run_test test_log_submodule
918 run_test test_log_diffstat