t06xx: always execute backend-specific tests
[alt-git.git] / t / t0610-reftable-basics.sh
blobaa9282007cf607afb6905ea7472b0435df458447
1 #!/bin/sh
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-lib.sh
15 INVALID_OID=$(test_oid 001)
17 test_expect_success 'init: creates basic reftable structures' '
18 test_when_finished "rm -rf repo" &&
19 git init repo &&
20 test_path_is_dir repo/.git/reftable &&
21 test_path_is_file repo/.git/reftable/tables.list &&
22 echo reftable >expect &&
23 git -C repo rev-parse --show-ref-format >actual &&
24 test_cmp expect actual
27 test_expect_success 'init: sha256 object format via environment variable' '
28 test_when_finished "rm -rf repo" &&
29 GIT_DEFAULT_HASH=sha256 git init repo &&
30 cat >expect <<-EOF &&
31 sha256
32 reftable
33 EOF
34 git -C repo rev-parse --show-object-format --show-ref-format >actual &&
35 test_cmp expect actual
38 test_expect_success 'init: sha256 object format via option' '
39 test_when_finished "rm -rf repo" &&
40 git init --object-format=sha256 repo &&
41 cat >expect <<-EOF &&
42 sha256
43 reftable
44 EOF
45 git -C repo rev-parse --show-object-format --show-ref-format >actual &&
46 test_cmp expect actual
49 test_expect_success 'init: reinitializing reftable backend succeeds' '
50 test_when_finished "rm -rf repo" &&
51 git init repo &&
52 test_commit -C repo A &&
54 git -C repo for-each-ref >expect &&
55 git init --ref-format=reftable repo &&
56 git -C repo for-each-ref >actual &&
57 test_cmp expect actual
60 test_expect_success 'init: reinitializing files with reftable backend fails' '
61 test_when_finished "rm -rf repo" &&
62 git init --ref-format=files repo &&
63 test_commit -C repo file &&
65 cp repo/.git/HEAD expect &&
66 test_must_fail git init --ref-format=reftable repo &&
67 test_cmp expect repo/.git/HEAD
70 test_expect_success 'init: reinitializing reftable with files backend fails' '
71 test_when_finished "rm -rf repo" &&
72 git init --ref-format=reftable repo &&
73 test_commit -C repo file &&
75 cp repo/.git/HEAD expect &&
76 test_must_fail git init --ref-format=files repo &&
77 test_cmp expect repo/.git/HEAD
80 test_expect_perms () {
81 local perms="$1"
82 local file="$2"
83 local actual=$(ls -l "$file") &&
85 case "$actual" in
86 $perms*)
87 : happy
90 echo "$(basename $2) is not $perms but $actual"
91 false
93 esac
96 for umask in 002 022
98 test_expect_success POSIXPERM 'init: honors core.sharedRepository' '
99 test_when_finished "rm -rf repo" &&
101 umask $umask &&
102 git init --shared=true repo &&
103 test 1 = "$(git -C repo config core.sharedrepository)"
104 ) &&
105 test_expect_perms "-rw-rw-r--" repo/.git/reftable/tables.list &&
106 for table in repo/.git/reftable/*.ref
108 test_expect_perms "-rw-rw-r--" "$table" ||
109 return 1
110 done
112 done
114 test_expect_success 'clone: can clone reftable repository' '
115 test_when_finished "rm -rf repo clone" &&
116 git init repo &&
117 test_commit -C repo message1 file1 &&
119 git clone repo cloned &&
120 echo reftable >expect &&
121 git -C cloned rev-parse --show-ref-format >actual &&
122 test_cmp expect actual &&
123 test_path_is_file cloned/file1
126 test_expect_success 'clone: can clone reffiles into reftable repository' '
127 test_when_finished "rm -rf reffiles reftable" &&
128 git init --ref-format=files reffiles &&
129 test_commit -C reffiles A &&
130 git clone --ref-format=reftable ./reffiles reftable &&
132 git -C reffiles rev-parse HEAD >expect &&
133 git -C reftable rev-parse HEAD >actual &&
134 test_cmp expect actual &&
136 git -C reftable rev-parse --show-ref-format >actual &&
137 echo reftable >expect &&
138 test_cmp expect actual &&
140 git -C reffiles rev-parse --show-ref-format >actual &&
141 echo files >expect &&
142 test_cmp expect actual
145 test_expect_success 'clone: can clone reftable into reffiles repository' '
146 test_when_finished "rm -rf reffiles reftable" &&
147 git init --ref-format=reftable reftable &&
148 test_commit -C reftable A &&
149 git clone --ref-format=files ./reftable reffiles &&
151 git -C reftable rev-parse HEAD >expect &&
152 git -C reffiles rev-parse HEAD >actual &&
153 test_cmp expect actual &&
155 git -C reftable rev-parse --show-ref-format >actual &&
156 echo reftable >expect &&
157 test_cmp expect actual &&
159 git -C reffiles rev-parse --show-ref-format >actual &&
160 echo files >expect &&
161 test_cmp expect actual
164 test_expect_success 'ref transaction: corrupted tables cause failure' '
165 test_when_finished "rm -rf repo" &&
166 git init repo &&
168 cd repo &&
169 test_commit file1 &&
170 for f in .git/reftable/*.ref
172 : >"$f" || return 1
173 done &&
174 test_must_fail git update-ref refs/heads/main HEAD
178 test_expect_success 'ref transaction: corrupted tables.list cause failure' '
179 test_when_finished "rm -rf repo" &&
180 git init repo &&
182 cd repo &&
183 test_commit file1 &&
184 echo garbage >.git/reftable/tables.list &&
185 test_must_fail git update-ref refs/heads/main HEAD
189 test_expect_success 'ref transaction: refuses to write ref causing F/D conflict' '
190 test_when_finished "rm -rf repo" &&
191 git init repo &&
192 test_commit -C repo file &&
193 test_must_fail git -C repo update-ref refs/heads/main/forbidden
196 test_expect_success 'ref transaction: deleting ref with invalid name fails' '
197 test_when_finished "rm -rf repo" &&
198 git init repo &&
199 test_commit -C repo file &&
200 test_must_fail git -C repo update-ref -d ../../my-private-file
203 test_expect_success 'ref transaction: can skip object ID verification' '
204 test_when_finished "rm -rf repo" &&
205 git init repo &&
206 test_must_fail test-tool -C repo ref-store main update-ref msg refs/heads/branch $INVALID_OID $ZERO_OID 0 &&
207 test-tool -C repo ref-store main update-ref msg refs/heads/branch $INVALID_OID $ZERO_OID REF_SKIP_OID_VERIFICATION
210 test_expect_success 'ref transaction: updating same ref multiple times fails' '
211 test_when_finished "rm -rf repo" &&
212 git init repo &&
213 test_commit -C repo A &&
214 cat >updates <<-EOF &&
215 update refs/heads/main $A
216 update refs/heads/main $A
218 cat >expect <<-EOF &&
219 fatal: multiple updates for ref ${SQ}refs/heads/main${SQ} not allowed
221 test_must_fail git -C repo update-ref --stdin <updates 2>err &&
222 test_cmp expect err
225 test_expect_success 'ref transaction: can delete symbolic self-reference with git-symbolic-ref(1)' '
226 test_when_finished "rm -rf repo" &&
227 git init repo &&
228 git -C repo symbolic-ref refs/heads/self refs/heads/self &&
229 git -C repo symbolic-ref -d refs/heads/self
232 test_expect_success 'ref transaction: deleting symbolic self-reference without --no-deref fails' '
233 test_when_finished "rm -rf repo" &&
234 git init repo &&
235 git -C repo symbolic-ref refs/heads/self refs/heads/self &&
236 cat >expect <<-EOF &&
237 error: multiple updates for ${SQ}refs/heads/self${SQ} (including one via symref ${SQ}refs/heads/self${SQ}) are not allowed
239 test_must_fail git -C repo update-ref -d refs/heads/self 2>err &&
240 test_cmp expect err
243 test_expect_success 'ref transaction: deleting symbolic self-reference with --no-deref succeeds' '
244 test_when_finished "rm -rf repo" &&
245 git init repo &&
246 git -C repo symbolic-ref refs/heads/self refs/heads/self &&
247 git -C repo update-ref -d --no-deref refs/heads/self
250 test_expect_success 'ref transaction: creating symbolic ref fails with F/D conflict' '
251 test_when_finished "rm -rf repo" &&
252 git init repo &&
253 test_commit -C repo A &&
254 cat >expect <<-EOF &&
255 error: unable to write symref for refs/heads: file/directory conflict
257 test_must_fail git -C repo symbolic-ref refs/heads refs/heads/foo 2>err &&
258 test_cmp expect err
261 test_expect_success 'ref transaction: ref deletion' '
262 test_when_finished "rm -rf repo" &&
263 git init repo &&
265 cd repo &&
266 test_commit file &&
267 HEAD_OID=$(git show-ref -s --verify HEAD) &&
268 cat >expect <<-EOF &&
269 $HEAD_OID refs/heads/main
270 $HEAD_OID refs/tags/file
272 git show-ref >actual &&
273 test_cmp expect actual &&
275 test_must_fail git update-ref -d refs/tags/file $INVALID_OID &&
276 git show-ref >actual &&
277 test_cmp expect actual &&
279 git update-ref -d refs/tags/file $HEAD_OID &&
280 echo "$HEAD_OID refs/heads/main" >expect &&
281 git show-ref >actual &&
282 test_cmp expect actual
286 test_expect_success 'ref transaction: writes cause auto-compaction' '
287 test_when_finished "rm -rf repo" &&
289 git init repo &&
290 test_line_count = 1 repo/.git/reftable/tables.list &&
292 test_commit -C repo --no-tag A &&
293 test_line_count = 2 repo/.git/reftable/tables.list &&
295 test_commit -C repo --no-tag B &&
296 test_line_count = 1 repo/.git/reftable/tables.list
299 check_fsync_events () {
300 local trace="$1" &&
301 shift &&
303 cat >expect &&
304 sed -n \
305 -e '/^{"event":"counter",.*"category":"fsync",/ {
306 s/.*"category":"fsync",//;
307 s/}$//;
309 }' \
310 <"$trace" >actual &&
311 test_cmp expect actual
314 test_expect_success 'ref transaction: writes are synced' '
315 test_when_finished "rm -rf repo" &&
316 git init repo &&
317 test_commit -C repo initial &&
319 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
320 GIT_TEST_FSYNC=true \
321 git -C repo -c core.fsync=reference \
322 -c core.fsyncMethod=fsync update-ref refs/heads/branch HEAD &&
323 check_fsync_events trace2.txt <<-EOF
324 "name":"hardware-flush","count":2
328 test_expect_success 'ref transaction: empty transaction in empty repo' '
329 test_when_finished "rm -rf repo" &&
330 git init repo &&
331 test_commit -C repo --no-tag A &&
332 git -C repo update-ref -d refs/heads/main &&
333 test-tool -C repo ref-store main delete-refs REF_NO_DEREF msg HEAD &&
334 git -C repo update-ref --stdin <<-EOF
335 prepare
336 commit
340 test_expect_success 'pack-refs: compacts tables' '
341 test_when_finished "rm -rf repo" &&
342 git init repo &&
344 test_commit -C repo A &&
345 ls -1 repo/.git/reftable >table-files &&
346 test_line_count = 4 table-files &&
347 test_line_count = 3 repo/.git/reftable/tables.list &&
349 git -C repo pack-refs &&
350 ls -1 repo/.git/reftable >table-files &&
351 test_line_count = 2 table-files &&
352 test_line_count = 1 repo/.git/reftable/tables.list
355 test_expect_success 'pack-refs: prunes stale tables' '
356 test_when_finished "rm -rf repo" &&
357 git init repo &&
358 touch repo/.git/reftable/stale-table.ref &&
359 git -C repo pack-refs &&
360 test_path_is_missing repo/.git/reftable/stable-ref.ref
363 test_expect_success 'pack-refs: does not prune non-table files' '
364 test_when_finished "rm -rf repo" &&
365 git init repo &&
366 touch repo/.git/reftable/garbage &&
367 git -C repo pack-refs &&
368 test_path_is_file repo/.git/reftable/garbage
371 for umask in 002 022
373 test_expect_success POSIXPERM 'pack-refs: honors core.sharedRepository' '
374 test_when_finished "rm -rf repo" &&
376 umask $umask &&
377 git init --shared=true repo &&
378 test_commit -C repo A &&
379 test_line_count = 3 repo/.git/reftable/tables.list
380 ) &&
381 git -C repo pack-refs &&
382 test_expect_perms "-rw-rw-r--" repo/.git/reftable/tables.list &&
383 for table in repo/.git/reftable/*.ref
385 test_expect_perms "-rw-rw-r--" "$table" ||
386 return 1
387 done
389 done
391 test_expect_success 'packed-refs: writes are synced' '
392 test_when_finished "rm -rf repo" &&
393 git init repo &&
394 test_commit -C repo initial &&
395 test_line_count = 2 table-files &&
397 : >trace2.txt &&
398 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
399 GIT_TEST_FSYNC=true \
400 git -C repo -c core.fsync=reference \
401 -c core.fsyncMethod=fsync pack-refs &&
402 check_fsync_events trace2.txt <<-EOF
403 "name":"hardware-flush","count":2
407 test_expect_success 'ref iterator: bogus names are flagged' '
408 test_when_finished "rm -rf repo" &&
409 git init repo &&
411 cd repo &&
412 test_commit --no-tag file &&
413 test-tool ref-store main update-ref msg "refs/heads/bogus..name" $(git rev-parse HEAD) $ZERO_OID REF_SKIP_REFNAME_VERIFICATION &&
415 cat >expect <<-EOF &&
416 $ZERO_OID refs/heads/bogus..name 0xc
417 $(git rev-parse HEAD) refs/heads/main 0x0
419 test-tool ref-store main for-each-ref "" >actual &&
420 test_cmp expect actual
424 test_expect_success 'ref iterator: missing object IDs are not flagged' '
425 test_when_finished "rm -rf repo" &&
426 git init repo &&
428 cd repo &&
429 test-tool ref-store main update-ref msg "refs/heads/broken-hash" $INVALID_OID $ZERO_OID REF_SKIP_OID_VERIFICATION &&
431 cat >expect <<-EOF &&
432 $INVALID_OID refs/heads/broken-hash 0x0
434 test-tool ref-store main for-each-ref "" >actual &&
435 test_cmp expect actual
439 test_expect_success 'basic: commit and list refs' '
440 test_when_finished "rm -rf repo" &&
441 git init repo &&
442 test_commit -C repo file &&
443 test_write_lines refs/heads/main refs/tags/file >expect &&
444 git -C repo for-each-ref --format="%(refname)" >actual &&
445 test_cmp actual expect
448 test_expect_success 'basic: can write large commit message' '
449 test_when_finished "rm -rf repo" &&
450 git init repo &&
451 perl -e "
452 print \"this is a long commit message\" x 50000
453 " >commit-msg &&
454 git -C repo commit --allow-empty --file=../commit-msg
457 test_expect_success 'basic: show-ref fails with empty repository' '
458 test_when_finished "rm -rf repo" &&
459 git init repo &&
460 test_must_fail git -C repo show-ref >actual &&
461 test_must_be_empty actual
464 test_expect_success 'basic: can check out unborn branch' '
465 test_when_finished "rm -rf repo" &&
466 git init repo &&
467 git -C repo checkout -b main
470 test_expect_success 'basic: peeled tags are stored' '
471 test_when_finished "rm -rf repo" &&
472 git init repo &&
473 test_commit -C repo file &&
474 git -C repo tag -m "annotated tag" test_tag HEAD &&
475 for ref in refs/heads/main refs/tags/file refs/tags/test_tag refs/tags/test_tag^{}
477 echo "$(git -C repo rev-parse "$ref") $ref" || return 1
478 done >expect &&
479 git -C repo show-ref -d >actual &&
480 test_cmp expect actual
483 test_expect_success 'basic: for-each-ref can print symrefs' '
484 test_when_finished "rm -rf repo" &&
485 git init repo &&
487 cd repo &&
488 test_commit file &&
489 git branch &&
490 git symbolic-ref refs/heads/sym refs/heads/main &&
491 cat >expected <<-EOF &&
492 refs/heads/main
494 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
495 test_cmp expected actual
499 test_expect_success 'basic: notes' '
500 test_when_finished "rm -rf repo" &&
501 git init repo &&
503 write_script fake_editor <<-\EOF &&
504 echo "$MSG" >"$1"
505 echo "$MSG" >&2
508 test_commit 1st &&
509 test_commit 2nd &&
510 GIT_EDITOR=./fake_editor MSG=b4 git notes add &&
511 GIT_EDITOR=./fake_editor MSG=b3 git notes edit &&
512 echo b4 >expect &&
513 git notes --ref commits@{1} show >actual &&
514 test_cmp expect actual
518 test_expect_success 'basic: stash' '
519 test_when_finished "rm -rf repo" &&
520 git init repo &&
522 cd repo &&
523 test_commit file &&
524 git stash list >expect &&
525 test_line_count = 0 expect &&
527 echo hoi >>file.t &&
528 git stash push -m stashed &&
529 git stash list >expect &&
530 test_line_count = 1 expect &&
532 git stash clear &&
533 git stash list >expect &&
534 test_line_count = 0 expect
538 test_expect_success 'basic: cherry-pick' '
539 test_when_finished "rm -rf repo" &&
540 git init repo &&
542 cd repo &&
543 test_commit message1 file1 &&
544 test_commit message2 file2 &&
545 git branch source &&
546 git checkout HEAD^ &&
547 test_commit message3 file3 &&
548 git cherry-pick source &&
549 test_path_is_file file2
553 test_expect_success 'basic: rebase' '
554 test_when_finished "rm -rf repo" &&
555 git init repo &&
557 cd repo &&
558 test_commit message1 file1 &&
559 test_commit message2 file2 &&
560 git branch source &&
561 git checkout HEAD^ &&
562 test_commit message3 file3 &&
563 git rebase source &&
564 test_path_is_file file2
568 test_expect_success 'reflog: can delete separate reflog entries' '
569 test_when_finished "rm -rf repo" &&
570 git init repo &&
572 cd repo &&
574 test_commit file &&
575 test_commit file2 &&
576 test_commit file3 &&
577 test_commit file4 &&
578 git reflog >actual &&
579 grep file3 actual &&
581 git reflog delete HEAD@{1} &&
582 git reflog >actual &&
583 ! grep file3 actual
587 test_expect_success 'reflog: can switch to previous branch' '
588 test_when_finished "rm -rf repo" &&
589 git init repo &&
591 cd repo &&
592 test_commit file1 &&
593 git checkout -b branch1 &&
594 test_commit file2 &&
595 git checkout -b branch2 &&
596 git switch - &&
597 git rev-parse --symbolic-full-name HEAD >actual &&
598 echo refs/heads/branch1 >expect &&
599 test_cmp actual expect
603 test_expect_success 'reflog: copying branch writes reflog entry' '
604 test_when_finished "rm -rf repo" &&
605 git init repo &&
607 cd repo &&
608 test_commit file1 &&
609 test_commit file2 &&
610 oid=$(git rev-parse --short HEAD) &&
611 git branch src &&
612 cat >expect <<-EOF &&
613 ${oid} dst@{0}: Branch: copied refs/heads/src to refs/heads/dst
614 ${oid} dst@{1}: branch: Created from main
616 git branch -c src dst &&
617 git reflog dst >actual &&
618 test_cmp expect actual
622 test_expect_success 'reflog: renaming branch writes reflog entry' '
623 test_when_finished "rm -rf repo" &&
624 git init repo &&
626 cd repo &&
627 git symbolic-ref HEAD refs/heads/before &&
628 test_commit file &&
629 git show-ref >expected.refs &&
630 sed s/before/after/g <expected.refs >expected &&
631 git branch -M after &&
632 git show-ref >actual &&
633 test_cmp expected actual &&
634 echo refs/heads/after >expected &&
635 git symbolic-ref HEAD >actual &&
636 test_cmp expected actual
640 test_expect_success 'reflog: can store empty logs' '
641 test_when_finished "rm -rf repo" &&
642 git init repo &&
644 cd repo &&
646 test_must_fail test-tool ref-store main reflog-exists refs/heads/branch &&
647 test-tool ref-store main create-reflog refs/heads/branch &&
648 test-tool ref-store main reflog-exists refs/heads/branch &&
649 test-tool ref-store main for-each-reflog-ent-reverse refs/heads/branch >actual &&
650 test_must_be_empty actual
654 test_expect_success 'reflog: expiry empties reflog' '
655 test_when_finished "rm -rf repo" &&
656 git init repo &&
658 cd repo &&
660 test_commit initial &&
661 git checkout -b branch &&
662 test_commit fileA &&
663 test_commit fileB &&
665 cat >expect <<-EOF &&
666 commit: fileB
667 commit: fileA
668 branch: Created from HEAD
670 git reflog show --format="%gs" refs/heads/branch >actual &&
671 test_cmp expect actual &&
673 git reflog expire branch --expire=all &&
674 git reflog show --format="%gs" refs/heads/branch >actual &&
675 test_must_be_empty actual &&
676 test-tool ref-store main reflog-exists refs/heads/branch
680 test_expect_success 'reflog: can be deleted' '
681 test_when_finished "rm -rf repo" &&
682 git init repo &&
684 cd repo &&
685 test_commit initial &&
686 test-tool ref-store main reflog-exists refs/heads/main &&
687 test-tool ref-store main delete-reflog refs/heads/main &&
688 test_must_fail test-tool ref-store main reflog-exists refs/heads/main
692 test_expect_success 'reflog: garbage collection deletes reflog entries' '
693 test_when_finished "rm -rf repo" &&
694 git init repo &&
696 cd repo &&
698 for count in $(test_seq 1 10)
700 test_commit "number $count" file.t $count number-$count ||
701 return 1
702 done &&
703 git reflog refs/heads/main >actual &&
704 test_line_count = 10 actual &&
705 grep "commit (initial): number 1" actual &&
706 grep "commit: number 10" actual &&
708 git gc &&
709 git reflog refs/heads/main >actual &&
710 test_line_count = 0 actual
714 test_expect_success 'reflog: updates via HEAD update HEAD reflog' '
715 test_when_finished "rm -rf repo" &&
716 git init repo &&
718 cd repo &&
719 test_commit main-one &&
720 git checkout -b new-branch &&
721 test_commit new-one &&
722 test_commit new-two &&
724 echo new-one >expect &&
725 git log -1 --format=%s HEAD@{1} >actual &&
726 test_cmp expect actual
730 test_expect_success 'worktree: adding worktree creates separate stack' '
731 test_when_finished "rm -rf repo worktree" &&
732 git init repo &&
733 test_commit -C repo A &&
735 git -C repo worktree add ../worktree &&
736 test_path_is_file repo/.git/worktrees/worktree/refs/heads &&
737 echo "ref: refs/heads/.invalid" >expect &&
738 test_cmp expect repo/.git/worktrees/worktree/HEAD &&
739 test_path_is_dir repo/.git/worktrees/worktree/reftable &&
740 test_path_is_file repo/.git/worktrees/worktree/reftable/tables.list
743 test_expect_success 'worktree: pack-refs in main repo packs main refs' '
744 test_when_finished "rm -rf repo worktree" &&
745 git init repo &&
746 test_commit -C repo A &&
747 git -C repo worktree add ../worktree &&
749 test_line_count = 3 repo/.git/worktrees/worktree/reftable/tables.list &&
750 test_line_count = 4 repo/.git/reftable/tables.list &&
751 git -C repo pack-refs &&
752 test_line_count = 3 repo/.git/worktrees/worktree/reftable/tables.list &&
753 test_line_count = 1 repo/.git/reftable/tables.list
756 test_expect_success 'worktree: pack-refs in worktree packs worktree refs' '
757 test_when_finished "rm -rf repo worktree" &&
758 git init repo &&
759 test_commit -C repo A &&
760 git -C repo worktree add ../worktree &&
762 test_line_count = 3 repo/.git/worktrees/worktree/reftable/tables.list &&
763 test_line_count = 4 repo/.git/reftable/tables.list &&
764 git -C worktree pack-refs &&
765 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
766 test_line_count = 4 repo/.git/reftable/tables.list
769 test_expect_success 'worktree: creating shared ref updates main stack' '
770 test_when_finished "rm -rf repo worktree" &&
771 git init repo &&
772 test_commit -C repo A &&
774 git -C repo worktree add ../worktree &&
775 git -C repo pack-refs &&
776 git -C worktree pack-refs &&
777 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
778 test_line_count = 1 repo/.git/reftable/tables.list &&
780 git -C worktree update-ref refs/heads/shared HEAD &&
781 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
782 test_line_count = 2 repo/.git/reftable/tables.list
785 test_expect_success 'worktree: creating per-worktree ref updates worktree stack' '
786 test_when_finished "rm -rf repo worktree" &&
787 git init repo &&
788 test_commit -C repo A &&
790 git -C repo worktree add ../worktree &&
791 git -C repo pack-refs &&
792 git -C worktree pack-refs &&
793 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
794 test_line_count = 1 repo/.git/reftable/tables.list &&
796 git -C worktree update-ref refs/bisect/per-worktree HEAD &&
797 test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
798 test_line_count = 1 repo/.git/reftable/tables.list
801 test_expect_success 'worktree: creating per-worktree ref from main repo' '
802 test_when_finished "rm -rf repo worktree" &&
803 git init repo &&
804 test_commit -C repo A &&
806 git -C repo worktree add ../worktree &&
807 git -C repo pack-refs &&
808 git -C worktree pack-refs &&
809 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
810 test_line_count = 1 repo/.git/reftable/tables.list &&
812 git -C repo update-ref worktrees/worktree/refs/bisect/per-worktree HEAD &&
813 test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
814 test_line_count = 1 repo/.git/reftable/tables.list
817 test_expect_success 'worktree: creating per-worktree ref from second worktree' '
818 test_when_finished "rm -rf repo wt1 wt2" &&
819 git init repo &&
820 test_commit -C repo A &&
822 git -C repo worktree add ../wt1 &&
823 git -C repo worktree add ../wt2 &&
824 git -C repo pack-refs &&
825 git -C wt1 pack-refs &&
826 git -C wt2 pack-refs &&
827 test_line_count = 1 repo/.git/worktrees/wt1/reftable/tables.list &&
828 test_line_count = 1 repo/.git/worktrees/wt2/reftable/tables.list &&
829 test_line_count = 1 repo/.git/reftable/tables.list &&
831 git -C wt1 update-ref worktrees/wt2/refs/bisect/per-worktree HEAD &&
832 test_line_count = 1 repo/.git/worktrees/wt1/reftable/tables.list &&
833 test_line_count = 2 repo/.git/worktrees/wt2/reftable/tables.list &&
834 test_line_count = 1 repo/.git/reftable/tables.list
837 test_expect_success 'worktree: can create shared and per-worktree ref in one transaction' '
838 test_when_finished "rm -rf repo worktree" &&
839 git init repo &&
840 test_commit -C repo A &&
842 git -C repo worktree add ../worktree &&
843 git -C repo pack-refs &&
844 git -C worktree pack-refs &&
845 test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
846 test_line_count = 1 repo/.git/reftable/tables.list &&
848 cat >stdin <<-EOF &&
849 create worktrees/worktree/refs/bisect/per-worktree HEAD
850 create refs/branches/shared HEAD
852 git -C repo update-ref --stdin <stdin &&
853 test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
854 test_line_count = 2 repo/.git/reftable/tables.list
857 test_expect_success 'worktree: can access common refs' '
858 test_when_finished "rm -rf repo worktree" &&
859 git init repo &&
860 test_commit -C repo file1 &&
861 git -C repo branch branch1 &&
862 git -C repo worktree add ../worktree &&
864 echo refs/heads/worktree >expect &&
865 git -C worktree symbolic-ref HEAD >actual &&
866 test_cmp expect actual &&
867 git -C worktree checkout branch1
870 test_expect_success 'worktree: adds worktree with detached HEAD' '
871 test_when_finished "rm -rf repo worktree" &&
873 git init repo &&
874 test_commit -C repo A &&
875 git -C repo rev-parse main >expect &&
877 git -C repo worktree add --detach ../worktree main &&
878 git -C worktree rev-parse HEAD >actual &&
879 test_cmp expect actual
882 test_expect_success 'fetch: accessing FETCH_HEAD special ref works' '
883 test_when_finished "rm -rf repo sub" &&
885 git init sub &&
886 test_commit -C sub two &&
887 git -C sub rev-parse HEAD >expect &&
889 git init repo &&
890 test_commit -C repo one &&
891 git -C repo fetch ../sub &&
892 git -C repo rev-parse FETCH_HEAD >actual &&
893 test_cmp expect actual
896 test_done