Skip to content

Commit 16feb99

Browse files
pcloudsgitster
authored andcommitted
t1405: some basic tests on main ref store
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80f2a60 commit 16feb99

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

t/t1405-main-ref-store.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/sh
2+
3+
test_description='test main ref store api'
4+
5+
. ./test-lib.sh
6+
7+
RUN="test-ref-store main"
8+
9+
test_expect_success 'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' '
10+
test_commit one &&
11+
N=`find .git/refs -type f | wc -l` &&
12+
test "$N" != 0 &&
13+
$RUN pack-refs 3 &&
14+
N=`find .git/refs -type f | wc -l`
15+
'
16+
17+
test_expect_success 'peel_ref(new-tag)' '
18+
git rev-parse HEAD >expected &&
19+
git tag -a -m new-tag new-tag HEAD &&
20+
$RUN peel-ref refs/tags/new-tag >actual &&
21+
test_cmp expected actual
22+
'
23+
24+
test_expect_success 'create_symref(FOO, refs/heads/master)' '
25+
$RUN create-symref FOO refs/heads/master nothing &&
26+
echo refs/heads/master >expected &&
27+
git symbolic-ref FOO >actual &&
28+
test_cmp expected actual
29+
'
30+
31+
test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
32+
git rev-parse FOO -- &&
33+
git rev-parse refs/tags/new-tag -- &&
34+
$RUN delete-refs 0 FOO refs/tags/new-tag &&
35+
test_must_fail git rev-parse FOO -- &&
36+
test_must_fail git rev-parse refs/tags/new-tag --
37+
'
38+
39+
test_expect_success 'rename_refs(master, new-master)' '
40+
git rev-parse master >expected &&
41+
$RUN rename-ref refs/heads/master refs/heads/new-master &&
42+
git rev-parse new-master >actual &&
43+
test_cmp expected actual &&
44+
test_commit recreate-master
45+
'
46+
47+
test_expect_success 'for_each_ref(refs/heads/)' '
48+
$RUN for-each-ref refs/heads/ | cut -c 42- >actual &&
49+
cat >expected <<-\EOF &&
50+
master 0x0
51+
new-master 0x0
52+
EOF
53+
test_cmp expected actual
54+
'
55+
56+
test_expect_success 'resolve_ref(new-master)' '
57+
SHA1=`git rev-parse new-master` &&
58+
echo "$SHA1 refs/heads/new-master 0x0" >expected &&
59+
$RUN resolve-ref refs/heads/new-master 0 >actual &&
60+
test_cmp expected actual
61+
'
62+
63+
test_expect_success 'verify_ref(new-master)' '
64+
$RUN verify-ref refs/heads/new-master
65+
'
66+
67+
test_expect_success 'for_each_reflog()' '
68+
$RUN for-each-reflog | sort | cut -c 42- >actual &&
69+
cat >expected <<-\EOF &&
70+
HEAD 0x1
71+
refs/heads/master 0x0
72+
refs/heads/new-master 0x0
73+
EOF
74+
test_cmp expected actual
75+
'
76+
77+
test_expect_success 'for_each_reflog_ent()' '
78+
$RUN for-each-reflog-ent HEAD >actual &&
79+
head -n1 actual | grep one &&
80+
tail -n2 actual | head -n1 | grep recreate-master
81+
'
82+
83+
test_expect_success 'for_each_reflog_ent_reverse()' '
84+
$RUN for-each-reflog-ent-reverse HEAD >actual &&
85+
head -n1 actual | grep recreate-master &&
86+
tail -n2 actual | head -n1 | grep one
87+
'
88+
89+
test_expect_success 'reflog_exists(HEAD)' '
90+
$RUN reflog-exists HEAD
91+
'
92+
93+
test_expect_success 'delete_reflog(HEAD)' '
94+
$RUN delete-reflog HEAD &&
95+
! test -f .git/logs/HEAD
96+
'
97+
98+
test_expect_success 'create-reflog(HEAD)' '
99+
$RUN create-reflog HEAD 1 &&
100+
test -f .git/logs/HEAD
101+
'
102+
103+
test_expect_success 'delete_ref(refs/heads/foo)' '
104+
git checkout -b foo &&
105+
FOO_SHA1=`git rev-parse foo` &&
106+
git checkout --detach &&
107+
test_commit bar-commit &&
108+
git checkout -b bar &&
109+
BAR_SHA1=`git rev-parse bar` &&
110+
$RUN update-ref updating refs/heads/foo $BAR_SHA1 $FOO_SHA1 0 &&
111+
echo $BAR_SHA1 >expected &&
112+
git rev-parse refs/heads/foo >actual &&
113+
test_cmp expected actual
114+
'
115+
116+
test_expect_success 'delete_ref(refs/heads/foo)' '
117+
SHA1=`git rev-parse foo` &&
118+
git checkout --detach &&
119+
$RUN delete-ref msg refs/heads/foo $SHA1 0 &&
120+
test_must_fail git rev-parse refs/heads/foo --
121+
'
122+
123+
test_done

0 commit comments

Comments
 (0)