]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1016-compatObjectFormat.sh
Merge branch 'jk/libcurl-8.7-regression-workaround'
[thirdparty/git.git] / t / t1016-compatObjectFormat.sh
CommitLineData
7673ecd2
EB
1#!/bin/sh
2#
3# Copyright (c) 2023 Eric Biederman
4#
5
6test_description='Test how well compatObjectFormat works'
7
8TEST_PASSES_SANITIZE_LEAK=true
9. ./test-lib.sh
10. "$TEST_DIRECTORY"/lib-gpg.sh
11
12# All of the follow variables must be defined in the environment:
13# GIT_AUTHOR_NAME
14# GIT_AUTHOR_EMAIL
15# GIT_AUTHOR_DATE
16# GIT_COMMITTER_NAME
17# GIT_COMMITTER_EMAIL
18# GIT_COMMITTER_DATE
19#
20# The test relies on these variables being set so that the two
21# different commits in two different repositories encoded with two
22# different hash functions result in the same content in the commits.
23# This means that when the commit is translated between hash functions
24# the commit is identical to the commit in the other repository.
25
26compat_hash () {
27 case "$1" in
28 "sha1")
29 echo "sha256"
30 ;;
31 "sha256")
32 echo "sha1"
33 ;;
34 esac
35}
36
37hello_oid () {
38 case "$1" in
39 "sha1")
40 echo "$hello_sha1_oid"
41 ;;
42 "sha256")
43 echo "$hello_sha256_oid"
44 ;;
45 esac
46}
47
48tree_oid () {
49 case "$1" in
50 "sha1")
51 echo "$tree_sha1_oid"
52 ;;
53 "sha256")
54 echo "$tree_sha256_oid"
55 ;;
56 esac
57}
58
59commit_oid () {
60 case "$1" in
61 "sha1")
62 echo "$commit_sha1_oid"
63 ;;
64 "sha256")
65 echo "$commit_sha256_oid"
66 ;;
67 esac
68}
69
70commit2_oid () {
71 case "$1" in
72 "sha1")
73 echo "$commit2_sha1_oid"
74 ;;
75 "sha256")
76 echo "$commit2_sha256_oid"
77 ;;
78 esac
79}
80
81del_sigcommit () {
82 local delete=$1
83
84 if test "$delete" = "sha256" ; then
85 local pattern="gpgsig-sha256"
86 else
87 local pattern="gpgsig"
88 fi
89 test-tool delete-gpgsig "$pattern"
90}
91
92
93del_sigtag () {
94 local storage=$1
95 local delete=$2
96
97 if test "$storage" = "$delete" ; then
98 local pattern="trailer"
99 elif test "$storage" = "sha256" ; then
100 local pattern="gpgsig"
101 else
102 local pattern="gpgsig-sha256"
103 fi
104 test-tool delete-gpgsig "$pattern"
105}
106
107base=$(pwd)
108for hash in sha1 sha256
109do
110 cd "$base"
111 mkdir -p repo-$hash
112 cd repo-$hash
113
114 test_expect_success "setup $hash repository" '
115 git init --object-format=$hash &&
116 git config core.repositoryformatversion 1 &&
117 git config extensions.objectformat $hash &&
118 git config extensions.compatobjectformat $(compat_hash $hash) &&
119 git config gpg.program $TEST_DIRECTORY/t1016/gpg &&
120 echo "Hellow World!" > hello &&
121 eval hello_${hash}_oid=$(git hash-object hello) &&
122 git update-index --add hello &&
123 git commit -m "Initial commit" &&
124 eval commit_${hash}_oid=$(git rev-parse HEAD) &&
125 eval tree_${hash}_oid=$(git rev-parse HEAD^{tree})
126 '
127 test_expect_success "create a $hash tagged blob" '
128 git tag --no-sign -m "This is a tag" hellotag $(hello_oid $hash) &&
129 eval hellotag_${hash}_oid=$(git rev-parse hellotag)
130 '
131 test_expect_success "create a $hash tagged tree" '
132 git tag --no-sign -m "This is a tag" treetag $(tree_oid $hash) &&
133 eval treetag_${hash}_oid=$(git rev-parse treetag)
134 '
135 test_expect_success "create a $hash tagged commit" '
136 git tag --no-sign -m "This is a tag" committag $(commit_oid $hash) &&
137 eval committag_${hash}_oid=$(git rev-parse committag)
138 '
139 test_expect_success GPG2 "create a $hash signed commit" '
140 git commit --gpg-sign --allow-empty -m "This is a signed commit" &&
141 eval signedcommit_${hash}_oid=$(git rev-parse HEAD)
142 '
143 test_expect_success GPG2 "create a $hash signed tag" '
144 git tag -s -m "This is a signed tag" signedtag HEAD &&
145 eval signedtag_${hash}_oid=$(git rev-parse signedtag)
146 '
147 test_expect_success "create a $hash branch" '
148 git checkout -b branch $(commit_oid $hash) &&
149 echo "More more more give me more!" > more &&
150 eval more_${hash}_oid=$(git hash-object more) &&
151 echo "Another and another and another" > another &&
152 eval another_${hash}_oid=$(git hash-object another) &&
153 git update-index --add more another &&
154 git commit -m "Add more files!" &&
155 eval commit2_${hash}_oid=$(git rev-parse HEAD) &&
156 eval tree2_${hash}_oid=$(git rev-parse HEAD^{tree})
157 '
158 test_expect_success GPG2 "create another $hash signed tag" '
159 git tag -s -m "This is another signed tag" signedtag2 $(commit2_oid $hash) &&
160 eval signedtag2_${hash}_oid=$(git rev-parse signedtag2)
161 '
162 test_expect_success GPG2 "merge the $hash branches together" '
163 git merge -S -m "merge some signed tags together" signedtag signedtag2 &&
164 eval signedcommit2_${hash}_oid=$(git rev-parse HEAD)
165 '
166 test_expect_success GPG2 "create additional $hash signed commits" '
167 git commit --gpg-sign --allow-empty -m "This is an additional signed commit" &&
168 git cat-file commit HEAD | del_sigcommit sha256 > "../${hash}_signedcommit3" &&
169 git cat-file commit HEAD | del_sigcommit sha1 > "../${hash}_signedcommit4" &&
170 eval signedcommit3_${hash}_oid=$(git hash-object -t commit -w ../${hash}_signedcommit3) &&
171 eval signedcommit4_${hash}_oid=$(git hash-object -t commit -w ../${hash}_signedcommit4)
172 '
173 test_expect_success GPG2 "create additional $hash signed tags" '
174 git tag -s -m "This is an additional signed tag" signedtag34 HEAD &&
175 git cat-file tag signedtag34 | del_sigtag "${hash}" sha256 > ../${hash}_signedtag3 &&
176 git cat-file tag signedtag34 | del_sigtag "${hash}" sha1 > ../${hash}_signedtag4 &&
177 eval signedtag3_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag3) &&
178 eval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)
179 '
180done
181cd "$base"
182
183compare_oids () {
184 test "$#" = 5 && { local PREREQ=$1; shift; } || PREREQ=
185 local type="$1"
186 local name="$2"
187 local sha1_oid="$3"
188 local sha256_oid="$4"
189
190 echo ${sha1_oid} > ${name}_sha1_expected
191 echo ${sha256_oid} > ${name}_sha256_expected
192 echo ${type} > ${name}_type_expected
193
194 git --git-dir=repo-sha1/.git rev-parse --output-object-format=sha256 ${sha1_oid} > ${name}_sha1_sha256_found
195 git --git-dir=repo-sha256/.git rev-parse --output-object-format=sha1 ${sha256_oid} > ${name}_sha256_sha1_found
196 local sha1_sha256_oid=$(cat ${name}_sha1_sha256_found)
197 local sha256_sha1_oid=$(cat ${name}_sha256_sha1_found)
198
199 test_expect_success $PREREQ "Verify ${type} ${name}'s sha1 oid" '
200 git --git-dir=repo-sha256/.git rev-parse --output-object-format=sha1 ${sha256_oid} > ${name}_sha1 &&
201 test_cmp ${name}_sha1 ${name}_sha1_expected
202'
203
204 test_expect_success $PREREQ "Verify ${type} ${name}'s sha256 oid" '
205 git --git-dir=repo-sha1/.git rev-parse --output-object-format=sha256 ${sha1_oid} > ${name}_sha256 &&
206 test_cmp ${name}_sha256 ${name}_sha256_expected
207'
208
209 test_expect_success $PREREQ "Verify ${name}'s sha1 type" '
210 git --git-dir=repo-sha1/.git cat-file -t ${sha1_oid} > ${name}_type1 &&
211 git --git-dir=repo-sha256/.git cat-file -t ${sha256_sha1_oid} > ${name}_type2 &&
212 test_cmp ${name}_type1 ${name}_type2 &&
213 test_cmp ${name}_type1 ${name}_type_expected
214'
215
216 test_expect_success $PREREQ "Verify ${name}'s sha256 type" '
217 git --git-dir=repo-sha256/.git cat-file -t ${sha256_oid} > ${name}_type3 &&
218 git --git-dir=repo-sha1/.git cat-file -t ${sha1_sha256_oid} > ${name}_type4 &&
219 test_cmp ${name}_type3 ${name}_type4 &&
220 test_cmp ${name}_type3 ${name}_type_expected
221'
222
223 test_expect_success $PREREQ "Verify ${name}'s sha1 size" '
224 git --git-dir=repo-sha1/.git cat-file -s ${sha1_oid} > ${name}_size1 &&
225 git --git-dir=repo-sha256/.git cat-file -s ${sha256_sha1_oid} > ${name}_size2 &&
226 test_cmp ${name}_size1 ${name}_size2
227'
228
229 test_expect_success $PREREQ "Verify ${name}'s sha256 size" '
230 git --git-dir=repo-sha256/.git cat-file -s ${sha256_oid} > ${name}_size3 &&
231 git --git-dir=repo-sha1/.git cat-file -s ${sha1_sha256_oid} > ${name}_size4 &&
232 test_cmp ${name}_size3 ${name}_size4
233'
234
235 test_expect_success $PREREQ "Verify ${name}'s sha1 pretty content" '
236 git --git-dir=repo-sha1/.git cat-file -p ${sha1_oid} > ${name}_content1 &&
237 git --git-dir=repo-sha256/.git cat-file -p ${sha256_sha1_oid} > ${name}_content2 &&
238 test_cmp ${name}_content1 ${name}_content2
239'
240
241 test_expect_success $PREREQ "Verify ${name}'s sha256 pretty content" '
242 git --git-dir=repo-sha256/.git cat-file -p ${sha256_oid} > ${name}_content3 &&
243 git --git-dir=repo-sha1/.git cat-file -p ${sha1_sha256_oid} > ${name}_content4 &&
244 test_cmp ${name}_content3 ${name}_content4
245'
246
247 test_expect_success $PREREQ "Verify ${name}'s sha1 content" '
248 git --git-dir=repo-sha1/.git cat-file ${type} ${sha1_oid} > ${name}_content5 &&
249 git --git-dir=repo-sha256/.git cat-file ${type} ${sha256_sha1_oid} > ${name}_content6 &&
250 test_cmp ${name}_content5 ${name}_content6
251'
252
253 test_expect_success $PREREQ "Verify ${name}'s sha256 content" '
254 git --git-dir=repo-sha256/.git cat-file ${type} ${sha256_oid} > ${name}_content7 &&
255 git --git-dir=repo-sha1/.git cat-file ${type} ${sha1_sha256_oid} > ${name}_content8 &&
256 test_cmp ${name}_content7 ${name}_content8
257'
258
259}
260
261compare_oids 'blob' hello "$hello_sha1_oid" "$hello_sha256_oid"
262compare_oids 'tree' tree "$tree_sha1_oid" "$tree_sha256_oid"
263compare_oids 'commit' commit "$commit_sha1_oid" "$commit_sha256_oid"
264compare_oids GPG2 'commit' signedcommit "$signedcommit_sha1_oid" "$signedcommit_sha256_oid"
265compare_oids 'tag' hellotag "$hellotag_sha1_oid" "$hellotag_sha256_oid"
266compare_oids 'tag' treetag "$treetag_sha1_oid" "$treetag_sha256_oid"
267compare_oids 'tag' committag "$committag_sha1_oid" "$committag_sha256_oid"
268compare_oids GPG2 'tag' signedtag "$signedtag_sha1_oid" "$signedtag_sha256_oid"
269
270compare_oids 'blob' more "$more_sha1_oid" "$more_sha256_oid"
271compare_oids 'blob' another "$another_sha1_oid" "$another_sha256_oid"
272compare_oids 'tree' tree2 "$tree2_sha1_oid" "$tree2_sha256_oid"
273compare_oids 'commit' commit2 "$commit2_sha1_oid" "$commit2_sha256_oid"
274compare_oids GPG2 'tag' signedtag2 "$signedtag2_sha1_oid" "$signedtag2_sha256_oid"
275compare_oids GPG2 'commit' signedcommit2 "$signedcommit2_sha1_oid" "$signedcommit2_sha256_oid"
276compare_oids GPG2 'commit' signedcommit3 "$signedcommit3_sha1_oid" "$signedcommit3_sha256_oid"
277compare_oids GPG2 'commit' signedcommit4 "$signedcommit4_sha1_oid" "$signedcommit4_sha256_oid"
278compare_oids GPG2 'tag' signedtag3 "$signedtag3_sha1_oid" "$signedtag3_sha256_oid"
279compare_oids GPG2 'tag' signedtag4 "$signedtag4_sha1_oid" "$signedtag4_sha256_oid"
280
281test_done