-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/bin/sh | ||
|
||
test_description='reftables are compatible with JGit' | ||
|
||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main | ||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | ||
GIT_TEST_DEFAULT_REF_FORMAT=reftable | ||
export GIT_TEST_DEFAULT_REF_FORMAT | ||
|
||
. ./test-lib.sh | ||
|
||
if ! test_have_prereq JGIT | ||
then | ||
skip_all='skipping reftable JGit tests' | ||
test_done | ||
fi | ||
|
||
test_commit_jgit () { | ||
touch "$1" && | ||
jgit add "$1" && | ||
jgit commit -m "$1" | ||
} | ||
|
||
test_same_refs () { | ||
git show-ref --head >cgit.actual && | ||
jgit show-ref >jgit-tabs.actual && | ||
tr "\t" " " <jgit-tabs.actual >jgit.actual && | ||
test_cmp cgit.actual jgit.actual | ||
} | ||
|
||
test_same_reflog () { | ||
git reflog "$*" >cgit.actual && | ||
jgit reflog "$*" >jgit-newline.actual && | ||
sed '/^$/d' <jgit-newline.actual >jgit.actual && | ||
test_cmp cgit.actual jgit.actual | ||
} | ||
|
||
test_expect_success 'CGit repository can be read by JGit' ' | ||
test_when_finished "rm -rf repo" && | ||
git init repo && | ||
( | ||
cd repo && | ||
test_commit A && | ||
test_same_refs && | ||
test_same_reflog HEAD | ||
) | ||
' | ||
|
||
test_expect_success 'JGit repository can be read by CGit' ' | ||
test_when_finished "rm -rf repo" && | ||
# JGit does not provide a way to create a reftable-enabled repository. | ||
git init repo && | ||
( | ||
cd repo && | ||
touch file && | ||
jgit add file && | ||
jgit commit -m "initial commit" && | ||
test_same_refs && | ||
# Interestingly, JGit cannot read its own reflog here. CGit can | ||
# though. | ||
echo -n "$(git rev-parse --short HEAD) HEAD@{0}: commit (initial): initial commit" >expect && | ||
git reflog HEAD >actual && | ||
test_cmp expect actual | ||
) | ||
' | ||
|
||
test_expect_success 'mixed writes from JGit and CGit' ' | ||
test_when_finished "rm -rf repo" && | ||
git init repo && | ||
( | ||
cd repo && | ||
test_commit A && | ||
test_commit_jgit B && | ||
test_commit C && | ||
test_commit_jgit D && | ||
test_same_refs && | ||
test_same_reflog HEAD | ||
) | ||
' | ||
|
||
test_expect_success 'JGit can read multi-level index' ' | ||
test_when_finished "rm -rf repo" && | ||
git init repo && | ||
( | ||
cd repo && | ||
test_commit A && | ||
awk " | ||
BEGIN { | ||
print \"start\"; | ||
for (i = 0; i < 10000; i++) | ||
printf \"create refs/heads/branch-%d HEAD\n\", i; | ||
print \"commit\"; | ||
} | ||
" >input && | ||
git update-ref --stdin <input && | ||
test_same_refs | ||
) | ||
' | ||
|
||
test_done |