Sync with Git 2.46-rc1
[alt-git.git] / t / t0612-reftable-jgit-compatibility.sh
blob84922153ab6a6d1aca3ce79d42a290a3899b372a
1 #!/bin/sh
3 test_description='reftables are compatible with JGit'
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
10 # JGit does not support the 'link' DIRC extension.
11 GIT_TEST_SPLIT_INDEX=0
12 export GIT_TEST_SPLIT_INDEX
14 TEST_PASSES_SANITIZE_LEAK=true
15 . ./test-lib.sh
17 if ! test_have_prereq JGIT
18 then
19 skip_all='skipping reftable JGit tests; JGit is not present in PATH'
20 test_done
23 if ! test_have_prereq SHA1
24 then
25 skip_all='skipping reftable JGit tests; JGit does not support SHA256 reftables'
26 test_done
29 test_commit_jgit () {
30 touch "$1" &&
31 jgit add "$1" &&
32 jgit commit -m "$1"
35 test_same_refs () {
36 git show-ref --head >cgit.actual &&
37 jgit show-ref >jgit-tabs.actual &&
38 tr "\t" " " <jgit-tabs.actual >jgit.actual &&
39 test_cmp cgit.actual jgit.actual
42 test_same_ref () {
43 git rev-parse "$1" >cgit.actual &&
44 jgit rev-parse "$1" >jgit.actual &&
45 test_cmp cgit.actual jgit.actual
48 test_same_reflog () {
49 git reflog "$*" >cgit.actual &&
50 jgit reflog "$*" >jgit-newline.actual &&
51 sed '/^$/d' <jgit-newline.actual >jgit.actual &&
52 test_cmp cgit.actual jgit.actual
55 test_expect_success 'CGit repository can be read by JGit' '
56 test_when_finished "rm -rf repo" &&
57 git init repo &&
59 cd repo &&
60 test_commit A &&
61 test_same_refs &&
62 test_same_ref HEAD &&
63 test_same_reflog HEAD
67 test_expect_success 'JGit repository can be read by CGit' '
68 test_when_finished "rm -rf repo" &&
69 jgit init repo &&
71 cd repo &&
73 touch file &&
74 jgit add file &&
75 jgit commit -m "initial commit" &&
77 # Note that we must convert the ref storage after we have
78 # written the default branch. Otherwise JGit will end up with
79 # no HEAD at all.
80 jgit convert-ref-storage --format=reftable &&
82 test_same_refs &&
83 test_same_ref HEAD &&
84 # Interestingly, JGit cannot read its own reflog here. CGit can
85 # though.
86 printf "%s HEAD@{0}: commit (initial): initial commit" "$(git rev-parse --short HEAD)" >expect &&
87 git reflog HEAD >actual &&
88 test_cmp expect actual
92 test_expect_success 'mixed writes from JGit and CGit' '
93 test_when_finished "rm -rf repo" &&
94 git init repo &&
96 cd repo &&
98 test_commit A &&
99 test_commit_jgit B &&
100 test_commit C &&
101 test_commit_jgit D &&
103 test_same_refs &&
104 test_same_ref HEAD &&
105 test_same_reflog HEAD
109 test_expect_success 'JGit can read multi-level index' '
110 test_when_finished "rm -rf repo" &&
111 git init repo &&
113 cd repo &&
115 test_commit A &&
116 awk "
117 BEGIN {
118 print \"start\";
119 for (i = 0; i < 10000; i++)
120 printf \"create refs/heads/branch-%d HEAD\n\", i;
121 print \"commit\";
123 " >input &&
124 git update-ref --stdin <input &&
126 test_same_refs &&
127 test_same_ref refs/heads/branch-1 &&
128 test_same_ref refs/heads/branch-5738 &&
129 test_same_ref refs/heads/branch-9999
133 test_done