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" != "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" != "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" != "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" != "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" != "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" != "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" != "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_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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "0" ]; then
295 diff -u $testroot/stdout.expected $testroot/stdout
296 fi
297 test_done "$testroot" "0"
300 test_log_patch_added_file() {
301 local testroot=`test_init log_patch_added_file`
302 local commit_id0=`git_show_head $testroot/repo`
304 got checkout $testroot/repo $testroot/wt > /dev/null
305 ret="$?"
306 if [ "$ret" != "0" ]; then
307 test_done "$testroot" "$ret"
308 return 1
309 fi
311 echo "new file" > $testroot/wt/new
312 (cd $testroot/wt && got add new >/dev/null)
313 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
314 local commit_id1=`git_show_head $testroot/repo`
316 echo "commit $commit_id1 (master)" > $testroot/stdout.expected
317 # This used to fail with 'got: no such entry found in tree'
318 (cd $testroot/wt && got log -l1 -p new > $testroot/stdout.patch)
319 ret="$?"
320 if [ "$ret" != "0" ]; then
321 echo "got log command failed unexpectedly" >&2
322 test_done "$testroot" "$ret"
323 return 1
324 fi
325 grep ^commit $testroot/stdout.patch > $testroot/stdout
326 cmp -s $testroot/stdout.expected $testroot/stdout
327 ret="$?"
328 if [ "$ret" != "0" ]; then
329 diff -u $testroot/stdout.expected $testroot/stdout
330 fi
331 test_done "$testroot" "$ret"
334 test_log_nonexistent_path() {
335 local testroot=`test_init log_nonexistent_path`
336 local head_rev=`git_show_head $testroot/repo`
338 echo "commit $head_rev (master)" > $testroot/stdout.expected
340 (cd $testroot/repo && got log this/does/not/exist \
341 > $testroot/stdout 2> $testroot/stderr)
342 ret="$?"
343 if [ "$ret" = "0" ]; then
344 echo "log command succeeded unexpectedly" >&2
345 test_done "$testroot" "1"
346 return 1
347 fi
349 echo -n > $testroot/stdout.expected
350 cmp -s $testroot/stdout.expected $testroot/stdout
351 ret="$?"
352 if [ "$ret" != "0" ]; then
353 diff -u $testroot/stdout.expected $testroot/stdout
354 test_done "$testroot" "$ret"
355 return 1
356 fi
358 echo "got: this/does/not/exist: no such entry found in tree" \
359 > $testroot/stderr.expected
360 cmp -s $testroot/stderr.expected $testroot/stderr
361 ret="$?"
362 if [ "$ret" != "0" ]; then
363 diff -u $testroot/stderr.expected $testroot/stderr
364 fi
365 test_done "$testroot" "$ret"
368 test_log_end_at_commit() {
369 local testroot=`test_init log_end_at_commit`
370 local commit_id0=`git_show_head $testroot/repo`
372 got checkout $testroot/repo $testroot/wt > /dev/null
373 ret="$?"
374 if [ "$ret" != "0" ]; then
375 test_done "$testroot" "$ret"
376 return 1
377 fi
379 echo "modified alpha" > $testroot/wt/alpha
380 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
381 local commit_id1=`git_show_head $testroot/repo`
383 (cd $testroot/wt && got rm beta >/dev/null)
384 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
385 local commit_id2=`git_show_head $testroot/repo`
387 echo "new file" > $testroot/wt/new
388 (cd $testroot/wt && got add new >/dev/null)
389 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
390 local commit_id3=`git_show_head $testroot/repo`
392 # Print commit 3 only
393 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
394 (cd $testroot/wt && got log -x $commit_id3 | grep ^commit \
395 > $testroot/stdout)
396 cmp -s $testroot/stdout.expected $testroot/stdout
397 ret="$?"
398 if [ "$ret" != "0" ]; then
399 diff -u $testroot/stdout.expected $testroot/stdout
400 test_done "$testroot" "$ret"
401 return 1
402 fi
404 # Print commit 3 up to commit 1 inclusive
405 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
406 echo "commit $commit_id2" >> $testroot/stdout.expected
407 echo "commit $commit_id1" >> $testroot/stdout.expected
408 (cd $testroot/wt && got log -c $commit_id3 -x $commit_id1 | \
409 grep ^commit > $testroot/stdout)
410 cmp -s $testroot/stdout.expected $testroot/stdout
411 ret="$?"
412 if [ "$ret" != "0" ]; then
413 diff -u $testroot/stdout.expected $testroot/stdout
414 test_done "$testroot" "$ret"
415 return 1
416 fi
418 # Create commits on an unrelated branch
419 (cd $testroot/wt && got br foo > /dev/null)
420 echo bar >> $testroot/wt/alpha
421 (cd $testroot/wt && got commit -m "change on branch foo" >/dev/null)
422 local commit_id4=`git_show_branch_head $testroot/repo foo`
424 # Print commit 4 only (in work tree)
425 echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
426 (cd $testroot/wt && got log -x foo | grep ^commit \
427 > $testroot/stdout)
428 cmp -s $testroot/stdout.expected $testroot/stdout
429 ret="$?"
430 if [ "$ret" != "0" ]; then
431 diff -u $testroot/stdout.expected $testroot/stdout
432 test_done "$testroot" "$ret"
433 return 1
434 fi
436 # Print commit 4 only (in repository)
437 echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
438 (cd $testroot/repo && got log -c foo -x foo | grep ^commit \
439 > $testroot/stdout)
440 cmp -s $testroot/stdout.expected $testroot/stdout
441 ret="$?"
442 if [ "$ret" != "0" ]; then
443 diff -u $testroot/stdout.expected $testroot/stdout
444 test_done "$testroot" "$ret"
445 return 1
446 fi
448 # Repository's HEAD is on master branch so -x foo without an explicit
449 # '-c foo' start commit has no effect there
450 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
451 echo "commit $commit_id2" >> $testroot/stdout.expected
452 echo "commit $commit_id1" >> $testroot/stdout.expected
453 echo "commit $commit_id0" >> $testroot/stdout.expected
454 (cd $testroot/repo && got log -x foo | grep ^commit \
455 > $testroot/stdout)
456 cmp -s $testroot/stdout.expected $testroot/stdout
457 ret="$?"
458 if [ "$ret" != "0" ]; then
459 diff -u $testroot/stdout.expected $testroot/stdout
460 test_done "$testroot" "$ret"
461 return 1
462 fi
464 # got will refuse -x with a non-existent commit
465 (cd $testroot/wt && got log -x nonexistent \
466 > $testroot/stdout 2> $testroot/stderr)
467 ret="$?"
468 if [ "$ret" = "0" ]; then
469 echo "log command succeeded unexpectedly" >&2
470 test_done "$testroot" "1"
471 return 1
472 fi
473 echo -n > $testroot/stdout.expected
474 echo "got: reference nonexistent not found" \
475 > $testroot/stderr.expected
476 cmp -s $testroot/stderr.expected $testroot/stderr
477 ret="$?"
478 if [ "$ret" != "0" ]; then
479 diff -u $testroot/stderr.expected $testroot/stderr
480 test_done "$testroot" "$ret"
481 return 1
482 fi
483 cmp -s $testroot/stdout.expected $testroot/stdout
484 ret="$?"
485 if [ "$ret" != "0" ]; then
486 diff -u $testroot/stdout.expected $testroot/stdout
487 test_done "$testroot" "$ret"
488 return 1
489 fi
491 # try the same with the hash of an empty string which is very
492 # unlikely to match any object
493 local empty_sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709
494 (cd $testroot/wt && got log -x $empty_sha1 \
495 > $testroot/stdout 2> $testroot/stderr)
496 ret="$?"
497 if [ "$ret" = "0" ]; then
498 echo "log command succeeded unexpectedly" >&2
499 test_done "$testroot" "1"
500 return 1
501 fi
502 echo -n > $testroot/stdout.expected
503 echo "got: commit $empty_sha1: object not found" \
504 > $testroot/stderr.expected
505 cmp -s $testroot/stderr.expected $testroot/stderr
506 ret="$?"
507 if [ "$ret" != "0" ]; then
508 diff -u $testroot/stderr.expected $testroot/stderr
509 test_done "$testroot" "$ret"
510 return 1
511 fi
512 cmp -s $testroot/stdout.expected $testroot/stdout
513 ret="$?"
514 if [ "$ret" != "0" ]; then
515 diff -u $testroot/stdout.expected $testroot/stdout
516 test_done "$testroot" "$ret"
517 return 1
518 fi
520 test_done "$testroot" "0"
523 test_log_reverse_display() {
524 local testroot=`test_init log_reverse_display`
525 local commit_id0=`git_show_head $testroot/repo`
527 got checkout $testroot/repo $testroot/wt > /dev/null
528 ret="$?"
529 if [ "$ret" != "0" ]; then
530 test_done "$testroot" "$ret"
531 return 1
532 fi
534 echo "modified alpha" > $testroot/wt/alpha
535 (cd $testroot/wt && got commit -m 'commit1' > /dev/null)
536 local commit_id1=`git_show_head $testroot/repo`
538 (cd $testroot/wt && got rm beta >/dev/null)
539 (cd $testroot/wt && got commit -m 'commit2' > /dev/null)
540 local commit_id2=`git_show_head $testroot/repo`
542 echo "new file" > $testroot/wt/new
543 (cd $testroot/wt && got add new >/dev/null)
544 (cd $testroot/wt && got commit -m 'commit3' > /dev/null)
545 local commit_id3=`git_show_head $testroot/repo`
547 # -R alone should display all commits in reverse
548 echo "commit $commit_id0" > $testroot/stdout.expected
549 echo "commit $commit_id1" >> $testroot/stdout.expected
550 echo "commit $commit_id2" >> $testroot/stdout.expected
551 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
552 (cd $testroot/wt && got log -R | grep ^commit > $testroot/stdout)
553 cmp -s $testroot/stdout.expected $testroot/stdout
554 ret="$?"
555 if [ "$ret" != "0" ]; then
556 diff -u $testroot/stdout.expected $testroot/stdout
557 test_done "$testroot" "$ret"
558 return 1
559 fi
561 # -R takes effect after the -l commit traversal limit
562 echo "commit $commit_id2" > $testroot/stdout.expected
563 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
564 (cd $testroot/wt && got log -R -l2 | grep ^commit > $testroot/stdout)
565 cmp -s $testroot/stdout.expected $testroot/stdout
566 ret="$?"
567 if [ "$ret" != "0" ]; then
568 diff -u $testroot/stdout.expected $testroot/stdout
569 test_done "$testroot" "$ret"
570 return 1
571 fi
573 # -R works with commit ranges specified via -c and -x
574 echo "commit $commit_id1" > $testroot/stdout.expected
575 echo "commit $commit_id2" >> $testroot/stdout.expected
576 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
577 (cd $testroot/wt && got log -R -c $commit_id3 -x $commit_id1 | \
578 grep ^commit > $testroot/stdout)
579 cmp -s $testroot/stdout.expected $testroot/stdout
580 ret="$?"
581 if [ "$ret" != "0" ]; then
582 diff -u $testroot/stdout.expected $testroot/stdout
583 test_done "$testroot" "$ret"
584 return 1
585 fi
587 # commit matching with -s applies before -R
588 echo "commit $commit_id1" > $testroot/stdout.expected
589 echo "commit $commit_id2" >> $testroot/stdout.expected
590 (cd $testroot/wt && got log -R -s 'commit[12]' | \
591 grep ^commit > $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 # -R works in combination with -P
601 echo "" > $testroot/stdout.expected
602 (cd $testroot/wt && got log -R -P | grep -E '^(commit| [MDmA])' \
603 > $testroot/stdout)
604 echo "commit $commit_id0" > $testroot/stdout.expected
605 echo " A alpha" >> $testroot/stdout.expected
606 echo " A beta" >> $testroot/stdout.expected
607 echo " A epsilon/zeta" >> $testroot/stdout.expected
608 echo " A gamma/delta" >> $testroot/stdout.expected
609 echo "commit $commit_id1" >> $testroot/stdout.expected
610 echo " M alpha" >> $testroot/stdout.expected
611 echo "commit $commit_id2" >> $testroot/stdout.expected
612 echo " D beta" >> $testroot/stdout.expected
613 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
614 echo " A new" >> $testroot/stdout.expected
615 cmp -s $testroot/stdout.expected $testroot/stdout
616 ret="$?"
617 if [ "$ret" != "0" ]; then
618 diff -u $testroot/stdout.expected $testroot/stdout
619 fi
620 test_done "$testroot" "$ret"
623 test_log_in_worktree_different_repo() {
624 local testroot=`test_init log_in_worktree_different_repo 1`
626 make_test_tree $testroot/repo
627 mkdir -p $testroot/repo/epsilon/d
628 echo foo > $testroot/repo/epsilon/d/foo
629 (cd $testroot/repo && git add .)
630 git_commit $testroot/repo -m "adding the test tree"
631 local head_commit=`git_show_head $testroot/repo`
633 got init $testroot/other-repo
634 mkdir -p $testroot/tree
635 make_test_tree $testroot/tree
636 got import -mm -b foo -r $testroot/other-repo $testroot/tree >/dev/null
637 got checkout -b foo $testroot/other-repo $testroot/wt > /dev/null
638 ret="$?"
639 if [ "$ret" != "0" ]; then
640 test_done "$testroot" "$ret"
641 return 1
642 fi
644 echo "commit $head_commit (master)" > $testroot/stdout.expected
646 # 'got log' used to fail with "reference refs/heads/foo not found"
647 # even though that reference belongs to an unrelated repository
648 # found via a worktree via the current working directory
649 for p in "" alpha epsilon; do
650 (cd $testroot/wt && got log -r $testroot/repo $p | \
651 grep ^commit > $testroot/stdout)
652 cmp -s $testroot/stdout.expected $testroot/stdout
653 ret="$?"
654 if [ "$ret" != "0" ]; then
655 diff -u $testroot/stdout.expected $testroot/stdout
656 test_done "$testroot" "$ret"
657 return 1
658 fi
659 done
661 for p in "" epsilon/zeta; do
662 (cd $testroot/wt/epsilon && got log -r $testroot/repo $p | \
663 grep ^commit > $testroot/stdout)
664 cmp -s $testroot/stdout.expected $testroot/stdout
665 ret="$?"
666 if [ "$ret" != "0" ]; then
667 diff -u $testroot/stdout.expected $testroot/stdout
668 test_done "$testroot" "$ret"
669 return 1
670 fi
671 done
673 for p in "" foo; do
674 (cd $testroot/wt/epsilon && got log -r $testroot/repo epsilon/d/$p | \
675 grep ^commit > $testroot/stdout)
676 cmp -s $testroot/stdout.expected $testroot/stdout
677 ret="$?"
678 if [ "$ret" != "0" ]; then
679 diff -u $testroot/stdout.expected $testroot/stdout
680 test_done "$testroot" "$ret"
681 return 1
682 fi
683 done
685 test_done "$testroot" "0"
688 test_log_changed_paths() {
689 local testroot=`test_init log_changed_paths`
690 local commit_id0=`git_show_head $testroot/repo`
692 got checkout $testroot/repo $testroot/wt > /dev/null
693 ret="$?"
694 if [ "$ret" != "0" ]; then
695 test_done "$testroot" "$ret"
696 return 1
697 fi
699 echo "modified alpha" > $testroot/wt/alpha
700 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
701 local commit_id1=`git_show_head $testroot/repo`
703 (cd $testroot/wt && got rm beta >/dev/null)
704 (cd $testroot/wt && chmod +x epsilon/zeta >/dev/null)
705 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
706 local commit_id2=`git_show_head $testroot/repo`
708 echo "new file" > $testroot/wt/new
709 (cd $testroot/wt && got add new >/dev/null)
710 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
711 local commit_id3=`git_show_head $testroot/repo`
713 (cd $testroot/wt && got log -P | grep '^ [MDmA]' > $testroot/stdout)
715 echo " A new" > $testroot/stdout.expected
716 echo " D beta" >> $testroot/stdout.expected
717 echo " m epsilon/zeta" >> $testroot/stdout.expected
718 echo " M alpha" >> $testroot/stdout.expected
719 echo " A alpha" >> $testroot/stdout.expected
720 echo " A beta" >> $testroot/stdout.expected
721 echo " A epsilon/zeta" >> $testroot/stdout.expected
722 echo " A gamma/delta" >> $testroot/stdout.expected
724 cmp -s $testroot/stdout.expected $testroot/stdout
725 ret="$?"
726 if [ "$ret" != "0" ]; then
727 diff -u $testroot/stdout.expected $testroot/stdout
728 fi
729 test_done "$testroot" "$ret"
732 test_log_submodule() {
733 local testroot=`test_init log_submodule`
735 make_single_file_repo $testroot/repo2 foo
737 (cd $testroot/repo && git submodule -q add ../repo2)
738 (cd $testroot/repo && git commit -q -m 'adding submodule')
739 local head_commit=`git_show_head $testroot/repo`
741 echo "commit $head_commit (master)" > $testroot/stdout.expected
743 got log -r $testroot/repo -l1 repo2 | grep ^commit > $testroot/stdout
744 cmp -s $testroot/stdout.expected $testroot/stdout
745 ret="$?"
746 if [ "$ret" != "0" ]; then
747 diff -u $testroot/stdout.expected $testroot/stdout
748 test_done "$testroot" "$ret"
749 return 1
750 fi
752 echo " A .gitmodules" > $testroot/stdout.expected
754 got log -r $testroot/repo -l1 -P repo2 | grep '^ [MDmA]' \
755 > $testroot/stdout
756 cmp -s $testroot/stdout.expected $testroot/stdout
757 ret="$?"
758 if [ "$ret" != "0" ]; then
759 diff -u $testroot/stdout.expected $testroot/stdout
760 test_done "$testroot" "$ret"
761 return 1
762 fi
764 got log -p -r $testroot/repo -l1 repo2 \
765 > $testroot/stdout 2> $testroot/stderr
766 ret="$?"
767 if [ "$ret" = "0" ]; then
768 echo "log command succeeded unexpectedly" >&2
769 test_done "$testroot" "1"
770 return 1
771 fi
772 local submodule_id=$(got tree -r $testroot/repo -i | \
773 grep 'repo2\$$' | cut -d ' ' -f1)
774 echo "got: object $submodule_id not found" > $testroot/stderr.expected
776 cmp -s $testroot/stderr.expected $testroot/stderr
777 ret="$?"
778 if [ "$ret" != "0" ]; then
779 diff -u $testroot/stderr.expected $testroot/stderr
780 test_done "$testroot" "$ret"
781 return 1
782 fi
784 echo "modified foo" > $testroot/repo2/foo
785 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
787 # Update the repo/repo2 submodule link
788 (cd $testroot/repo && git -C repo2 pull -q)
789 (cd $testroot/repo && git add repo2)
790 git_commit $testroot/repo -m "changed submodule link"
792 # log -P does not show the changed submodule path
793 got log -P -r $testroot/repo -l1 repo2 > $testroot/stdout.full
794 ret="$?"
795 if [ "$ret" != "0" ]; then
796 echo "log command failed unexpectedly" >&2
797 test_done "$testroot" "1"
798 return 1
799 fi
800 grep '^ [MDmA]' $testroot/stdout.full > $testroot/stdout
802 echo -n > $testroot/stdout.expected
803 cmp -s $testroot/stdout.expected $testroot/stdout
804 ret="$?"
805 if [ "$ret" != "0" ]; then
806 diff -u $testroot/stdout.expected $testroot/stdout
807 fi
808 test_done "$testroot" "$ret"
811 test_parseargs "$@"
812 run_test test_log_in_repo
813 run_test test_log_in_bare_repo
814 run_test test_log_in_worktree
815 run_test test_log_in_worktree_with_path_prefix
816 run_test test_log_tag
817 run_test test_log_limit
818 run_test test_log_patch_added_file
819 run_test test_log_nonexistent_path
820 run_test test_log_end_at_commit
821 run_test test_log_reverse_display
822 run_test test_log_in_worktree_different_repo
823 run_test test_log_changed_paths
824 run_test test_log_submodule