portable: move tmpl.h to EXTRA_DIST
[got-portable.git] / regress / cmdline / log.sh
blob9210413ada76ebe36264f3770c28732157edfe99
1 #!/bin/sh
3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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
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
47 done
49 test_done "$testroot" "0"
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
68 done
70 test_done "$testroot" "0"
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
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
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
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
126 done
128 test_done "$testroot" "0"
131 test_log_in_worktree_with_path_prefix() {
132 local testroot=`test_init log_in_prefixed_worktree`
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
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
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
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
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
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
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
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
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
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
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
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
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 -d "@${author_time1}" +"%G-%m-%d"`
323 printf "$d %-7s test oneline\n" master > $testroot/stdout.expected
324 d=`date -u -d "@${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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
849 test_done "$testroot" "$ret"
852 test_parseargs "$@"
853 run_test test_log_in_repo
854 run_test test_log_in_bare_repo
855 run_test test_log_in_worktree
856 run_test test_log_in_worktree_with_path_prefix
857 run_test test_log_tag
858 run_test test_log_limit
859 run_test test_log_oneline
860 run_test test_log_patch_added_file
861 run_test test_log_nonexistent_path
862 run_test test_log_end_at_commit
863 run_test test_log_reverse_display
864 run_test test_log_in_worktree_different_repo
865 run_test test_log_changed_paths
866 run_test test_log_submodule