3 test_description
='test main ref store api'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 RUN
="test-tool ref-store main"
13 test_expect_success
'setup' '
17 test_expect_success REFFILES
'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' '
18 N=`find .git/refs -type f | wc -l` &&
20 ALL_OR_PRUNE_FLAG=3 &&
21 $RUN pack-refs ${ALL_OR_PRUNE_FLAG} &&
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) &&
39 $RUN delete-refs $REF_NO_DEREF nothing FOO refs/tags/new-tag &&
40 test_must_fail git rev-parse --symbolic-full-name FOO &&
41 test_must_fail git rev-parse FOO -- &&
42 test_must_fail git rev-parse refs/tags/new-tag --
45 test_expect_success
'rename_refs(main, new-main)' '
46 git rev-parse main >expected &&
47 $RUN rename-ref refs/heads/main refs/heads/new-main &&
48 git rev-parse new-main >actual &&
49 test_cmp expected actual &&
50 test_commit recreate-main
53 test_expect_success
'for_each_ref(refs/heads/)' '
54 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
55 cat >expected <<-\EOF &&
59 test_cmp expected actual
62 test_expect_success
'for_each_ref() is sorted' '
63 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
64 sort actual > expected &&
65 test_cmp expected actual
68 test_expect_success
'resolve_ref(new-main)' '
69 SHA1=`git rev-parse new-main` &&
70 echo "$SHA1 refs/heads/new-main 0x0" >expected &&
71 $RUN resolve-ref refs/heads/new-main 0 >actual &&
72 test_cmp expected actual
75 test_expect_success
'verify_ref(new-main)' '
76 $RUN verify-ref refs/heads/new-main
79 test_expect_success
'for_each_reflog()' '
80 $RUN for-each-reflog | sort -k2 | cut -d" " -f 2- >actual &&
81 cat >expected <<-\EOF &&
84 refs/heads/new-main 0x0
86 test_cmp expected actual
89 test_expect_success
'for_each_reflog_ent()' '
90 $RUN for-each-reflog-ent HEAD >actual &&
91 head -n1 actual | grep one &&
92 tail -n2 actual | head -n1 | grep recreate-main
95 test_expect_success
'for_each_reflog_ent_reverse()' '
96 $RUN for-each-reflog-ent-reverse HEAD >actual &&
97 head -n1 actual | grep recreate-main &&
98 tail -n2 actual | head -n1 | grep one
101 test_expect_success
'reflog_exists(HEAD)' '
102 $RUN reflog-exists HEAD
105 test_expect_success
'delete_reflog(HEAD)' '
106 $RUN delete-reflog HEAD &&
107 test_must_fail git reflog exists HEAD
110 test_expect_success
'create-reflog(HEAD)' '
111 $RUN create-reflog HEAD 1 &&
112 git reflog exists HEAD
115 test_expect_success
'delete_ref(refs/heads/foo)' '
116 git checkout -b foo &&
117 FOO_SHA1=`git rev-parse foo` &&
118 git checkout --detach &&
119 test_commit bar-commit &&
120 git checkout -b bar &&
121 BAR_SHA1=`git rev-parse bar` &&
122 $RUN update-ref updating refs/heads/foo $BAR_SHA1 $FOO_SHA1 0 &&
123 echo $BAR_SHA1 >expected &&
124 git rev-parse refs/heads/foo >actual &&
125 test_cmp expected actual
128 test_expect_success
'delete_ref(refs/heads/foo)' '
129 SHA1=`git rev-parse foo` &&
130 git checkout --detach &&
131 $RUN delete-ref msg refs/heads/foo $SHA1 0 &&
132 test_must_fail git rev-parse refs/heads/foo --