Skip to content

Commit 70b81fb

Browse files
pks-tgitster
authored andcommitted
t0612: add tests to exercise Git/JGit reftable compatibility
While the reftable format is a recent introduction in Git, JGit already knows to read and write reftables since 2017. Given the complexity of the format there is a very real risk of incompatibilities between those two implementations, which is something that we really want to avoid. Add some basic tests that verify that reftables written by Git and JGit can be read by the respective other implementation. For now this test suite is rather small, only covering basic functionality. But it serves as a good starting point and can be extended over time. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent db1d63b commit 70b81fb

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/sh
2+
3+
test_description='reftables are compatible with JGit'
4+
5+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7+
GIT_TEST_DEFAULT_REF_FORMAT=reftable
8+
export GIT_TEST_DEFAULT_REF_FORMAT
9+
10+
# JGit does not support the 'link' DIRC extension.
11+
GIT_TEST_SPLIT_INDEX=0
12+
export GIT_TEST_SPLIT_INDEX
13+
14+
. ./test-lib.sh
15+
16+
if ! test_have_prereq JGIT
17+
then
18+
skip_all='skipping reftable JGit tests; JGit is not present in PATH'
19+
test_done
20+
fi
21+
22+
if ! test_have_prereq SHA1
23+
then
24+
skip_all='skipping reftable JGit tests; JGit does not support SHA256 reftables'
25+
test_done
26+
fi
27+
28+
test_commit_jgit () {
29+
touch "$1" &&
30+
jgit add "$1" &&
31+
jgit commit -m "$1"
32+
}
33+
34+
test_same_refs () {
35+
git show-ref --head >cgit.actual &&
36+
jgit show-ref >jgit-tabs.actual &&
37+
tr "\t" " " <jgit-tabs.actual >jgit.actual &&
38+
test_cmp cgit.actual jgit.actual
39+
}
40+
41+
test_same_ref () {
42+
git rev-parse "$1" >cgit.actual &&
43+
jgit rev-parse "$1" >jgit.actual &&
44+
test_cmp cgit.actual jgit.actual
45+
}
46+
47+
test_same_reflog () {
48+
git reflog "$*" >cgit.actual &&
49+
jgit reflog "$*" >jgit-newline.actual &&
50+
sed '/^$/d' <jgit-newline.actual >jgit.actual &&
51+
test_cmp cgit.actual jgit.actual
52+
}
53+
54+
test_expect_success 'CGit repository can be read by JGit' '
55+
test_when_finished "rm -rf repo" &&
56+
git init repo &&
57+
(
58+
cd repo &&
59+
test_commit A &&
60+
test_same_refs &&
61+
test_same_ref HEAD &&
62+
test_same_reflog HEAD
63+
)
64+
'
65+
66+
test_expect_success 'JGit repository can be read by CGit' '
67+
test_when_finished "rm -rf repo" &&
68+
jgit init repo &&
69+
(
70+
cd repo &&
71+
72+
touch file &&
73+
jgit add file &&
74+
jgit commit -m "initial commit" &&
75+
76+
# Note that we must convert the ref storage after we have
77+
# written the default branch. Otherwise JGit will end up with
78+
# no HEAD at all.
79+
jgit convert-ref-storage --format=reftable &&
80+
81+
test_same_refs &&
82+
test_same_ref HEAD &&
83+
# Interestingly, JGit cannot read its own reflog here. CGit can
84+
# though.
85+
printf "%s HEAD@{0}: commit (initial): initial commit" "$(git rev-parse --short HEAD)" >expect &&
86+
git reflog HEAD >actual &&
87+
test_cmp expect actual
88+
)
89+
'
90+
91+
test_expect_success 'mixed writes from JGit and CGit' '
92+
test_when_finished "rm -rf repo" &&
93+
git init repo &&
94+
(
95+
cd repo &&
96+
97+
test_commit A &&
98+
test_commit_jgit B &&
99+
test_commit C &&
100+
test_commit_jgit D &&
101+
102+
test_same_refs &&
103+
test_same_ref HEAD &&
104+
test_same_reflog HEAD
105+
)
106+
'
107+
108+
test_expect_success 'JGit can read multi-level index' '
109+
test_when_finished "rm -rf repo" &&
110+
git init repo &&
111+
(
112+
cd repo &&
113+
114+
test_commit A &&
115+
awk "
116+
BEGIN {
117+
print \"start\";
118+
for (i = 0; i < 10000; i++)
119+
printf \"create refs/heads/branch-%d HEAD\n\", i;
120+
print \"commit\";
121+
}
122+
" >input &&
123+
git update-ref --stdin <input &&
124+
125+
test_same_refs &&
126+
test_same_ref refs/heads/branch-1 &&
127+
test_same_ref refs/heads/branch-5738 &&
128+
test_same_ref refs/heads/branch-9999
129+
)
130+
'
131+
132+
test_done

0 commit comments

Comments
 (0)