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 function 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 function 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 function 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 function 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"
142 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
143 ret="$?"
144 if [ "$ret" != "0" ]; then
145 test_done "$testroot" "$ret"
146 return 1
147 fi
149 echo "commit $zeta_rev" > $testroot/stdout.expected
150 echo "commit $head_rev" >> $testroot/stdout.expected
152 for p in "" "." zeta; do
153 (cd $testroot/wt && got log $p | \
154 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
162 done
164 test_done "$testroot" "0"
167 function test_log_tag {
168 local testroot=`test_init log_tag`
169 local commit_id=`git_show_head $testroot/repo`
170 local tag="1.0.0"
171 local tag2="2.0.0"
173 got checkout $testroot/repo $testroot/wt > /dev/null
174 ret="$?"
175 if [ "$ret" != "0" ]; then
176 test_done "$testroot" "$ret"
177 return 1
178 fi
180 (cd $testroot/repo && git tag -a -m "test" $tag)
182 echo "commit $commit_id (master, tags/$tag)" > $testroot/stdout.expected
183 (cd $testroot/wt && got log -l1 -c $tag | grep ^commit \
184 > $testroot/stdout)
185 cmp -s $testroot/stdout.expected $testroot/stdout
186 ret="$?"
187 if [ "$ret" != "0" ]; then
188 diff -u $testroot/stdout.expected $testroot/stdout
189 test_done "$testroot" "$ret"
190 return 1
191 fi
193 # test a "lightweight" tag
194 (cd $testroot/repo && git tag $tag2)
196 echo "commit $commit_id (master, tags/$tag, tags/$tag2)" \
197 > $testroot/stdout.expected
198 (cd $testroot/wt && got log -l1 -c $tag2 | grep ^commit \
199 > $testroot/stdout)
200 cmp -s $testroot/stdout.expected $testroot/stdout
201 ret="$?"
202 if [ "$ret" != "0" ]; then
203 diff -u $testroot/stdout.expected $testroot/stdout
204 fi
205 test_done "$testroot" "$ret"
208 function test_log_limit {
209 local testroot=`test_init log_limit`
210 local commit_id0=`git_show_head $testroot/repo`
212 got checkout $testroot/repo $testroot/wt > /dev/null
213 ret="$?"
214 if [ "$ret" != "0" ]; then
215 test_done "$testroot" "$ret"
216 return 1
217 fi
219 echo "modified alpha" > $testroot/wt/alpha
220 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
221 local commit_id1=`git_show_head $testroot/repo`
223 (cd $testroot/wt && got rm beta >/dev/null)
224 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
225 local commit_id2=`git_show_head $testroot/repo`
227 echo "new file" > $testroot/wt/new
228 (cd $testroot/wt && got add new >/dev/null)
229 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
230 local commit_id3=`git_show_head $testroot/repo`
232 # -l1 should print the first commit only
233 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
234 (cd $testroot/wt && got log -l1 | grep ^commit > $testroot/stdout)
235 cmp -s $testroot/stdout.expected $testroot/stdout
236 ret="$?"
237 if [ "$ret" != "0" ]; then
238 diff -u $testroot/stdout.expected $testroot/stdout
239 test_done "$testroot" "$ret"
240 return 1
241 fi
243 # env var can be used to set a log limit without -l option
244 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
245 echo "commit $commit_id2" >> $testroot/stdout.expected
246 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=2 got log | \
247 grep ^commit > $testroot/stdout)
248 cmp -s $testroot/stdout.expected $testroot/stdout
249 ret="$?"
250 if [ "$ret" != "0" ]; then
251 diff -u $testroot/stdout.expected $testroot/stdout
252 test_done "$testroot" "$ret"
253 return 1
254 fi
256 # non-numeric env var is ignored
257 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=foobar got log | \
258 grep ^commit > $testroot/stdout)
259 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
260 echo "commit $commit_id2" >> $testroot/stdout.expected
261 echo "commit $commit_id1" >> $testroot/stdout.expected
262 echo "commit $commit_id0" >> $testroot/stdout.expected
263 cmp -s $testroot/stdout.expected $testroot/stdout
264 ret="$?"
265 if [ "$ret" != "0" ]; then
266 diff -u $testroot/stdout.expected $testroot/stdout
267 test_done "$testroot" "$ret"
268 return 1
269 fi
271 # -l option takes precedence over env var
272 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
273 echo "commit $commit_id2" >> $testroot/stdout.expected
274 echo "commit $commit_id1" >> $testroot/stdout.expected
275 echo "commit $commit_id0" >> $testroot/stdout.expected
276 (cd $testroot/wt && env GOT_LOG_DEFAULT_LIMIT=1 got log -l0 | \
277 grep ^commit > $testroot/stdout)
278 cmp -s $testroot/stdout.expected $testroot/stdout
279 ret="$?"
280 if [ "$ret" != "0" ]; then
281 diff -u $testroot/stdout.expected $testroot/stdout
282 fi
283 test_done "$testroot" "0"
286 function test_log_patch_added_file {
287 local testroot=`test_init log_patch_added_file`
288 local commit_id0=`git_show_head $testroot/repo`
290 got checkout $testroot/repo $testroot/wt > /dev/null
291 ret="$?"
292 if [ "$ret" != "0" ]; then
293 test_done "$testroot" "$ret"
294 return 1
295 fi
297 echo "new file" > $testroot/wt/new
298 (cd $testroot/wt && got add new >/dev/null)
299 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
300 local commit_id1=`git_show_head $testroot/repo`
302 echo "commit $commit_id1 (master)" > $testroot/stdout.expected
303 # This used to fail with 'got: no such entry found in tree'
304 (cd $testroot/wt && got log -l1 -p new > $testroot/stdout.patch)
305 ret="$?"
306 if [ "$ret" != "0" ]; then
307 echo "got log command failed unexpectedly" >&2
308 test_done "$testroot" "$ret"
309 return 1
310 fi
311 grep ^commit $testroot/stdout.patch > $testroot/stdout
312 cmp -s $testroot/stdout.expected $testroot/stdout
313 ret="$?"
314 if [ "$ret" != "0" ]; then
315 diff -u $testroot/stdout.expected $testroot/stdout
316 fi
317 test_done "$testroot" "$ret"
320 function test_log_nonexistent_path {
321 local testroot=`test_init log_nonexistent_path`
322 local head_rev=`git_show_head $testroot/repo`
324 echo "commit $head_rev (master)" > $testroot/stdout.expected
326 (cd $testroot/repo && got log this/does/not/exist \
327 > $testroot/stdout 2> $testroot/stderr)
328 ret="$?"
329 if [ "$ret" == "0" ]; then
330 echo "log command succeeded unexpectedly" >&2
331 test_done "$testroot" "1"
332 return 1
333 fi
335 echo -n > $testroot/stdout.expected
336 cmp -s $testroot/stdout.expected $testroot/stdout
337 ret="$?"
338 if [ "$ret" != "0" ]; then
339 diff -u $testroot/stdout.expected $testroot/stdout
340 test_done "$testroot" "$ret"
341 return 1
342 fi
344 echo "got: this/does/not/exist: no such entry found in tree" \
345 > $testroot/stderr.expected
346 cmp -s $testroot/stderr.expected $testroot/stderr
347 ret="$?"
348 if [ "$ret" != "0" ]; then
349 diff -u $testroot/stderr.expected $testroot/stderr
350 fi
351 test_done "$testroot" "$ret"
354 function test_log_end_at_commit {
355 local testroot=`test_init log_end_at_commit`
356 local commit_id0=`git_show_head $testroot/repo`
358 got checkout $testroot/repo $testroot/wt > /dev/null
359 ret="$?"
360 if [ "$ret" != "0" ]; then
361 test_done "$testroot" "$ret"
362 return 1
363 fi
365 echo "modified alpha" > $testroot/wt/alpha
366 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
367 local commit_id1=`git_show_head $testroot/repo`
369 (cd $testroot/wt && got rm beta >/dev/null)
370 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
371 local commit_id2=`git_show_head $testroot/repo`
373 echo "new file" > $testroot/wt/new
374 (cd $testroot/wt && got add new >/dev/null)
375 (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
376 local commit_id3=`git_show_head $testroot/repo`
378 # Print commit 3 only
379 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
380 (cd $testroot/wt && got log -x $commit_id3 | grep ^commit \
381 > $testroot/stdout)
382 cmp -s $testroot/stdout.expected $testroot/stdout
383 ret="$?"
384 if [ "$ret" != "0" ]; then
385 diff -u $testroot/stdout.expected $testroot/stdout
386 test_done "$testroot" "$ret"
387 return 1
388 fi
390 # Print commit 3 up to commit 1 inclusive
391 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
392 echo "commit $commit_id2" >> $testroot/stdout.expected
393 echo "commit $commit_id1" >> $testroot/stdout.expected
394 (cd $testroot/wt && got log -c $commit_id3 -x $commit_id1 | \
395 grep ^commit > $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 # Create commits on an unrelated branch
405 (cd $testroot/wt && got br foo > /dev/null)
406 echo bar >> $testroot/wt/alpha
407 (cd $testroot/wt && got commit -m "change on branch foo" >/dev/null)
408 local commit_id4=`git_show_branch_head $testroot/repo foo`
410 # Print commit 4 only (in work tree)
411 echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
412 (cd $testroot/wt && got log -x foo | grep ^commit \
413 > $testroot/stdout)
414 cmp -s $testroot/stdout.expected $testroot/stdout
415 ret="$?"
416 if [ "$ret" != "0" ]; then
417 diff -u $testroot/stdout.expected $testroot/stdout
418 test_done "$testroot" "$ret"
419 return 1
420 fi
422 # Print commit 4 only (in repository)
423 echo "commit $commit_id4 (foo)" > $testroot/stdout.expected
424 (cd $testroot/repo && got log -c foo -x foo | grep ^commit \
425 > $testroot/stdout)
426 cmp -s $testroot/stdout.expected $testroot/stdout
427 ret="$?"
428 if [ "$ret" != "0" ]; then
429 diff -u $testroot/stdout.expected $testroot/stdout
430 test_done "$testroot" "$ret"
431 return 1
432 fi
434 # Repository's HEAD is on master branch so -x foo without an explicit
435 # '-c foo' start commit has no effect there
436 echo "commit $commit_id3 (master)" > $testroot/stdout.expected
437 echo "commit $commit_id2" >> $testroot/stdout.expected
438 echo "commit $commit_id1" >> $testroot/stdout.expected
439 echo "commit $commit_id0" >> $testroot/stdout.expected
440 (cd $testroot/repo && got log -x foo | grep ^commit \
441 > $testroot/stdout)
442 cmp -s $testroot/stdout.expected $testroot/stdout
443 ret="$?"
444 if [ "$ret" != "0" ]; then
445 diff -u $testroot/stdout.expected $testroot/stdout
446 test_done "$testroot" "$ret"
447 return 1
448 fi
450 # got will refuse -x with a non-existent commit
451 (cd $testroot/wt && got log -x nonexistent \
452 > $testroot/stdout 2> $testroot/stderr)
453 ret="$?"
454 if [ "$ret" == "0" ]; then
455 echo "log command succeeded unexpectedly" >&2
456 test_done "$testroot" "1"
457 return 1
458 fi
459 echo -n > $testroot/stdout.expected
460 echo "got: nonexistent: bad object id string" \
461 > $testroot/stderr.expected
462 cmp -s $testroot/stderr.expected $testroot/stderr
463 ret="$?"
464 if [ "$ret" != "0" ]; then
465 diff -u $testroot/stderr.expected $testroot/stderr
466 test_done "$testroot" "$ret"
467 return 1
468 fi
469 cmp -s $testroot/stdout.expected $testroot/stdout
470 ret="$?"
471 if [ "$ret" != "0" ]; then
472 diff -u $testroot/stdout.expected $testroot/stdout
473 test_done "$testroot" "$ret"
474 return 1
475 fi
477 # try the same with the hash of an empty string which is very
478 # unlikely to match any object
479 local empty_sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709
480 (cd $testroot/wt && got log -x $empty_sha1 \
481 > $testroot/stdout 2> $testroot/stderr)
482 ret="$?"
483 if [ "$ret" == "0" ]; then
484 echo "log command succeeded unexpectedly" >&2
485 test_done "$testroot" "1"
486 return 1
487 fi
488 echo -n > $testroot/stdout.expected
489 echo "got: $empty_sha1: object not found" > $testroot/stderr.expected
490 cmp -s $testroot/stderr.expected $testroot/stderr
491 ret="$?"
492 if [ "$ret" != "0" ]; then
493 diff -u $testroot/stderr.expected $testroot/stderr
494 test_done "$testroot" "$ret"
495 return 1
496 fi
497 cmp -s $testroot/stdout.expected $testroot/stdout
498 ret="$?"
499 if [ "$ret" != "0" ]; then
500 diff -u $testroot/stdout.expected $testroot/stdout
501 test_done "$testroot" "$ret"
502 return 1
503 fi
505 test_done "$testroot" "0"
508 function test_log_reverse_display {
509 local testroot=`test_init log_reverse_display`
510 local commit_id0=`git_show_head $testroot/repo`
512 got checkout $testroot/repo $testroot/wt > /dev/null
513 ret="$?"
514 if [ "$ret" != "0" ]; then
515 test_done "$testroot" "$ret"
516 return 1
517 fi
519 echo "modified alpha" > $testroot/wt/alpha
520 (cd $testroot/wt && got commit -m 'commit1' > /dev/null)
521 local commit_id1=`git_show_head $testroot/repo`
523 (cd $testroot/wt && got rm beta >/dev/null)
524 (cd $testroot/wt && got commit -m 'commit2' > /dev/null)
525 local commit_id2=`git_show_head $testroot/repo`
527 echo "new file" > $testroot/wt/new
528 (cd $testroot/wt && got add new >/dev/null)
529 (cd $testroot/wt && got commit -m 'commit3' > /dev/null)
530 local commit_id3=`git_show_head $testroot/repo`
532 # -R alone should display all commits in reverse
533 echo "commit $commit_id0" > $testroot/stdout.expected
534 echo "commit $commit_id1" >> $testroot/stdout.expected
535 echo "commit $commit_id2" >> $testroot/stdout.expected
536 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
537 (cd $testroot/wt && got log -R | grep ^commit > $testroot/stdout)
538 cmp -s $testroot/stdout.expected $testroot/stdout
539 ret="$?"
540 if [ "$ret" != "0" ]; then
541 diff -u $testroot/stdout.expected $testroot/stdout
542 test_done "$testroot" "$ret"
543 return 1
544 fi
546 # -R takes effect after the -l commit traversal limit
547 echo "commit $commit_id2" > $testroot/stdout.expected
548 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
549 (cd $testroot/wt && got log -R -l2 | grep ^commit > $testroot/stdout)
550 cmp -s $testroot/stdout.expected $testroot/stdout
551 ret="$?"
552 if [ "$ret" != "0" ]; then
553 diff -u $testroot/stdout.expected $testroot/stdout
554 test_done "$testroot" "$ret"
555 return 1
556 fi
558 # -R works with commit ranges specified via -c and -x
559 echo "commit $commit_id1" > $testroot/stdout.expected
560 echo "commit $commit_id2" >> $testroot/stdout.expected
561 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
562 (cd $testroot/wt && got log -R -c $commit_id3 -x $commit_id1 | \
563 grep ^commit > $testroot/stdout)
564 cmp -s $testroot/stdout.expected $testroot/stdout
565 ret="$?"
566 if [ "$ret" != "0" ]; then
567 diff -u $testroot/stdout.expected $testroot/stdout
568 test_done "$testroot" "$ret"
569 fi
571 # commit matching with -s applies before -R
572 echo "commit $commit_id1" > $testroot/stdout.expected
573 echo "commit $commit_id2" >> $testroot/stdout.expected
574 (cd $testroot/wt && got log -R -s 'commit[12]' | \
575 grep ^commit > $testroot/stdout)
576 cmp -s $testroot/stdout.expected $testroot/stdout
577 ret="$?"
578 if [ "$ret" != "0" ]; then
579 diff -u $testroot/stdout.expected $testroot/stdout
580 test_done "$testroot" "$ret"
581 return 1
582 fi
584 # -R works in combination with -P
585 echo "" > $testroot/stdout.expected
586 (cd $testroot/wt && got log -R -P | grep -E '^(commit| [MDmA])' \
587 > $testroot/stdout)
588 echo "commit $commit_id0" > $testroot/stdout.expected
589 echo " A alpha" >> $testroot/stdout.expected
590 echo " A beta" >> $testroot/stdout.expected
591 echo " A epsilon/zeta" >> $testroot/stdout.expected
592 echo " A gamma/delta" >> $testroot/stdout.expected
593 echo "commit $commit_id1" >> $testroot/stdout.expected
594 echo " M alpha" >> $testroot/stdout.expected
595 echo "commit $commit_id2" >> $testroot/stdout.expected
596 echo " D beta" >> $testroot/stdout.expected
597 echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
598 echo " A new" >> $testroot/stdout.expected
599 cmp -s $testroot/stdout.expected $testroot/stdout
600 ret="$?"
601 if [ "$ret" != "0" ]; then
602 diff -u $testroot/stdout.expected $testroot/stdout
603 fi
604 test_done "$testroot" "$ret"
607 function test_log_in_worktree_different_repo {
608 local testroot=`test_init log_in_worktree_different_repo 1`
610 make_test_tree $testroot/repo
611 mkdir -p $testroot/repo/epsilon/d
612 echo foo > $testroot/repo/epsilon/d/foo
613 (cd $testroot/repo && git add .)
614 git_commit $testroot/repo -m "adding the test tree"
615 local head_commit=`git_show_head $testroot/repo`
617 got init $testroot/other-repo
618 mkdir -p $testroot/tree
619 make_test_tree $testroot/tree
620 got import -mm -b foo -r $testroot/other-repo $testroot/tree >/dev/null
621 got checkout -b foo $testroot/other-repo $testroot/wt > /dev/null
622 ret="$?"
623 if [ "$ret" != "0" ]; then
624 test_done "$testroot" "$ret"
625 return 1
626 fi
628 echo "commit $head_commit (master)" > $testroot/stdout.expected
630 # 'got log' used to fail with "reference refs/heads/foo not found"
631 # even though that reference belongs to an unrelated repository
632 # found via a worktree via the current working directory
633 for p in "" alpha epsilon; do
634 (cd $testroot/wt && got log -r $testroot/repo $p | \
635 grep ^commit > $testroot/stdout)
636 cmp -s $testroot/stdout.expected $testroot/stdout
637 ret="$?"
638 if [ "$ret" != "0" ]; then
639 diff -u $testroot/stdout.expected $testroot/stdout
640 test_done "$testroot" "$ret"
641 return 1
642 fi
643 done
645 for p in "" epsilon/zeta; do
646 (cd $testroot/wt/epsilon && got log -r $testroot/repo $p | \
647 grep ^commit > $testroot/stdout)
648 cmp -s $testroot/stdout.expected $testroot/stdout
649 ret="$?"
650 if [ "$ret" != "0" ]; then
651 diff -u $testroot/stdout.expected $testroot/stdout
652 test_done "$testroot" "$ret"
653 return 1
654 fi
655 done
657 for p in "" foo; do
658 (cd $testroot/wt/epsilon && got log -r $testroot/repo epsilon/d/$p | \
659 grep ^commit > $testroot/stdout)
660 cmp -s $testroot/stdout.expected $testroot/stdout
661 ret="$?"
662 if [ "$ret" != "0" ]; then
663 diff -u $testroot/stdout.expected $testroot/stdout
664 test_done "$testroot" "$ret"
665 return 1
666 fi
667 done
669 test_done "$testroot" "0"
672 function test_log_changed_paths {
673 local testroot=`test_init log_changed_paths`
674 local commit_id0=`git_show_head $testroot/repo`
676 got checkout $testroot/repo $testroot/wt > /dev/null
677 ret="$?"
678 if [ "$ret" != "0" ]; then
679 test_done "$testroot" "$ret"
680 return 1
681 fi
683 echo "modified alpha" > $testroot/wt/alpha
684 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
685 local commit_id1=`git_show_head $testroot/repo`
687 (cd $testroot/wt && got rm beta >/dev/null)
688 (cd $testroot/wt && chmod +x epsilon/zeta >/dev/null)
689 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
690 local commit_id2=`git_show_head $testroot/repo`
692 echo "new file" > $testroot/wt/new
693 (cd $testroot/wt && got add new >/dev/null)
694 (cd $testroot/wt && got commit -m 'test log_changed_paths' > /dev/null)
695 local commit_id3=`git_show_head $testroot/repo`
697 (cd $testroot/wt && got log -P | grep '^ [MDmA]' > $testroot/stdout)
699 echo " A new" > $testroot/stdout.expected
700 echo " D beta" >> $testroot/stdout.expected
701 echo " m epsilon/zeta" >> $testroot/stdout.expected
702 echo " M alpha" >> $testroot/stdout.expected
703 echo " A alpha" >> $testroot/stdout.expected
704 echo " A beta" >> $testroot/stdout.expected
705 echo " A epsilon/zeta" >> $testroot/stdout.expected
706 echo " A gamma/delta" >> $testroot/stdout.expected
708 cmp -s $testroot/stdout.expected $testroot/stdout
709 ret="$?"
710 if [ "$ret" != "0" ]; then
711 diff -u $testroot/stdout.expected $testroot/stdout
712 fi
713 test_done "$testroot" "$ret"
716 function test_log_submodule {
717 local testroot=`test_init log_submodule`
719 make_single_file_repo $testroot/repo2 foo
721 (cd $testroot/repo && git submodule -q add ../repo2)
722 (cd $testroot/repo && git commit -q -m 'adding submodule')
723 local head_commit=`git_show_head $testroot/repo`
725 echo "commit $head_commit (master)" > $testroot/stdout.expected
727 got log -r $testroot/repo -l1 repo2 | grep ^commit > $testroot/stdout
728 cmp -s $testroot/stdout.expected $testroot/stdout
729 ret="$?"
730 if [ "$ret" != "0" ]; then
731 diff -u $testroot/stdout.expected $testroot/stdout
732 test_done "$testroot" "$ret"
733 return 1
734 fi
736 echo " A .gitmodules" > $testroot/stdout.expected
738 got log -r $testroot/repo -l1 -P repo2 | grep '^ [MDmA]' \
739 > $testroot/stdout
740 cmp -s $testroot/stdout.expected $testroot/stdout
741 ret="$?"
742 if [ "$ret" != "0" ]; then
743 diff -u $testroot/stdout.expected $testroot/stdout
744 test_done "$testroot" "$ret"
745 return 1
746 fi
748 got log -p -r $testroot/repo -l1 repo2 \
749 > $testroot/stdout 2> $testroot/stderr
750 ret="$?"
751 if [ "$ret" == "0" ]; then
752 echo "log command succeeded unexpectedly" >&2
753 test_done "$testroot" "1"
754 return 1
755 fi
756 local submodule_id=$(got tree -r $testroot/repo -i | \
757 grep 'repo2\$$' | cut -d ' ' -f1)
758 echo "got: object $submodule_id not found" > $testroot/stderr.expected
760 cmp -s $testroot/stderr.expected $testroot/stderr
761 ret="$?"
762 if [ "$ret" != "0" ]; then
763 diff -u $testroot/stderr.expected $testroot/stderr
764 test_done "$testroot" "$ret"
765 return 1
766 fi
768 echo "modified foo" > $testroot/repo2/foo
769 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
771 # Update the repo/repo2 submodule link
772 (cd $testroot/repo && git -C repo2 pull -q)
773 (cd $testroot/repo && git add repo2)
774 git_commit $testroot/repo -m "changed submodule link"
776 # log -P does not show the changed submodule path
777 got log -P -r $testroot/repo -l1 repo2 > $testroot/stdout.full
778 ret="$?"
779 if [ "$ret" != "0" ]; then
780 echo "log command failed unexpectedly" >&2
781 test_done "$testroot" "1"
782 return 1
783 fi
784 grep '^ [MDmA]' $testroot/stdout.full > $testroot/stdout
786 echo -n > $testroot/stdout.expected
787 cmp -s $testroot/stdout.expected $testroot/stdout
788 ret="$?"
789 if [ "$ret" != "0" ]; then
790 diff -u $testroot/stdout.expected $testroot/stdout
791 fi
792 test_done "$testroot" "$ret"
795 test_parseargs "$@"
796 run_test test_log_in_repo
797 run_test test_log_in_bare_repo
798 run_test test_log_in_worktree
799 run_test test_log_in_worktree_with_path_prefix
800 run_test test_log_tag
801 run_test test_log_limit
802 run_test test_log_patch_added_file
803 run_test test_log_nonexistent_path
804 run_test test_log_end_at_commit
805 run_test test_log_reverse_display
806 run_test test_log_in_worktree_different_repo
807 run_test test_log_changed_paths
808 run_test test_log_submodule