Git fork
1#!/bin/sh
2
3test_description='reftables are compatible with JGit'
4
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7GIT_TEST_DEFAULT_REF_FORMAT=reftable
8export GIT_TEST_DEFAULT_REF_FORMAT
9
10# JGit does not support the 'link' DIRC extension.
11GIT_TEST_SPLIT_INDEX=0
12export GIT_TEST_SPLIT_INDEX
13
14. ./test-lib.sh
15
16if ! test_have_prereq JGIT
17then
18 skip_all='skipping reftable JGit tests; JGit is not present in PATH'
19 test_done
20fi
21
22if ! test_have_prereq SHA1
23then
24 skip_all='skipping reftable JGit tests; JGit does not support SHA256 reftables'
25 test_done
26fi
27
28test_commit_jgit () {
29 touch "$1" &&
30 jgit add "$1" &&
31 jgit commit -m "$1"
32}
33
34test_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
41test_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
47test_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
54test_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
66test_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
91test_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
108test_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 {
116 echo start &&
117 test_seq -f "create refs/heads/branch-%d HEAD" 10000 &&
118 echo commit
119 } >input &&
120 git update-ref --stdin <input &&
121
122 test_same_refs &&
123 test_same_ref refs/heads/branch-1 &&
124 test_same_ref refs/heads/branch-5738 &&
125 test_same_ref refs/heads/branch-9999
126 )
127'
128
129test_done