3 test_description
='test main ref store api'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 RUN
="test-tool ref-store main"
14 test_expect_success
'setup' '
18 test_expect_success REFFILES
'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' '
19 N=`find .git/refs -type f | wc -l` &&
21 $RUN pack-refs PACK_REFS_PRUNE,PACK_REFS_ALL &&
22 N=`find .git/refs -type f` &&
26 test_expect_success
'create_symref(FOO, refs/heads/main)' '
27 $RUN create-symref FOO refs/heads/main nothing &&
28 echo refs/heads/main >expected &&
29 git symbolic-ref FOO >actual &&
30 test_cmp expected actual
33 test_expect_success
'delete_refs(FOO, refs/tags/new-tag)' '
34 git tag -a -m new-tag new-tag HEAD &&
35 git rev-parse FOO -- &&
36 git rev-parse refs/tags/new-tag -- &&
37 m=$(git rev-parse main) &&
38 $RUN delete-refs REF_NO_DEREF nothing FOO refs/tags/new-tag &&
39 test_must_fail git rev-parse --symbolic-full-name FOO &&
40 test_must_fail git rev-parse FOO -- &&
41 test_must_fail git rev-parse refs/tags/new-tag --
44 # In reftable, we keep the reflogs around for deleted refs.
45 test_expect_success
!REFFILES
'delete-reflog(FOO, refs/tags/new-tag)' '
46 $RUN delete-reflog FOO &&
47 $RUN delete-reflog refs/tags/new-tag
50 test_expect_success
'rename_refs(main, new-main)' '
51 git rev-parse main >expected &&
52 $RUN rename-ref refs/heads/main refs/heads/new-main &&
53 git rev-parse new-main >actual &&
54 test_cmp expected actual &&
55 test_commit recreate-main
58 test_expect_success
'for_each_ref(refs/heads/)' '
59 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
60 cat >expected <<-\EOF &&
64 test_cmp expected actual
67 test_expect_success
'for_each_ref() is sorted' '
68 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
69 sort actual > expected &&
70 test_cmp expected actual
73 test_expect_success
'resolve_ref(new-main)' '
74 SHA1=`git rev-parse new-main` &&
75 echo "$SHA1 refs/heads/new-main 0x0" >expected &&
76 $RUN resolve-ref refs/heads/new-main 0 >actual &&
77 test_cmp expected actual
80 test_expect_success
'verify_ref(new-main)' '
81 $RUN verify-ref refs/heads/new-main
84 test_expect_success
'for_each_reflog()' '
85 $RUN for-each-reflog | sort -k2 | cut -d" " -f 2- >actual &&
86 cat >expected <<-\EOF &&
89 refs/heads/new-main 0x0
91 test_cmp expected actual
94 test_expect_success
'for_each_reflog_ent()' '
95 $RUN for-each-reflog-ent HEAD >actual &&
96 head -n1 actual | grep one &&
97 tail -n1 actual | grep recreate-main
100 test_expect_success
'for_each_reflog_ent_reverse()' '
101 $RUN for-each-reflog-ent-reverse HEAD >actual &&
102 head -n1 actual | grep recreate-main &&
103 tail -n1 actual | grep one
106 test_expect_success
'reflog_exists(HEAD)' '
107 $RUN reflog-exists HEAD
110 test_expect_success
'delete_reflog(HEAD)' '
111 $RUN delete-reflog HEAD &&
112 test_must_fail git reflog exists HEAD
115 test_expect_success REFFILES
'create-reflog(HEAD)' '
116 $RUN create-reflog HEAD &&
117 git reflog exists HEAD
120 test_expect_success
'delete_ref(refs/heads/foo)' '
121 git checkout -b foo &&
122 FOO_SHA1=`git rev-parse foo` &&
123 git checkout --detach &&
124 test_commit bar-commit &&
125 git checkout -b bar &&
126 BAR_SHA1=`git rev-parse bar` &&
127 $RUN update-ref updating refs/heads/foo $BAR_SHA1 $FOO_SHA1 0 &&
128 echo $BAR_SHA1 >expected &&
129 git rev-parse refs/heads/foo >actual &&
130 test_cmp expected actual
133 test_expect_success
'delete_ref(refs/heads/foo)' '
134 SHA1=`git rev-parse foo` &&
135 git checkout --detach &&
136 $RUN delete-ref msg refs/heads/foo $SHA1 0 &&
137 test_must_fail git rev-parse refs/heads/foo --