]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1405-main-ref-store.sh
Sync with 2.36.3
[thirdparty/git.git] / t / t1405-main-ref-store.sh
CommitLineData
16feb99d
NTND
1#!/bin/sh
2
3test_description='test main ref store api'
4
06d53148 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
16feb99d
NTND
8. ./test-lib.sh
9
65370d81 10RUN="test-tool ref-store main"
16feb99d 11
a50234b3
HWN
12
13test_expect_success 'setup' '
14 test_commit one
15'
16
17test_expect_success REFFILES 'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' '
16feb99d
NTND
18 N=`find .git/refs -type f | wc -l` &&
19 test "$N" != 0 &&
cd2d40fb 20 $RUN pack-refs PACK_REFS_PRUNE,PACK_REFS_ALL &&
a50234b3
HWN
21 N=`find .git/refs -type f` &&
22 test -z "$N"
16feb99d
NTND
23'
24
06d53148
JS
25test_expect_success 'create_symref(FOO, refs/heads/main)' '
26 $RUN create-symref FOO refs/heads/main nothing &&
27 echo refs/heads/main >expected &&
16feb99d
NTND
28 git symbolic-ref FOO >actual &&
29 test_cmp expected actual
30'
31
32test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
36a31792 33 git tag -a -m new-tag new-tag HEAD &&
16feb99d
NTND
34 git rev-parse FOO -- &&
35 git rev-parse refs/tags/new-tag -- &&
06d53148 36 m=$(git rev-parse main) &&
93db6eef 37 $RUN delete-refs REF_NO_DEREF nothing FOO refs/tags/new-tag &&
09743417 38 test_must_fail git rev-parse --symbolic-full-name FOO &&
16feb99d
NTND
39 test_must_fail git rev-parse FOO -- &&
40 test_must_fail git rev-parse refs/tags/new-tag --
41'
42
5e005147
HWN
43# In reftable, we keep the reflogs around for deleted refs.
44test_expect_success !REFFILES 'delete-reflog(FOO, refs/tags/new-tag)' '
45 $RUN delete-reflog FOO &&
46 $RUN delete-reflog refs/tags/new-tag
47'
48
06d53148
JS
49test_expect_success 'rename_refs(main, new-main)' '
50 git rev-parse main >expected &&
51 $RUN rename-ref refs/heads/main refs/heads/new-main &&
52 git rev-parse new-main >actual &&
16feb99d 53 test_cmp expected actual &&
06d53148 54 test_commit recreate-main
16feb99d
NTND
55'
56
57test_expect_success 'for_each_ref(refs/heads/)' '
64af7752 58 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
16feb99d 59 cat >expected <<-\EOF &&
06d53148
JS
60 main 0x0
61 new-main 0x0
16feb99d
NTND
62 EOF
63 test_cmp expected actual
64'
65
adac8115 66test_expect_success 'for_each_ref() is sorted' '
63477b32 67 $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
adac8115
NTND
68 sort actual > expected &&
69 test_cmp expected actual
70'
71
06d53148
JS
72test_expect_success 'resolve_ref(new-main)' '
73 SHA1=`git rev-parse new-main` &&
74 echo "$SHA1 refs/heads/new-main 0x0" >expected &&
75 $RUN resolve-ref refs/heads/new-main 0 >actual &&
16feb99d
NTND
76 test_cmp expected actual
77'
78
06d53148
JS
79test_expect_success 'verify_ref(new-main)' '
80 $RUN verify-ref refs/heads/new-main
16feb99d
NTND
81'
82
83test_expect_success 'for_each_reflog()' '
63477b32 84 $RUN for-each-reflog | sort -k2 | cut -d" " -f 2- >actual &&
16feb99d
NTND
85 cat >expected <<-\EOF &&
86 HEAD 0x1
06d53148
JS
87 refs/heads/main 0x0
88 refs/heads/new-main 0x0
16feb99d
NTND
89 EOF
90 test_cmp expected actual
91'
92
93test_expect_success 'for_each_reflog_ent()' '
94 $RUN for-each-reflog-ent HEAD >actual &&
95 head -n1 actual | grep one &&
21f0e850 96 tail -n1 actual | grep recreate-main
16feb99d
NTND
97'
98
99test_expect_success 'for_each_reflog_ent_reverse()' '
100 $RUN for-each-reflog-ent-reverse HEAD >actual &&
06d53148 101 head -n1 actual | grep recreate-main &&
21f0e850 102 tail -n1 actual | grep one
16feb99d
NTND
103'
104
105test_expect_success 'reflog_exists(HEAD)' '
106 $RUN reflog-exists HEAD
107'
108
109test_expect_success 'delete_reflog(HEAD)' '
110 $RUN delete-reflog HEAD &&
ace40eab 111 test_must_fail git reflog exists HEAD
16feb99d
NTND
112'
113
53af25e4 114test_expect_success REFFILES 'create-reflog(HEAD)' '
7b089120 115 $RUN create-reflog HEAD &&
ace40eab 116 git reflog exists HEAD
16feb99d
NTND
117'
118
119test_expect_success 'delete_ref(refs/heads/foo)' '
120 git checkout -b foo &&
121 FOO_SHA1=`git rev-parse foo` &&
122 git checkout --detach &&
123 test_commit bar-commit &&
124 git checkout -b bar &&
125 BAR_SHA1=`git rev-parse bar` &&
126 $RUN update-ref updating refs/heads/foo $BAR_SHA1 $FOO_SHA1 0 &&
127 echo $BAR_SHA1 >expected &&
128 git rev-parse refs/heads/foo >actual &&
129 test_cmp expected actual
130'
131
132test_expect_success 'delete_ref(refs/heads/foo)' '
133 SHA1=`git rev-parse foo` &&
134 git checkout --detach &&
135 $RUN delete-ref msg refs/heads/foo $SHA1 0 &&
136 test_must_fail git rev-parse refs/heads/foo --
137'
138
139test_done