3 # Copyright (c) 2020 Google LLC
6 test_description
='reftable basics'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 if ! test_have_prereq REFTABLE
14 skip_all
='skipping reftable tests; set GIT_TEST_DEFAULT_REF_FORMAT=reftable'
18 INVALID_OID
=$
(test_oid
001)
20 test_expect_success
'init: creates basic reftable structures' '
21 test_when_finished "rm -rf repo" &&
23 test_path_is_dir repo/.git/reftable &&
24 test_path_is_file repo/.git/reftable/tables.list &&
25 echo reftable >expect &&
26 git -C repo rev-parse --show-ref-format >actual &&
27 test_cmp expect actual
30 test_expect_success
'init: sha256 object format via environment variable' '
31 test_when_finished "rm -rf repo" &&
32 GIT_DEFAULT_HASH=sha256 git init repo &&
37 git -C repo rev-parse --show-object-format --show-ref-format >actual &&
38 test_cmp expect actual
41 test_expect_success
'init: sha256 object format via option' '
42 test_when_finished "rm -rf repo" &&
43 git init --object-format=sha256 repo &&
48 git -C repo rev-parse --show-object-format --show-ref-format >actual &&
49 test_cmp expect actual
52 test_expect_success
'init: reinitializing reftable backend succeeds' '
53 test_when_finished "rm -rf repo" &&
55 test_commit -C repo A &&
57 git -C repo for-each-ref >expect &&
58 git init --ref-format=reftable repo &&
59 git -C repo for-each-ref >actual &&
60 test_cmp expect actual
63 test_expect_success
'init: reinitializing files with reftable backend fails' '
64 test_when_finished "rm -rf repo" &&
65 git init --ref-format=files repo &&
66 test_commit -C repo file &&
68 cp repo/.git/HEAD expect &&
69 test_must_fail git init --ref-format=reftable repo &&
70 test_cmp expect repo/.git/HEAD
73 test_expect_success
'init: reinitializing reftable with files backend fails' '
74 test_when_finished "rm -rf repo" &&
75 git init --ref-format=reftable repo &&
76 test_commit -C repo file &&
78 cp repo/.git/HEAD expect &&
79 test_must_fail git init --ref-format=files repo &&
80 test_cmp expect repo/.git/HEAD
83 test_expect_perms
() {
86 local actual
="$(ls -l "$file")" &&
93 echo "$(basename $2) is not $perms but $actual"
99 test_expect_reftable_perms
() {
104 test_expect_success POSIXPERM
"init: honors --shared=$shared with umask $umask" '
105 test_when_finished "rm -rf repo" &&
108 git init --shared=$shared repo
110 test_expect_perms "$expect" repo/.git/reftable/tables.list &&
111 for table in repo/.git/reftable/*.ref
113 test_expect_perms "$expect" "$table" ||
118 test_expect_success POSIXPERM
"pack-refs: honors --shared=$shared with umask $umask" '
119 test_when_finished "rm -rf repo" &&
122 git init --shared=$shared repo &&
123 test_commit -C repo A &&
124 test_line_count = 2 repo/.git/reftable/tables.list &&
125 git -C repo pack-refs
127 test_expect_perms "$expect" repo/.git/reftable/tables.list &&
128 for table in repo/.git/reftable/*.ref
130 test_expect_perms "$expect" "$table" ||
136 test_expect_reftable_perms
002 umask "-rw-rw-r--"
137 test_expect_reftable_perms
022 umask "-rw-r--r--"
138 test_expect_reftable_perms
027 umask "-rw-r-----"
140 test_expect_reftable_perms
002 group
"-rw-rw-r--"
141 test_expect_reftable_perms
022 group
"-rw-rw-r--"
142 test_expect_reftable_perms
027 group
"-rw-rw----"
144 test_expect_reftable_perms
002 world
"-rw-rw-r--"
145 test_expect_reftable_perms
022 world
"-rw-rw-r--"
146 test_expect_reftable_perms
027 world
"-rw-rw-r--"
148 test_expect_success
'clone: can clone reftable repository' '
149 test_when_finished "rm -rf repo clone" &&
151 test_commit -C repo message1 file1 &&
153 git clone repo cloned &&
154 echo reftable >expect &&
155 git -C cloned rev-parse --show-ref-format >actual &&
156 test_cmp expect actual &&
157 test_path_is_file cloned/file1
160 test_expect_success
'clone: can clone reffiles into reftable repository' '
161 test_when_finished "rm -rf reffiles reftable" &&
162 git init --ref-format=files reffiles &&
163 test_commit -C reffiles A &&
164 git clone --ref-format=reftable ./reffiles reftable &&
166 git -C reffiles rev-parse HEAD >expect &&
167 git -C reftable rev-parse HEAD >actual &&
168 test_cmp expect actual &&
170 git -C reftable rev-parse --show-ref-format >actual &&
171 echo reftable >expect &&
172 test_cmp expect actual &&
174 git -C reffiles rev-parse --show-ref-format >actual &&
175 echo files >expect &&
176 test_cmp expect actual
179 test_expect_success
'clone: can clone reftable into reffiles repository' '
180 test_when_finished "rm -rf reffiles reftable" &&
181 git init --ref-format=reftable reftable &&
182 test_commit -C reftable A &&
183 git clone --ref-format=files ./reftable reffiles &&
185 git -C reftable rev-parse HEAD >expect &&
186 git -C reffiles rev-parse HEAD >actual &&
187 test_cmp expect actual &&
189 git -C reftable rev-parse --show-ref-format >actual &&
190 echo reftable >expect &&
191 test_cmp expect actual &&
193 git -C reffiles rev-parse --show-ref-format >actual &&
194 echo files >expect &&
195 test_cmp expect actual
198 test_expect_success
'ref transaction: corrupted tables cause failure' '
199 test_when_finished "rm -rf repo" &&
204 for f in .git/reftable/*.ref
208 test_must_fail git update-ref refs/heads/main HEAD
212 test_expect_success
'ref transaction: corrupted tables.list cause failure' '
213 test_when_finished "rm -rf repo" &&
218 echo garbage >.git/reftable/tables.list &&
219 test_must_fail git update-ref refs/heads/main HEAD
223 test_expect_success
'ref transaction: refuses to write ref causing F/D conflict' '
224 test_when_finished "rm -rf repo" &&
226 test_commit -C repo file &&
227 test_must_fail git -C repo update-ref refs/heads/main/forbidden
230 test_expect_success
'ref transaction: deleting ref with invalid name fails' '
231 test_when_finished "rm -rf repo" &&
233 test_commit -C repo file &&
234 test_must_fail git -C repo update-ref -d ../../my-private-file
237 test_expect_success
'ref transaction: can skip object ID verification' '
238 test_when_finished "rm -rf repo" &&
240 test_must_fail test-tool -C repo ref-store main update-ref msg refs/heads/branch $INVALID_OID $ZERO_OID 0 &&
241 test-tool -C repo ref-store main update-ref msg refs/heads/branch $INVALID_OID $ZERO_OID REF_SKIP_OID_VERIFICATION
244 test_expect_success
'ref transaction: updating same ref multiple times fails' '
245 test_when_finished "rm -rf repo" &&
247 test_commit -C repo A &&
248 cat >updates <<-EOF &&
249 update refs/heads/main $A
250 update refs/heads/main $A
252 cat >expect <<-EOF &&
253 fatal: multiple updates for ref ${SQ}refs/heads/main${SQ} not allowed
255 test_must_fail git -C repo update-ref --stdin <updates 2>err &&
259 test_expect_success
'ref transaction: can delete symbolic self-reference with git-symbolic-ref(1)' '
260 test_when_finished "rm -rf repo" &&
262 git -C repo symbolic-ref refs/heads/self refs/heads/self &&
263 git -C repo symbolic-ref -d refs/heads/self
266 test_expect_success
'ref transaction: deleting symbolic self-reference without --no-deref fails' '
267 test_when_finished "rm -rf repo" &&
269 git -C repo symbolic-ref refs/heads/self refs/heads/self &&
270 cat >expect <<-EOF &&
271 error: multiple updates for ${SQ}refs/heads/self${SQ} (including one via symref ${SQ}refs/heads/self${SQ}) are not allowed
273 test_must_fail git -C repo update-ref -d refs/heads/self 2>err &&
277 test_expect_success
'ref transaction: deleting symbolic self-reference with --no-deref succeeds' '
278 test_when_finished "rm -rf repo" &&
280 git -C repo symbolic-ref refs/heads/self refs/heads/self &&
281 git -C repo update-ref -d --no-deref refs/heads/self
284 test_expect_success
'ref transaction: creating symbolic ref fails with F/D conflict' '
285 test_when_finished "rm -rf repo" &&
287 test_commit -C repo A &&
288 cat >expect <<-EOF &&
289 error: ${SQ}refs/heads/main${SQ} exists; cannot create ${SQ}refs/heads${SQ}
291 test_must_fail git -C repo symbolic-ref refs/heads refs/heads/foo 2>err &&
295 test_expect_success
'ref transaction: ref deletion' '
296 test_when_finished "rm -rf repo" &&
301 HEAD_OID=$(git show-ref -s --verify HEAD) &&
302 cat >expect <<-EOF &&
303 $HEAD_OID refs/heads/main
304 $HEAD_OID refs/tags/file
306 git show-ref >actual &&
307 test_cmp expect actual &&
309 test_must_fail git update-ref -d refs/tags/file $INVALID_OID &&
310 git show-ref >actual &&
311 test_cmp expect actual &&
313 git update-ref -d refs/tags/file $HEAD_OID &&
314 echo "$HEAD_OID refs/heads/main" >expect &&
315 git show-ref >actual &&
316 test_cmp expect actual
320 test_expect_success
'ref transaction: writes cause auto-compaction' '
321 test_when_finished "rm -rf repo" &&
324 test_line_count = 1 repo/.git/reftable/tables.list &&
326 test_commit -C repo --no-tag A &&
327 test_line_count = 1 repo/.git/reftable/tables.list &&
329 test_commit -C repo --no-tag B &&
330 test_line_count = 1 repo/.git/reftable/tables.list
333 test_expect_success
'ref transaction: env var disables compaction' '
334 test_when_finished "rm -rf repo" &&
337 test_commit -C repo A &&
339 start=$(wc -l <repo/.git/reftable/tables.list) &&
341 expected=$((start + iterations)) &&
343 for i in $(test_seq $iterations)
345 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
346 git -C repo update-ref branch-$i HEAD || return 1
348 test_line_count = $expected repo/.git/reftable/tables.list &&
350 git -C repo update-ref foo HEAD &&
351 test_line_count -lt $expected repo/.git/reftable/tables.list
354 test_expect_success
'ref transaction: alternating table sizes are compacted' '
355 test_when_finished "rm -rf repo" &&
358 test_commit -C repo A &&
359 for i in $(test_seq 5)
361 git -C repo branch -f foo &&
362 git -C repo branch -d foo || return 1
364 test_line_count = 2 repo/.git/reftable/tables.list
367 check_fsync_events
() {
373 -e '/^{"event":"counter",.*"category":"fsync",/ {
374 s/.*"category":"fsync",//;
379 test_cmp expect actual
382 test_expect_success
'ref transaction: writes are synced' '
383 test_when_finished "rm -rf repo" &&
385 test_commit -C repo initial &&
387 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
388 GIT_TEST_FSYNC=true \
389 git -C repo -c core.fsync=reference \
390 -c core.fsyncMethod=fsync update-ref refs/heads/branch HEAD &&
391 check_fsync_events trace2.txt <<-EOF
392 "name":"hardware-flush","count":4
396 test_expect_success
'ref transaction: empty transaction in empty repo' '
397 test_when_finished "rm -rf repo" &&
399 test_commit -C repo --no-tag A &&
400 git -C repo update-ref -d refs/heads/main &&
401 test-tool -C repo ref-store main delete-refs REF_NO_DEREF msg HEAD &&
402 git -C repo update-ref --stdin <<-EOF
408 test_expect_success
'ref transaction: fails gracefully when auto compaction fails' '
409 test_when_finished "rm -rf repo" &&
415 for i in $(test_seq 10)
417 git branch branch-$i &&
418 for table in .git/reftable/*.ref
420 touch "$table.lock" || exit 1
424 test_line_count = 10 .git/reftable/tables.list
428 test_expect_success
'pack-refs: compacts tables' '
429 test_when_finished "rm -rf repo" &&
432 test_commit -C repo A &&
433 ls -1 repo/.git/reftable >table-files &&
434 test_line_count = 3 table-files &&
435 test_line_count = 2 repo/.git/reftable/tables.list &&
437 git -C repo pack-refs &&
438 ls -1 repo/.git/reftable >table-files &&
439 test_line_count = 2 table-files &&
440 test_line_count = 1 repo/.git/reftable/tables.list
443 test_expect_success
'pack-refs: compaction raises locking errors' '
444 test_when_finished "rm -rf repo" &&
446 test_commit -C repo A &&
447 touch repo/.git/reftable/tables.list.lock &&
448 cat >expect <<-EOF &&
449 error: unable to compact stack: data is locked
451 test_must_fail git -C repo pack-refs 2>err &&
455 for command in pack-refs gc
"maintenance run --task=pack-refs"
457 test_expect_success
"$command: auto compaction" '
458 test_when_finished "rm -rf repo" &&
465 # We need a bit of setup to ensure that git-gc(1) actually
466 # triggers, and that it does not write anything to the refdb.
467 git config gc.auto 1 &&
468 git config gc.autoDetach 0 &&
469 git config gc.reflogExpire never &&
470 git config gc.reflogExpireUnreachable never &&
471 test_oid blob17_1 | git hash-object -w --stdin &&
473 # The tables should have been auto-compacted, and thus auto
474 # compaction should not have to do anything.
475 ls -1 .git/reftable >tables-expect &&
476 test_line_count = 3 tables-expect &&
477 git $command --auto &&
478 ls -1 .git/reftable >tables-actual &&
479 test_cmp tables-expect tables-actual &&
481 test_oid blob17_2 | git hash-object -w --stdin &&
483 # Lock all tables write some refs. Auto-compaction will be
484 # unable to compact tables and thus fails gracefully, leaving
485 # the stack in a sub-optimal state.
486 ls .git/reftable/*.ref |
489 touch "$table.lock" || exit 1
493 rm .git/reftable/*.lock &&
494 test_line_count = 4 .git/reftable/tables.list &&
496 git $command --auto &&
497 test_line_count = 1 .git/reftable/tables.list
502 test_expect_success
'pack-refs: prunes stale tables' '
503 test_when_finished "rm -rf repo" &&
505 touch repo/.git/reftable/stale-table.ref &&
506 git -C repo pack-refs &&
507 test_path_is_missing repo/.git/reftable/stable-ref.ref
510 test_expect_success
'pack-refs: does not prune non-table files' '
511 test_when_finished "rm -rf repo" &&
513 touch repo/.git/reftable/garbage &&
514 git -C repo pack-refs &&
515 test_path_is_file repo/.git/reftable/garbage
518 test_expect_success
'packed-refs: writes are synced' '
519 test_when_finished "rm -rf repo" &&
521 test_commit -C repo initial &&
522 test_line_count = 2 table-files &&
525 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
526 GIT_TEST_FSYNC=true \
527 git -C repo -c core.fsync=reference \
528 -c core.fsyncMethod=fsync pack-refs &&
529 check_fsync_events trace2.txt <<-EOF
530 "name":"hardware-flush","count":2
534 test_expect_success
'ref iterator: bogus names are flagged' '
535 test_when_finished "rm -rf repo" &&
539 test_commit --no-tag file &&
540 test-tool ref-store main update-ref msg "refs/heads/bogus..name" $(git rev-parse HEAD) $ZERO_OID REF_SKIP_REFNAME_VERIFICATION &&
542 cat >expect <<-EOF &&
543 $ZERO_OID refs/heads/bogus..name 0xc
544 $(git rev-parse HEAD) refs/heads/main 0x0
546 test-tool ref-store main for-each-ref "" >actual &&
547 test_cmp expect actual
551 test_expect_success
'ref iterator: missing object IDs are not flagged' '
552 test_when_finished "rm -rf repo" &&
556 test-tool ref-store main update-ref msg "refs/heads/broken-hash" $INVALID_OID $ZERO_OID REF_SKIP_OID_VERIFICATION &&
558 cat >expect <<-EOF &&
559 $INVALID_OID refs/heads/broken-hash 0x0
561 test-tool ref-store main for-each-ref "" >actual &&
562 test_cmp expect actual
566 test_expect_success
'basic: commit and list refs' '
567 test_when_finished "rm -rf repo" &&
569 test_commit -C repo file &&
570 test_write_lines refs/heads/main refs/tags/file >expect &&
571 git -C repo for-each-ref --format="%(refname)" >actual &&
572 test_cmp actual expect
575 test_expect_success
'basic: can write large commit message' '
576 test_when_finished "rm -rf repo" &&
579 print \"this is a long commit message\" x 50000
581 git -C repo commit --allow-empty --file=../commit-msg
584 test_expect_success
'basic: show-ref fails with empty repository' '
585 test_when_finished "rm -rf repo" &&
587 test_must_fail git -C repo show-ref >actual &&
588 test_must_be_empty actual
591 test_expect_success
'basic: can check out unborn branch' '
592 test_when_finished "rm -rf repo" &&
594 git -C repo checkout -b main
597 test_expect_success
'basic: peeled tags are stored' '
598 test_when_finished "rm -rf repo" &&
600 test_commit -C repo file &&
601 git -C repo tag -m "annotated tag" test_tag HEAD &&
602 for ref in refs/heads/main refs/tags/file refs/tags/test_tag refs/tags/test_tag^{}
604 echo "$(git -C repo rev-parse "$ref") $ref" || return 1
606 git -C repo show-ref -d >actual &&
607 test_cmp expect actual
610 test_expect_success
'basic: for-each-ref can print symrefs' '
611 test_when_finished "rm -rf repo" &&
617 git symbolic-ref refs/heads/sym refs/heads/main &&
618 cat >expected <<-EOF &&
621 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
622 test_cmp expected actual
626 test_expect_success
'basic: notes' '
627 test_when_finished "rm -rf repo" &&
630 write_script fake_editor <<-\EOF &&
637 GIT_EDITOR=./fake_editor MSG=b4 git notes add &&
638 GIT_EDITOR=./fake_editor MSG=b3 git notes edit &&
640 git notes --ref commits@{1} show >actual &&
641 test_cmp expect actual
645 test_expect_success
'basic: stash' '
646 test_when_finished "rm -rf repo" &&
651 git stash list >expect &&
652 test_line_count = 0 expect &&
655 git stash push -m stashed &&
656 git stash list >expect &&
657 test_line_count = 1 expect &&
660 git stash list >expect &&
661 test_line_count = 0 expect
665 test_expect_success
'basic: cherry-pick' '
666 test_when_finished "rm -rf repo" &&
670 test_commit message1 file1 &&
671 test_commit message2 file2 &&
673 git checkout HEAD^ &&
674 test_commit message3 file3 &&
675 git cherry-pick source &&
676 test_path_is_file file2
680 test_expect_success
'basic: rebase' '
681 test_when_finished "rm -rf repo" &&
685 test_commit message1 file1 &&
686 test_commit message2 file2 &&
688 git checkout HEAD^ &&
689 test_commit message3 file3 &&
691 test_path_is_file file2
695 test_expect_success
'reflog: can delete separate reflog entries' '
696 test_when_finished "rm -rf repo" &&
705 git reflog >actual &&
708 git reflog delete HEAD@{1} &&
709 git reflog >actual &&
714 test_expect_success
'reflog: can switch to previous branch' '
715 test_when_finished "rm -rf repo" &&
720 git checkout -b branch1 &&
722 git checkout -b branch2 &&
724 git rev-parse --symbolic-full-name HEAD >actual &&
725 echo refs/heads/branch1 >expect &&
726 test_cmp actual expect
730 test_expect_success
'reflog: copying branch writes reflog entry' '
731 test_when_finished "rm -rf repo" &&
737 oid=$(git rev-parse --short HEAD) &&
739 cat >expect <<-EOF &&
740 ${oid} dst@{0}: Branch: copied refs/heads/src to refs/heads/dst
741 ${oid} dst@{1}: branch: Created from main
743 git branch -c src dst &&
744 git reflog dst >actual &&
745 test_cmp expect actual
749 test_expect_success
'reflog: renaming branch writes reflog entry' '
750 test_when_finished "rm -rf repo" &&
754 git symbolic-ref HEAD refs/heads/before &&
756 git show-ref >expected.refs &&
757 sed s/before/after/g <expected.refs >expected &&
758 git branch -M after &&
759 git show-ref >actual &&
760 test_cmp expected actual &&
761 echo refs/heads/after >expected &&
762 git symbolic-ref HEAD >actual &&
763 test_cmp expected actual
767 test_expect_success
'reflog: can store empty logs' '
768 test_when_finished "rm -rf repo" &&
773 test_must_fail test-tool ref-store main reflog-exists refs/heads/branch &&
774 test-tool ref-store main create-reflog refs/heads/branch &&
775 test-tool ref-store main reflog-exists refs/heads/branch &&
776 test-tool ref-store main for-each-reflog-ent-reverse refs/heads/branch >actual &&
777 test_must_be_empty actual
781 test_expect_success
'reflog: expiry empties reflog' '
782 test_when_finished "rm -rf repo" &&
787 test_commit initial &&
788 git checkout -b branch &&
792 cat >expect <<-EOF &&
795 branch: Created from HEAD
797 git reflog show --format="%gs" refs/heads/branch >actual &&
798 test_cmp expect actual &&
800 git reflog expire branch --expire=all &&
801 git reflog show --format="%gs" refs/heads/branch >actual &&
802 test_must_be_empty actual &&
803 test-tool ref-store main reflog-exists refs/heads/branch
807 test_expect_success
'reflog: can be deleted' '
808 test_when_finished "rm -rf repo" &&
812 test_commit initial &&
813 test-tool ref-store main reflog-exists refs/heads/main &&
814 test-tool ref-store main delete-reflog refs/heads/main &&
815 test_must_fail test-tool ref-store main reflog-exists refs/heads/main
819 test_expect_success
'reflog: garbage collection deletes reflog entries' '
820 test_when_finished "rm -rf repo" &&
825 for count in $(test_seq 1 10)
827 test_commit "number $count" file.t $count number-$count ||
830 git reflog refs/heads/main >actual &&
831 test_line_count = 10 actual &&
832 grep "commit (initial): number 1" actual &&
833 grep "commit: number 10" actual &&
836 git reflog refs/heads/main >actual &&
837 test_line_count = 0 actual
841 test_expect_success
'reflog: updates via HEAD update HEAD reflog' '
842 test_when_finished "rm -rf repo" &&
846 test_commit main-one &&
847 git checkout -b new-branch &&
848 test_commit new-one &&
849 test_commit new-two &&
851 echo new-one >expect &&
852 git log -1 --format=%s HEAD@{1} >actual &&
853 test_cmp expect actual
857 test_expect_success
'branch: copying branch with D/F conflict' '
858 test_when_finished "rm -rf repo" &&
864 cat >expect <<-EOF &&
865 error: ${SQ}refs/heads/branch${SQ} exists; cannot create ${SQ}refs/heads/branch/moved${SQ}
866 fatal: branch copy failed
868 test_must_fail git branch -c branch branch/moved 2>err &&
873 test_expect_success
'branch: moving branch with D/F conflict' '
874 test_when_finished "rm -rf repo" &&
880 git branch conflict &&
881 cat >expect <<-EOF &&
882 error: ${SQ}refs/heads/conflict${SQ} exists; cannot create ${SQ}refs/heads/conflict/moved${SQ}
883 fatal: branch rename failed
885 test_must_fail git branch -m branch conflict/moved 2>err &&
890 test_expect_success
'worktree: adding worktree creates separate stack' '
891 test_when_finished "rm -rf repo worktree" &&
893 test_commit -C repo A &&
895 git -C repo worktree add ../worktree &&
896 test_path_is_file repo/.git/worktrees/worktree/refs/heads &&
897 echo "ref: refs/heads/.invalid" >expect &&
898 test_cmp expect repo/.git/worktrees/worktree/HEAD &&
899 test_path_is_dir repo/.git/worktrees/worktree/reftable &&
900 test_path_is_file repo/.git/worktrees/worktree/reftable/tables.list
903 test_expect_success
'worktree: pack-refs in main repo packs main refs' '
904 test_when_finished "rm -rf repo worktree" &&
906 test_commit -C repo A &&
908 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
909 git -C repo worktree add ../worktree &&
910 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
911 git -C worktree update-ref refs/worktree/per-worktree HEAD &&
913 test_line_count = 4 repo/.git/worktrees/worktree/reftable/tables.list &&
914 test_line_count = 3 repo/.git/reftable/tables.list &&
915 git -C repo pack-refs &&
916 test_line_count = 4 repo/.git/worktrees/worktree/reftable/tables.list &&
917 test_line_count = 1 repo/.git/reftable/tables.list
920 test_expect_success
'worktree: pack-refs in worktree packs worktree refs' '
921 test_when_finished "rm -rf repo worktree" &&
923 test_commit -C repo A &&
925 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
926 git -C repo worktree add ../worktree &&
927 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
928 git -C worktree update-ref refs/worktree/per-worktree HEAD &&
930 test_line_count = 4 repo/.git/worktrees/worktree/reftable/tables.list &&
931 test_line_count = 3 repo/.git/reftable/tables.list &&
932 git -C worktree pack-refs &&
933 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
934 test_line_count = 3 repo/.git/reftable/tables.list
937 test_expect_success
'worktree: creating shared ref updates main stack' '
938 test_when_finished "rm -rf repo worktree" &&
940 test_commit -C repo A &&
942 git -C repo worktree add ../worktree &&
943 git -C repo pack-refs &&
944 git -C worktree pack-refs &&
945 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
946 test_line_count = 1 repo/.git/reftable/tables.list &&
948 GIT_TEST_REFTABLE_AUTOCOMPACTION=false \
949 git -C worktree update-ref refs/heads/shared HEAD &&
950 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
951 test_line_count = 2 repo/.git/reftable/tables.list
954 test_expect_success
'worktree: creating per-worktree ref updates worktree stack' '
955 test_when_finished "rm -rf repo worktree" &&
957 test_commit -C repo A &&
959 git -C repo worktree add ../worktree &&
960 git -C repo pack-refs &&
961 git -C worktree pack-refs &&
962 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
963 test_line_count = 1 repo/.git/reftable/tables.list &&
965 git -C worktree update-ref refs/bisect/per-worktree HEAD &&
966 test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
967 test_line_count = 1 repo/.git/reftable/tables.list
970 test_expect_success
'worktree: creating per-worktree ref from main repo' '
971 test_when_finished "rm -rf repo worktree" &&
973 test_commit -C repo A &&
975 git -C repo worktree add ../worktree &&
976 git -C repo pack-refs &&
977 git -C worktree pack-refs &&
978 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
979 test_line_count = 1 repo/.git/reftable/tables.list &&
981 git -C repo update-ref worktrees/worktree/refs/bisect/per-worktree HEAD &&
982 test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
983 test_line_count = 1 repo/.git/reftable/tables.list
986 test_expect_success
'worktree: creating per-worktree ref from second worktree' '
987 test_when_finished "rm -rf repo wt1 wt2" &&
989 test_commit -C repo A &&
991 git -C repo worktree add ../wt1 &&
992 git -C repo worktree add ../wt2 &&
993 git -C repo pack-refs &&
994 git -C wt1 pack-refs &&
995 git -C wt2 pack-refs &&
996 test_line_count = 1 repo/.git/worktrees/wt1/reftable/tables.list &&
997 test_line_count = 1 repo/.git/worktrees/wt2/reftable/tables.list &&
998 test_line_count = 1 repo/.git/reftable/tables.list &&
1000 git -C wt1 update-ref worktrees/wt2/refs/bisect/per-worktree HEAD &&
1001 test_line_count = 1 repo/.git/worktrees/wt1/reftable/tables.list &&
1002 test_line_count = 2 repo/.git/worktrees/wt2/reftable/tables.list &&
1003 test_line_count = 1 repo/.git/reftable/tables.list
1006 test_expect_success
'worktree: can create shared and per-worktree ref in one transaction' '
1007 test_when_finished "rm -rf repo worktree" &&
1009 test_commit -C repo A &&
1011 git -C repo worktree add ../worktree &&
1012 git -C repo pack-refs &&
1013 git -C worktree pack-refs &&
1014 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
1015 test_line_count = 1 repo/.git/reftable/tables.list &&
1017 cat >stdin <<-EOF &&
1018 create worktrees/worktree/refs/bisect/per-worktree HEAD
1019 create refs/branches/shared HEAD
1021 git -C repo update-ref --stdin <stdin &&
1022 test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
1023 test_line_count = 2 repo/.git/reftable/tables.list
1026 test_expect_success
'worktree: can access common refs' '
1027 test_when_finished "rm -rf repo worktree" &&
1029 test_commit -C repo file1 &&
1030 git -C repo branch branch1 &&
1031 git -C repo worktree add ../worktree &&
1033 echo refs/heads/worktree >expect &&
1034 git -C worktree symbolic-ref HEAD >actual &&
1035 test_cmp expect actual &&
1036 git -C worktree checkout branch1
1039 test_expect_success
'worktree: adds worktree with detached HEAD' '
1040 test_when_finished "rm -rf repo worktree" &&
1043 test_commit -C repo A &&
1044 git -C repo rev-parse main >expect &&
1046 git -C repo worktree add --detach ../worktree main &&
1047 git -C worktree rev-parse HEAD >actual &&
1048 test_cmp expect actual
1051 test_expect_success
'fetch: accessing FETCH_HEAD special ref works' '
1052 test_when_finished "rm -rf repo sub" &&
1055 test_commit -C sub two &&
1056 git -C sub rev-parse HEAD >expect &&
1059 test_commit -C repo one &&
1060 git -C repo fetch ../sub &&
1061 git -C repo rev-parse FETCH_HEAD >actual &&
1062 test_cmp expect actual