3 # Copyright (c) 2020 Google LLC
6 test_description
='reftable basics'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 GIT_TEST_DEFAULT_REF_FORMAT
=reftable
11 export GIT_TEST_DEFAULT_REF_FORMAT
13 TEST_PASSES_SANITIZE_LEAK
=true
16 INVALID_OID
=$
(test_oid
001)
18 test_expect_success
'init: creates basic reftable structures' '
19 test_when_finished "rm -rf repo" &&
21 test_path_is_dir repo/.git/reftable &&
22 test_path_is_file repo/.git/reftable/tables.list &&
23 echo reftable >expect &&
24 git -C repo rev-parse --show-ref-format >actual &&
25 test_cmp expect actual
28 test_expect_success
'init: sha256 object format via environment variable' '
29 test_when_finished "rm -rf repo" &&
30 GIT_DEFAULT_HASH=sha256 git init repo &&
35 git -C repo rev-parse --show-object-format --show-ref-format >actual &&
36 test_cmp expect actual
39 test_expect_success
'init: sha256 object format via option' '
40 test_when_finished "rm -rf repo" &&
41 git init --object-format=sha256 repo &&
46 git -C repo rev-parse --show-object-format --show-ref-format >actual &&
47 test_cmp expect actual
50 test_expect_success
'init: reinitializing reftable backend succeeds' '
51 test_when_finished "rm -rf repo" &&
53 test_commit -C repo A &&
55 git -C repo for-each-ref >expect &&
56 git init --ref-format=reftable repo &&
57 git -C repo for-each-ref >actual &&
58 test_cmp expect actual
61 test_expect_success
'init: reinitializing files with reftable backend fails' '
62 test_when_finished "rm -rf repo" &&
63 git init --ref-format=files repo &&
64 test_commit -C repo file &&
66 cp repo/.git/HEAD expect &&
67 test_must_fail git init --ref-format=reftable repo &&
68 test_cmp expect repo/.git/HEAD
71 test_expect_success
'init: reinitializing reftable with files backend fails' '
72 test_when_finished "rm -rf repo" &&
73 git init --ref-format=reftable repo &&
74 test_commit -C repo file &&
76 cp repo/.git/HEAD expect &&
77 test_must_fail git init --ref-format=files repo &&
78 test_cmp expect repo/.git/HEAD
81 test_expect_perms
() {
84 local actual
="$(ls -l "$file")" &&
91 echo "$(basename $2) is not $perms but $actual"
97 test_expect_reftable_perms
() {
102 test_expect_success POSIXPERM
"init: honors --shared=$shared with umask $umask" '
103 test_when_finished "rm -rf repo" &&
106 git init --shared=$shared repo
108 test_expect_perms "$expect" repo/.git/reftable/tables.list &&
109 for table in repo/.git/reftable/*.ref
111 test_expect_perms "$expect" "$table" ||
116 test_expect_success POSIXPERM
"pack-refs: honors --shared=$shared with umask $umask" '
117 test_when_finished "rm -rf repo" &&
120 git init --shared=$shared repo &&
121 test_commit -C repo A &&
122 test_line_count = 2 repo/.git/reftable/tables.list &&
123 git -C repo pack-refs
125 test_expect_perms "$expect" repo/.git/reftable/tables.list &&
126 for table in repo/.git/reftable/*.ref
128 test_expect_perms "$expect" "$table" ||
134 test_expect_reftable_perms
002 umask "-rw-rw-r--"
135 test_expect_reftable_perms
022 umask "-rw-r--r--"
136 test_expect_reftable_perms
027 umask "-rw-r-----"
138 test_expect_reftable_perms
002 group
"-rw-rw-r--"
139 test_expect_reftable_perms
022 group
"-rw-rw-r--"
140 test_expect_reftable_perms
027 group
"-rw-rw----"
142 test_expect_reftable_perms
002 world
"-rw-rw-r--"
143 test_expect_reftable_perms
022 world
"-rw-rw-r--"
144 test_expect_reftable_perms
027 world
"-rw-rw-r--"
146 test_expect_success
'clone: can clone reftable repository' '
147 test_when_finished "rm -rf repo clone" &&
149 test_commit -C repo message1 file1 &&
151 git clone repo cloned &&
152 echo reftable >expect &&
153 git -C cloned rev-parse --show-ref-format >actual &&
154 test_cmp expect actual &&
155 test_path_is_file cloned/file1
158 test_expect_success
'clone: can clone reffiles into reftable repository' '
159 test_when_finished "rm -rf reffiles reftable" &&
160 git init --ref-format=files reffiles &&
161 test_commit -C reffiles A &&
162 git clone --ref-format=reftable ./reffiles reftable &&
164 git -C reffiles rev-parse HEAD >expect &&
165 git -C reftable rev-parse HEAD >actual &&
166 test_cmp expect actual &&
168 git -C reftable rev-parse --show-ref-format >actual &&
169 echo reftable >expect &&
170 test_cmp expect actual &&
172 git -C reffiles rev-parse --show-ref-format >actual &&
173 echo files >expect &&
174 test_cmp expect actual
177 test_expect_success
'clone: can clone reftable into reffiles repository' '
178 test_when_finished "rm -rf reffiles reftable" &&
179 git init --ref-format=reftable reftable &&
180 test_commit -C reftable A &&
181 git clone --ref-format=files ./reftable reffiles &&
183 git -C reftable rev-parse HEAD >expect &&
184 git -C reffiles rev-parse HEAD >actual &&
185 test_cmp expect actual &&
187 git -C reftable rev-parse --show-ref-format >actual &&
188 echo reftable >expect &&
189 test_cmp expect actual &&
191 git -C reffiles rev-parse --show-ref-format >actual &&
192 echo files >expect &&
193 test_cmp expect actual
196 test_expect_success
'ref transaction: corrupted tables cause failure' '
197 test_when_finished "rm -rf repo" &&
202 for f in .git/reftable/*.ref
206 test_must_fail git update-ref refs/heads/main HEAD
210 test_expect_success
'ref transaction: corrupted tables.list cause failure' '
211 test_when_finished "rm -rf repo" &&
216 echo garbage >.git/reftable/tables.list &&
217 test_must_fail git update-ref refs/heads/main HEAD
221 test_expect_success
'ref transaction: refuses to write ref causing F/D conflict' '
222 test_when_finished "rm -rf repo" &&
224 test_commit -C repo file &&
225 test_must_fail git -C repo update-ref refs/heads/main/forbidden
228 test_expect_success
'ref transaction: deleting ref with invalid name fails' '
229 test_when_finished "rm -rf repo" &&
231 test_commit -C repo file &&
232 test_must_fail git -C repo update-ref -d ../../my-private-file
235 test_expect_success
'ref transaction: can skip object ID verification' '
236 test_when_finished "rm -rf repo" &&
238 test_must_fail test-tool -C repo ref-store main update-ref msg refs/heads/branch $INVALID_OID $ZERO_OID 0 &&
239 test-tool -C repo ref-store main update-ref msg refs/heads/branch $INVALID_OID $ZERO_OID REF_SKIP_OID_VERIFICATION
242 test_expect_success
'ref transaction: updating same ref multiple times fails' '
243 test_when_finished "rm -rf repo" &&
245 test_commit -C repo A &&
246 cat >updates <<-EOF &&
247 update refs/heads/main $A
248 update refs/heads/main $A
250 cat >expect <<-EOF &&
251 fatal: multiple updates for ref ${SQ}refs/heads/main${SQ} not allowed
253 test_must_fail git -C repo update-ref --stdin <updates 2>err &&
257 test_expect_success
'ref transaction: can delete symbolic self-reference with git-symbolic-ref(1)' '
258 test_when_finished "rm -rf repo" &&
260 git -C repo symbolic-ref refs/heads/self refs/heads/self &&
261 git -C repo symbolic-ref -d refs/heads/self
264 test_expect_success
'ref transaction: deleting symbolic self-reference without --no-deref fails' '
265 test_when_finished "rm -rf repo" &&
267 git -C repo symbolic-ref refs/heads/self refs/heads/self &&
268 cat >expect <<-EOF &&
269 error: multiple updates for ${SQ}refs/heads/self${SQ} (including one via symref ${SQ}refs/heads/self${SQ}) are not allowed
271 test_must_fail git -C repo update-ref -d refs/heads/self 2>err &&
275 test_expect_success
'ref transaction: deleting symbolic self-reference with --no-deref succeeds' '
276 test_when_finished "rm -rf repo" &&
278 git -C repo symbolic-ref refs/heads/self refs/heads/self &&
279 git -C repo update-ref -d --no-deref refs/heads/self
282 test_expect_success
'ref transaction: creating symbolic ref fails with F/D conflict' '
283 test_when_finished "rm -rf repo" &&
285 test_commit -C repo A &&
286 cat >expect <<-EOF &&
287 error: ${SQ}refs/heads/main${SQ} exists; cannot create ${SQ}refs/heads${SQ}
289 test_must_fail git -C repo symbolic-ref refs/heads refs/heads/foo 2>err &&
293 test_expect_success
'ref transaction: ref deletion' '
294 test_when_finished "rm -rf repo" &&
299 HEAD_OID=$(git show-ref -s --verify HEAD) &&
300 cat >expect <<-EOF &&
301 $HEAD_OID refs/heads/main
302 $HEAD_OID refs/tags/file
304 git show-ref >actual &&
305 test_cmp expect actual &&
307 test_must_fail git update-ref -d refs/tags/file $INVALID_OID &&
308 git show-ref >actual &&
309 test_cmp expect actual &&
311 git update-ref -d refs/tags/file $HEAD_OID &&
312 echo "$HEAD_OID refs/heads/main" >expect &&
313 git show-ref >actual &&
314 test_cmp expect actual
318 test_expect_success
'ref transaction: writes cause auto-compaction' '
319 test_when_finished "rm -rf repo" &&
322 test_line_count = 1 repo/.git/reftable/tables.list &&
324 test_commit -C repo --no-tag A &&
325 test_line_count = 1 repo/.git/reftable/tables.list &&
327 test_commit -C repo --no-tag B &&
328 test_line_count = 1 repo/.git/reftable/tables.list
331 test_expect_success
'ref transaction: env var disables compaction' '
332 test_when_finished "rm -rf repo" &&
335 test_commit -C repo A &&
337 start=$(wc -l <repo/.git/reftable/tables.list) &&
339 expected=$((start + iterations)) &&
341 for i in $(test_seq $iterations)
343 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
344 git -C repo update-ref branch-$i HEAD || return 1
346 test_line_count = $expected repo/.git/reftable/tables.list &&
348 git -C repo update-ref foo HEAD &&
349 test_line_count -lt $expected repo/.git/reftable/tables.list
352 test_expect_success
'ref transaction: alternating table sizes are compacted' '
353 test_when_finished "rm -rf repo" &&
356 test_commit -C repo A &&
357 for i in $(test_seq 5)
359 git -C repo branch -f foo &&
360 git -C repo branch -d foo || return 1
362 test_line_count = 2 repo/.git/reftable/tables.list
365 check_fsync_events
() {
371 -e '/^{"event":"counter",.*"category":"fsync",/ {
372 s/.*"category":"fsync",//;
377 test_cmp expect actual
380 test_expect_success
'ref transaction: writes are synced' '
381 test_when_finished "rm -rf repo" &&
383 test_commit -C repo initial &&
385 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
386 GIT_TEST_FSYNC=true \
387 git -C repo -c core.fsync=reference \
388 -c core.fsyncMethod=fsync update-ref refs/heads/branch HEAD &&
389 check_fsync_events trace2.txt <<-EOF
390 "name":"hardware-flush","count":4
394 test_expect_success
'ref transaction: empty transaction in empty repo' '
395 test_when_finished "rm -rf repo" &&
397 test_commit -C repo --no-tag A &&
398 git -C repo update-ref -d refs/heads/main &&
399 test-tool -C repo ref-store main delete-refs REF_NO_DEREF msg HEAD &&
400 git -C repo update-ref --stdin <<-EOF
406 test_expect_success
'ref transaction: fails gracefully when auto compaction fails' '
407 test_when_finished "rm -rf repo" &&
413 for i in $(test_seq 10)
415 git branch branch-$i &&
416 for table in .git/reftable/*.ref
418 touch "$table.lock" || exit 1
422 test_line_count = 10 .git/reftable/tables.list
426 test_expect_success
'ref transaction: timeout acquiring tables.list lock' '
427 test_when_finished "rm -rf repo" &&
431 test_commit initial &&
432 >.git/reftable/tables.list.lock &&
433 test_must_fail git update-ref refs/heads/branch HEAD 2>err &&
434 test_grep "cannot lock references" err
438 test_expect_success
'ref transaction: retry acquiring tables.list lock' '
439 test_when_finished "rm -rf repo" &&
443 test_commit initial &&
444 LOCK=.git/reftable/tables.list.lock &&
447 ( sleep 1 && rm -f $LOCK ) &
449 git -c reftable.lockTimeout=5000 update-ref refs/heads/branch HEAD
453 # This test fails most of the time on Windows systems. The root cause is
454 # that Windows does not allow us to rename the "tables.list.lock" file into
455 # place when "tables.list" is open for reading by a concurrent process.
456 test_expect_success
!WINDOWS
'ref transaction: many concurrent writers' '
457 test_when_finished "rm -rf repo" &&
461 # Set a high timeout. While a couple of seconds should be
462 # plenty, using the address sanitizer will significantly slow
463 # us down here. So we are aiming way higher than you would ever
464 # think is necessary just to keep us from flaking. We could
465 # also lock indefinitely by passing -1, but that could
466 # potentially block CI jobs indefinitely if there was a bug
468 git config set reftable.lockTimeout 300000 &&
469 test_commit --no-tag initial &&
471 head=$(git rev-parse HEAD) &&
472 for i in $(test_seq 100)
474 printf "%s commit\trefs/heads/branch-%s\n" "$head" "$i" ||
477 printf "%s commit\trefs/heads/main\n" "$head" >>expect &&
479 for i in $(test_seq 100)
481 { git update-ref refs/heads/branch-$i HEAD& } ||
486 git for-each-ref --sort=v:refname >actual &&
487 test_cmp expect actual
491 test_expect_success
'pack-refs: compacts tables' '
492 test_when_finished "rm -rf repo" &&
495 test_commit -C repo A &&
496 ls -1 repo/.git/reftable >table-files &&
497 test_line_count = 3 table-files &&
498 test_line_count = 2 repo/.git/reftable/tables.list &&
500 git -C repo pack-refs &&
501 ls -1 repo/.git/reftable >table-files &&
502 test_line_count = 2 table-files &&
503 test_line_count = 1 repo/.git/reftable/tables.list
506 test_expect_success
'pack-refs: compaction raises locking errors' '
507 test_when_finished "rm -rf repo" &&
509 test_commit -C repo A &&
510 touch repo/.git/reftable/tables.list.lock &&
511 cat >expect <<-EOF &&
512 error: unable to compact stack: data is locked
514 test_must_fail git -C repo pack-refs 2>err &&
518 for command in pack-refs gc
"maintenance run --task=pack-refs"
520 test_expect_success
"$command: auto compaction" '
521 test_when_finished "rm -rf repo" &&
528 # We need a bit of setup to ensure that git-gc(1) actually
529 # triggers, and that it does not write anything to the refdb.
530 git config gc.auto 1 &&
531 git config gc.autoDetach 0 &&
532 git config gc.reflogExpire never &&
533 git config gc.reflogExpireUnreachable never &&
534 test_oid blob17_1 | git hash-object -w --stdin &&
536 # The tables should have been auto-compacted, and thus auto
537 # compaction should not have to do anything.
538 ls -1 .git/reftable >tables-expect &&
539 test_line_count = 3 tables-expect &&
540 git $command --auto &&
541 ls -1 .git/reftable >tables-actual &&
542 test_cmp tables-expect tables-actual &&
544 test_oid blob17_2 | git hash-object -w --stdin &&
546 # Lock all tables, write some refs. Auto-compaction will be
547 # unable to compact tables and thus fails gracefully,
548 # compacting only those tables which are not locked.
549 ls .git/reftable/*.ref | sort |
552 touch "$table.lock" &&
553 basename "$table" >>tables.expect || exit 1
555 test_line_count = 2 .git/reftable/tables.list &&
559 # The new tables are auto-compacted, but the locked tables are
561 test_line_count = 3 .git/reftable/tables.list &&
562 head -n 2 .git/reftable/tables.list >tables.head &&
563 test_cmp tables.expect tables.head &&
565 rm .git/reftable/*.lock &&
566 git $command --auto &&
567 test_line_count = 1 .git/reftable/tables.list
572 test_expect_success
'pack-refs: prunes stale tables' '
573 test_when_finished "rm -rf repo" &&
575 touch repo/.git/reftable/stale-table.ref &&
576 git -C repo pack-refs &&
577 test_path_is_missing repo/.git/reftable/stable-ref.ref
580 test_expect_success
'pack-refs: does not prune non-table files' '
581 test_when_finished "rm -rf repo" &&
583 touch repo/.git/reftable/garbage &&
584 git -C repo pack-refs &&
585 test_path_is_file repo/.git/reftable/garbage
588 test_expect_success
'packed-refs: writes are synced' '
589 test_when_finished "rm -rf repo" &&
591 test_commit -C repo initial &&
592 test_line_count = 2 table-files &&
595 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
596 GIT_TEST_FSYNC=true \
597 git -C repo -c core.fsync=reference \
598 -c core.fsyncMethod=fsync pack-refs &&
599 check_fsync_events trace2.txt <<-EOF
600 "name":"hardware-flush","count":2
604 test_expect_success
'ref iterator: bogus names are flagged' '
605 test_when_finished "rm -rf repo" &&
609 test_commit --no-tag file &&
610 test-tool ref-store main update-ref msg "refs/heads/bogus..name" $(git rev-parse HEAD) $ZERO_OID REF_SKIP_REFNAME_VERIFICATION &&
612 cat >expect <<-EOF &&
613 $ZERO_OID refs/heads/bogus..name 0xc
614 $(git rev-parse HEAD) refs/heads/main 0x0
616 test-tool ref-store main for-each-ref "" >actual &&
617 test_cmp expect actual
621 test_expect_success
'ref iterator: missing object IDs are not flagged' '
622 test_when_finished "rm -rf repo" &&
626 test-tool ref-store main update-ref msg "refs/heads/broken-hash" $INVALID_OID $ZERO_OID REF_SKIP_OID_VERIFICATION &&
628 cat >expect <<-EOF &&
629 $INVALID_OID refs/heads/broken-hash 0x0
631 test-tool ref-store main for-each-ref "" >actual &&
632 test_cmp expect actual
636 test_expect_success
'basic: commit and list refs' '
637 test_when_finished "rm -rf repo" &&
639 test_commit -C repo file &&
640 test_write_lines refs/heads/main refs/tags/file >expect &&
641 git -C repo for-each-ref --format="%(refname)" >actual &&
642 test_cmp actual expect
645 test_expect_success
'basic: can write large commit message' '
646 test_when_finished "rm -rf repo" &&
649 print \"this is a long commit message\" x 50000
651 git -C repo commit --allow-empty --file=../commit-msg
654 test_expect_success
'basic: show-ref fails with empty repository' '
655 test_when_finished "rm -rf repo" &&
657 test_must_fail git -C repo show-ref >actual &&
658 test_must_be_empty actual
661 test_expect_success
'basic: can check out unborn branch' '
662 test_when_finished "rm -rf repo" &&
664 git -C repo checkout -b main
667 test_expect_success
'basic: peeled tags are stored' '
668 test_when_finished "rm -rf repo" &&
670 test_commit -C repo file &&
671 git -C repo tag -m "annotated tag" test_tag HEAD &&
672 for ref in refs/heads/main refs/tags/file refs/tags/test_tag refs/tags/test_tag^{}
674 echo "$(git -C repo rev-parse "$ref") $ref" || return 1
676 git -C repo show-ref -d >actual &&
677 test_cmp expect actual
680 test_expect_success
'basic: for-each-ref can print symrefs' '
681 test_when_finished "rm -rf repo" &&
687 git symbolic-ref refs/heads/sym refs/heads/main &&
688 cat >expected <<-EOF &&
691 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
692 test_cmp expected actual
696 test_expect_success
'basic: notes' '
697 test_when_finished "rm -rf repo" &&
700 write_script fake_editor <<-\EOF &&
707 GIT_EDITOR=./fake_editor MSG=b4 git notes add &&
708 GIT_EDITOR=./fake_editor MSG=b3 git notes edit &&
710 git notes --ref commits@{1} show >actual &&
711 test_cmp expect actual
715 test_expect_success
'basic: stash' '
716 test_when_finished "rm -rf repo" &&
721 git stash list >expect &&
722 test_line_count = 0 expect &&
725 git stash push -m stashed &&
726 git stash list >expect &&
727 test_line_count = 1 expect &&
730 git stash list >expect &&
731 test_line_count = 0 expect
735 test_expect_success
'basic: cherry-pick' '
736 test_when_finished "rm -rf repo" &&
740 test_commit message1 file1 &&
741 test_commit message2 file2 &&
743 git checkout HEAD^ &&
744 test_commit message3 file3 &&
745 git cherry-pick source &&
746 test_path_is_file file2
750 test_expect_success
'basic: rebase' '
751 test_when_finished "rm -rf repo" &&
755 test_commit message1 file1 &&
756 test_commit message2 file2 &&
758 git checkout HEAD^ &&
759 test_commit message3 file3 &&
761 test_path_is_file file2
765 test_expect_success
'reflog: can delete separate reflog entries' '
766 test_when_finished "rm -rf repo" &&
775 git reflog >actual &&
778 git reflog delete HEAD@{1} &&
779 git reflog >actual &&
784 test_expect_success
'reflog: can switch to previous branch' '
785 test_when_finished "rm -rf repo" &&
790 git checkout -b branch1 &&
792 git checkout -b branch2 &&
794 git rev-parse --symbolic-full-name HEAD >actual &&
795 echo refs/heads/branch1 >expect &&
796 test_cmp actual expect
800 test_expect_success
'reflog: copying branch writes reflog entry' '
801 test_when_finished "rm -rf repo" &&
807 oid=$(git rev-parse --short HEAD) &&
809 cat >expect <<-EOF &&
810 ${oid} dst@{0}: Branch: copied refs/heads/src to refs/heads/dst
811 ${oid} dst@{1}: branch: Created from main
813 git branch -c src dst &&
814 git reflog dst >actual &&
815 test_cmp expect actual
819 test_expect_success
'reflog: renaming branch writes reflog entry' '
820 test_when_finished "rm -rf repo" &&
824 git symbolic-ref HEAD refs/heads/before &&
826 git show-ref >expected.refs &&
827 sed s/before/after/g <expected.refs >expected &&
828 git branch -M after &&
829 git show-ref >actual &&
830 test_cmp expected actual &&
831 echo refs/heads/after >expected &&
832 git symbolic-ref HEAD >actual &&
833 test_cmp expected actual
837 test_expect_success
'reflog: can store empty logs' '
838 test_when_finished "rm -rf repo" &&
843 test_must_fail test-tool ref-store main reflog-exists refs/heads/branch &&
844 test-tool ref-store main create-reflog refs/heads/branch &&
845 test-tool ref-store main reflog-exists refs/heads/branch &&
846 test-tool ref-store main for-each-reflog-ent-reverse refs/heads/branch >actual &&
847 test_must_be_empty actual
851 test_expect_success
'reflog: expiry empties reflog' '
852 test_when_finished "rm -rf repo" &&
857 test_commit initial &&
858 git checkout -b branch &&
862 cat >expect <<-EOF &&
865 branch: Created from HEAD
867 git reflog show --format="%gs" refs/heads/branch >actual &&
868 test_cmp expect actual &&
870 git reflog expire branch --expire=all &&
871 git reflog show --format="%gs" refs/heads/branch >actual &&
872 test_must_be_empty actual &&
873 test-tool ref-store main reflog-exists refs/heads/branch
877 test_expect_success
'reflog: can be deleted' '
878 test_when_finished "rm -rf repo" &&
882 test_commit initial &&
883 test-tool ref-store main reflog-exists refs/heads/main &&
884 test-tool ref-store main delete-reflog refs/heads/main &&
885 test_must_fail test-tool ref-store main reflog-exists refs/heads/main
889 test_expect_success
'reflog: garbage collection deletes reflog entries' '
890 test_when_finished "rm -rf repo" &&
895 for count in $(test_seq 1 10)
897 test_commit "number $count" file.t $count number-$count ||
900 git reflog refs/heads/main >actual &&
901 test_line_count = 10 actual &&
902 grep "commit (initial): number 1" actual &&
903 grep "commit: number 10" actual &&
906 git reflog refs/heads/main >actual &&
907 test_line_count = 0 actual
911 test_expect_success
'reflog: updates via HEAD update HEAD reflog' '
912 test_when_finished "rm -rf repo" &&
916 test_commit main-one &&
917 git checkout -b new-branch &&
918 test_commit new-one &&
919 test_commit new-two &&
921 echo new-one >expect &&
922 git log -1 --format=%s HEAD@{1} >actual &&
923 test_cmp expect actual
927 test_expect_success
'branch: copying branch with D/F conflict' '
928 test_when_finished "rm -rf repo" &&
934 cat >expect <<-EOF &&
935 error: ${SQ}refs/heads/branch${SQ} exists; cannot create ${SQ}refs/heads/branch/moved${SQ}
936 fatal: branch copy failed
938 test_must_fail git branch -c branch branch/moved 2>err &&
943 test_expect_success
'branch: moving branch with D/F conflict' '
944 test_when_finished "rm -rf repo" &&
950 git branch conflict &&
951 cat >expect <<-EOF &&
952 error: ${SQ}refs/heads/conflict${SQ} exists; cannot create ${SQ}refs/heads/conflict/moved${SQ}
953 fatal: branch rename failed
955 test_must_fail git branch -m branch conflict/moved 2>err &&
960 test_expect_success
'worktree: adding worktree creates separate stack' '
961 test_when_finished "rm -rf repo worktree" &&
963 test_commit -C repo A &&
965 git -C repo worktree add ../worktree &&
966 test_path_is_file repo/.git/worktrees/worktree/refs/heads &&
967 echo "ref: refs/heads/.invalid" >expect &&
968 test_cmp expect repo/.git/worktrees/worktree/HEAD &&
969 test_path_is_dir repo/.git/worktrees/worktree/reftable &&
970 test_path_is_file repo/.git/worktrees/worktree/reftable/tables.list
973 test_expect_success
'worktree: pack-refs in main repo packs main refs' '
974 test_when_finished "rm -rf repo worktree" &&
976 test_commit -C repo A &&
978 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
979 git -C repo worktree add ../worktree &&
980 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
981 git -C worktree update-ref refs/worktree/per-worktree HEAD &&
983 test_line_count = 4 repo/.git/worktrees/worktree/reftable/tables.list &&
984 test_line_count = 3 repo/.git/reftable/tables.list &&
985 git -C repo pack-refs &&
986 test_line_count = 4 repo/.git/worktrees/worktree/reftable/tables.list &&
987 test_line_count = 1 repo/.git/reftable/tables.list
990 test_expect_success
'worktree: pack-refs in worktree packs worktree refs' '
991 test_when_finished "rm -rf repo worktree" &&
993 test_commit -C repo A &&
995 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
996 git -C repo worktree add ../worktree &&
997 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
998 git -C worktree update-ref refs/worktree/per-worktree HEAD &&
1000 test_line_count = 4 repo/.git/worktrees/worktree/reftable/tables.list &&
1001 test_line_count = 3 repo/.git/reftable/tables.list &&
1002 git -C worktree pack-refs &&
1003 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
1004 test_line_count = 3 repo/.git/reftable/tables.list
1007 test_expect_success
'worktree: creating shared ref updates main stack' '
1008 test_when_finished "rm -rf repo worktree" &&
1010 test_commit -C repo A &&
1012 git -C repo worktree add ../worktree &&
1013 git -C repo pack-refs &&
1014 git -C worktree pack-refs &&
1015 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
1016 test_line_count = 1 repo/.git/reftable/tables.list &&
1018 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
1019 git -C worktree update-ref refs/heads/shared HEAD &&
1020 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
1021 test_line_count = 2 repo/.git/reftable/tables.list
1024 test_expect_success
'worktree: creating per-worktree ref updates worktree stack' '
1025 test_when_finished "rm -rf repo worktree" &&
1027 test_commit -C repo A &&
1029 git -C repo worktree add ../worktree &&
1030 git -C repo pack-refs &&
1031 git -C worktree pack-refs &&
1032 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
1033 test_line_count = 1 repo/.git/reftable/tables.list &&
1035 git -C worktree update-ref refs/bisect/per-worktree HEAD &&
1036 test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
1037 test_line_count = 1 repo/.git/reftable/tables.list
1040 test_expect_success
'worktree: creating per-worktree ref from main repo' '
1041 test_when_finished "rm -rf repo worktree" &&
1043 test_commit -C repo A &&
1045 git -C repo worktree add ../worktree &&
1046 git -C repo pack-refs &&
1047 git -C worktree pack-refs &&
1048 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
1049 test_line_count = 1 repo/.git/reftable/tables.list &&
1051 git -C repo update-ref worktrees/worktree/refs/bisect/per-worktree HEAD &&
1052 test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
1053 test_line_count = 1 repo/.git/reftable/tables.list
1056 test_expect_success
'worktree: creating per-worktree ref from second worktree' '
1057 test_when_finished "rm -rf repo wt1 wt2" &&
1059 test_commit -C repo A &&
1061 git -C repo worktree add ../wt1 &&
1062 git -C repo worktree add ../wt2 &&
1063 git -C repo pack-refs &&
1064 git -C wt1 pack-refs &&
1065 git -C wt2 pack-refs &&
1066 test_line_count = 1 repo/.git/worktrees/wt1/reftable/tables.list &&
1067 test_line_count = 1 repo/.git/worktrees/wt2/reftable/tables.list &&
1068 test_line_count = 1 repo/.git/reftable/tables.list &&
1070 git -C wt1 update-ref worktrees/wt2/refs/bisect/per-worktree HEAD &&
1071 test_line_count = 1 repo/.git/worktrees/wt1/reftable/tables.list &&
1072 test_line_count = 2 repo/.git/worktrees/wt2/reftable/tables.list &&
1073 test_line_count = 1 repo/.git/reftable/tables.list
1076 test_expect_success
'worktree: can create shared and per-worktree ref in one transaction' '
1077 test_when_finished "rm -rf repo worktree" &&
1079 test_commit -C repo A &&
1081 git -C repo worktree add ../worktree &&
1082 git -C repo pack-refs &&
1083 git -C worktree pack-refs &&
1084 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
1085 test_line_count = 1 repo/.git/reftable/tables.list &&
1087 cat >stdin <<-EOF &&
1088 create worktrees/worktree/refs/bisect/per-worktree HEAD
1089 create refs/branches/shared HEAD
1091 git -C repo update-ref --stdin <stdin &&
1092 test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
1093 test_line_count = 2 repo/.git/reftable/tables.list
1096 test_expect_success
'worktree: can access common refs' '
1097 test_when_finished "rm -rf repo worktree" &&
1099 test_commit -C repo file1 &&
1100 git -C repo branch branch1 &&
1101 git -C repo worktree add ../worktree &&
1103 echo refs/heads/worktree >expect &&
1104 git -C worktree symbolic-ref HEAD >actual &&
1105 test_cmp expect actual &&
1106 git -C worktree checkout branch1
1109 test_expect_success
'worktree: adds worktree with detached HEAD' '
1110 test_when_finished "rm -rf repo worktree" &&
1113 test_commit -C repo A &&
1114 git -C repo rev-parse main >expect &&
1116 git -C repo worktree add --detach ../worktree main &&
1117 git -C worktree rev-parse HEAD >actual &&
1118 test_cmp expect actual
1121 test_expect_success
'fetch: accessing FETCH_HEAD special ref works' '
1122 test_when_finished "rm -rf repo sub" &&
1125 test_commit -C sub two &&
1126 git -C sub rev-parse HEAD >expect &&
1129 test_commit -C repo one &&
1130 git -C repo fetch ../sub &&
1131 git -C repo rev-parse FETCH_HEAD >actual &&
1132 test_cmp expect actual