]>
Commit | Line | Data |
---|---|---|
f237c8b6 DS |
1 | #!/bin/sh |
2 | ||
3 | test_description='commit graph' | |
4 | . ./test-lib.sh | |
5 | ||
6 | test_expect_success 'setup full repo' ' | |
7 | mkdir full && | |
8 | cd "$TRASH_DIRECTORY/full" && | |
9 | git init && | |
177722b3 | 10 | git config core.commitGraph true && |
ae0c89d4 DS |
11 | objdir=".git/objects" && |
12 | test_oid_init | |
f237c8b6 DS |
13 | ' |
14 | ||
283e68c7 DS |
15 | test_expect_success 'verify graph with no graph file' ' |
16 | cd "$TRASH_DIRECTORY/full" && | |
17 | git commit-graph verify | |
18 | ' | |
19 | ||
f237c8b6 DS |
20 | test_expect_success 'write graph with no packs' ' |
21 | cd "$TRASH_DIRECTORY/full" && | |
22 | git commit-graph write --object-dir . && | |
6c622f9f | 23 | test_path_is_missing info/commit-graph |
f237c8b6 DS |
24 | ' |
25 | ||
e103f727 DS |
26 | test_expect_success 'close with correct error on bad input' ' |
27 | cd "$TRASH_DIRECTORY/full" && | |
28 | echo doesnotexist >in && | |
9916073b | 29 | test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr && |
e103f727 DS |
30 | test_i18ngrep "error adding pack" stderr |
31 | ' | |
32 | ||
f237c8b6 DS |
33 | test_expect_success 'create commits and repack' ' |
34 | cd "$TRASH_DIRECTORY/full" && | |
35 | for i in $(test_seq 3) | |
36 | do | |
37 | test_commit $i && | |
38 | git branch commits/$i | |
39 | done && | |
40 | git repack | |
41 | ' | |
42 | ||
177722b3 | 43 | graph_git_two_modes() { |
55abcb41 DS |
44 | git -c core.commitGraph=true $1 >output |
45 | git -c core.commitGraph=false $1 >expect | |
dcbaa0b3 | 46 | test_cmp expect output |
177722b3 DS |
47 | } |
48 | ||
49 | graph_git_behavior() { | |
50 | MSG=$1 | |
51 | DIR=$2 | |
52 | BRANCH=$3 | |
53 | COMPARE=$4 | |
54 | test_expect_success "check normal git operations: $MSG" ' | |
55 | cd "$TRASH_DIRECTORY/$DIR" && | |
56 | graph_git_two_modes "log --oneline $BRANCH" && | |
57 | graph_git_two_modes "log --topo-order $BRANCH" && | |
58 | graph_git_two_modes "log --graph $COMPARE..$BRANCH" && | |
59 | graph_git_two_modes "branch -vv" && | |
60 | graph_git_two_modes "merge-base -a $BRANCH $COMPARE" | |
61 | ' | |
62 | } | |
63 | ||
64 | graph_git_behavior 'no graph' full commits/3 commits/1 | |
65 | ||
2a2e32bd DS |
66 | graph_read_expect() { |
67 | OPTIONAL="" | |
68 | NUM_CHUNKS=3 | |
69 | if test ! -z $2 | |
70 | then | |
71 | OPTIONAL=" $2" | |
72 | NUM_CHUNKS=$((3 + $(echo "$2" | wc -w))) | |
73 | fi | |
74 | cat >expect <<- EOF | |
75 | header: 43475048 1 1 $NUM_CHUNKS 0 | |
76 | num_commits: $1 | |
77 | chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL | |
78 | EOF | |
79 | git commit-graph read >output && | |
80 | test_cmp expect output | |
81 | } | |
82 | ||
f237c8b6 DS |
83 | test_expect_success 'write graph' ' |
84 | cd "$TRASH_DIRECTORY/full" && | |
0b918b75 | 85 | git commit-graph write && |
2a2e32bd DS |
86 | test_path_is_file $objdir/info/commit-graph && |
87 | graph_read_expect "3" | |
f237c8b6 DS |
88 | ' |
89 | ||
177722b3 DS |
90 | graph_git_behavior 'graph exists' full commits/3 commits/1 |
91 | ||
f237c8b6 DS |
92 | test_expect_success 'Add more commits' ' |
93 | cd "$TRASH_DIRECTORY/full" && | |
94 | git reset --hard commits/1 && | |
95 | for i in $(test_seq 4 5) | |
96 | do | |
97 | test_commit $i && | |
98 | git branch commits/$i | |
99 | done && | |
100 | git reset --hard commits/2 && | |
101 | for i in $(test_seq 6 7) | |
102 | do | |
103 | test_commit $i && | |
104 | git branch commits/$i | |
105 | done && | |
106 | git reset --hard commits/2 && | |
107 | git merge commits/4 && | |
108 | git branch merge/1 && | |
109 | git reset --hard commits/4 && | |
110 | git merge commits/6 && | |
111 | git branch merge/2 && | |
112 | git reset --hard commits/3 && | |
113 | git merge commits/5 commits/7 && | |
114 | git branch merge/3 && | |
115 | git repack | |
116 | ' | |
117 | ||
118 | # Current graph structure: | |
119 | # | |
120 | # __M3___ | |
121 | # / | \ | |
122 | # 3 M1 5 M2 7 | |
123 | # |/ \|/ \| | |
124 | # 2 4 6 | |
125 | # |___/____/ | |
126 | # 1 | |
127 | ||
f237c8b6 DS |
128 | test_expect_success 'write graph with merges' ' |
129 | cd "$TRASH_DIRECTORY/full" && | |
130 | git commit-graph write && | |
2a2e32bd | 131 | test_path_is_file $objdir/info/commit-graph && |
5af7417b | 132 | graph_read_expect "10" "extra_edges" |
f237c8b6 DS |
133 | ' |
134 | ||
177722b3 DS |
135 | graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2 |
136 | graph_git_behavior 'merge 1 vs 3' full merge/1 merge/3 | |
137 | graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3 | |
138 | ||
f237c8b6 DS |
139 | test_expect_success 'Add one more commit' ' |
140 | cd "$TRASH_DIRECTORY/full" && | |
141 | test_commit 8 && | |
142 | git branch commits/8 && | |
143 | ls $objdir/pack | grep idx >existing-idx && | |
144 | git repack && | |
4a3ed638 | 145 | ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx |
f237c8b6 DS |
146 | ' |
147 | ||
148 | # Current graph structure: | |
149 | # | |
150 | # 8 | |
151 | # | | |
152 | # __M3___ | |
153 | # / | \ | |
154 | # 3 M1 5 M2 7 | |
155 | # |/ \|/ \| | |
156 | # 2 4 6 | |
157 | # |___/____/ | |
158 | # 1 | |
159 | ||
177722b3 DS |
160 | graph_git_behavior 'mixed mode, commit 8 vs merge 1' full commits/8 merge/1 |
161 | graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2 | |
162 | ||
f237c8b6 DS |
163 | test_expect_success 'write graph with new commit' ' |
164 | cd "$TRASH_DIRECTORY/full" && | |
165 | git commit-graph write && | |
2a2e32bd | 166 | test_path_is_file $objdir/info/commit-graph && |
5af7417b | 167 | graph_read_expect "11" "extra_edges" |
f237c8b6 DS |
168 | ' |
169 | ||
177722b3 DS |
170 | graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1 |
171 | graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2 | |
172 | ||
f237c8b6 DS |
173 | test_expect_success 'write graph with nothing new' ' |
174 | cd "$TRASH_DIRECTORY/full" && | |
175 | git commit-graph write && | |
2a2e32bd | 176 | test_path_is_file $objdir/info/commit-graph && |
5af7417b | 177 | graph_read_expect "11" "extra_edges" |
f237c8b6 DS |
178 | ' |
179 | ||
177722b3 DS |
180 | graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1 |
181 | graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2 | |
182 | ||
049d51a2 DS |
183 | test_expect_success 'build graph from latest pack with closure' ' |
184 | cd "$TRASH_DIRECTORY/full" && | |
185 | cat new-idx | git commit-graph write --stdin-packs && | |
186 | test_path_is_file $objdir/info/commit-graph && | |
5af7417b | 187 | graph_read_expect "9" "extra_edges" |
049d51a2 DS |
188 | ' |
189 | ||
190 | graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1 | |
191 | graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2 | |
192 | ||
3d5df01b DS |
193 | test_expect_success 'build graph from commits with closure' ' |
194 | cd "$TRASH_DIRECTORY/full" && | |
195 | git tag -a -m "merge" tag/merge merge/2 && | |
196 | git rev-parse tag/merge >commits-in && | |
197 | git rev-parse merge/1 >>commits-in && | |
198 | cat commits-in | git commit-graph write --stdin-commits && | |
199 | test_path_is_file $objdir/info/commit-graph && | |
200 | graph_read_expect "6" | |
201 | ' | |
202 | ||
203 | graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1 | |
204 | graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2 | |
205 | ||
7547b95b DS |
206 | test_expect_success 'build graph from commits with append' ' |
207 | cd "$TRASH_DIRECTORY/full" && | |
208 | git rev-parse merge/3 | git commit-graph write --stdin-commits --append && | |
209 | test_path_is_file $objdir/info/commit-graph && | |
5af7417b | 210 | graph_read_expect "10" "extra_edges" |
7547b95b DS |
211 | ' |
212 | ||
213 | graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1 | |
214 | graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2 | |
215 | ||
59fb8770 DS |
216 | test_expect_success 'build graph using --reachable' ' |
217 | cd "$TRASH_DIRECTORY/full" && | |
218 | git commit-graph write --reachable && | |
219 | test_path_is_file $objdir/info/commit-graph && | |
5af7417b | 220 | graph_read_expect "11" "extra_edges" |
59fb8770 DS |
221 | ' |
222 | ||
223 | graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1 | |
224 | graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2 | |
225 | ||
f237c8b6 DS |
226 | test_expect_success 'setup bare repo' ' |
227 | cd "$TRASH_DIRECTORY" && | |
228 | git clone --bare --no-local full bare && | |
229 | cd bare && | |
177722b3 | 230 | git config core.commitGraph true && |
f237c8b6 DS |
231 | baredir="./objects" |
232 | ' | |
233 | ||
177722b3 DS |
234 | graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1 |
235 | graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2 | |
236 | ||
f237c8b6 DS |
237 | test_expect_success 'write graph in bare repo' ' |
238 | cd "$TRASH_DIRECTORY/bare" && | |
239 | git commit-graph write && | |
2a2e32bd | 240 | test_path_is_file $baredir/info/commit-graph && |
5af7417b | 241 | graph_read_expect "11" "extra_edges" |
f237c8b6 DS |
242 | ' |
243 | ||
177722b3 DS |
244 | graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1 |
245 | graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2 | |
246 | ||
7adf5266 DS |
247 | test_expect_success 'perform fast-forward merge in full repo' ' |
248 | cd "$TRASH_DIRECTORY/full" && | |
249 | git checkout -b merge-5-to-8 commits/5 && | |
250 | git merge commits/8 && | |
251 | git show-ref -s merge-5-to-8 >output && | |
252 | git show-ref -s commits/8 >expect && | |
253 | test_cmp expect output | |
254 | ' | |
255 | ||
d5d5d7b6 DS |
256 | test_expect_success 'check that gc computes commit-graph' ' |
257 | cd "$TRASH_DIRECTORY/full" && | |
258 | git commit --allow-empty -m "blank" && | |
259 | git commit-graph write --reachable && | |
260 | cp $objdir/info/commit-graph commit-graph-before-gc && | |
261 | git reset --hard HEAD~1 && | |
262 | git config gc.writeCommitGraph true && | |
263 | git gc && | |
264 | cp $objdir/info/commit-graph commit-graph-after-gc && | |
eb7cc5bc | 265 | ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc && |
d5d5d7b6 | 266 | git commit-graph write --reachable && |
eb7cc5bc | 267 | test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph |
d5d5d7b6 DS |
268 | ' |
269 | ||
d6538246 DS |
270 | test_expect_success 'replace-objects invalidates commit-graph' ' |
271 | cd "$TRASH_DIRECTORY" && | |
272 | test_when_finished rm -rf replace && | |
273 | git clone full replace && | |
274 | ( | |
275 | cd replace && | |
276 | git commit-graph write --reachable && | |
277 | test_path_is_file .git/objects/info/commit-graph && | |
278 | git replace HEAD~1 HEAD~2 && | |
279 | git -c core.commitGraph=false log >expect && | |
280 | git -c core.commitGraph=true log >actual && | |
281 | test_cmp expect actual && | |
282 | git commit-graph write --reachable && | |
283 | git -c core.commitGraph=false --no-replace-objects log >expect && | |
284 | git -c core.commitGraph=true --no-replace-objects log >actual && | |
285 | test_cmp expect actual && | |
286 | rm -rf .git/objects/info/commit-graph && | |
287 | git commit-graph write --reachable && | |
288 | test_path_is_file .git/objects/info/commit-graph | |
289 | ) | |
290 | ' | |
291 | ||
20fd6d57 DS |
292 | test_expect_success 'commit grafts invalidate commit-graph' ' |
293 | cd "$TRASH_DIRECTORY" && | |
294 | test_when_finished rm -rf graft && | |
295 | git clone full graft && | |
296 | ( | |
297 | cd graft && | |
298 | git commit-graph write --reachable && | |
299 | test_path_is_file .git/objects/info/commit-graph && | |
300 | H1=$(git rev-parse --verify HEAD~1) && | |
301 | H3=$(git rev-parse --verify HEAD~3) && | |
302 | echo "$H1 $H3" >.git/info/grafts && | |
303 | git -c core.commitGraph=false log >expect && | |
304 | git -c core.commitGraph=true log >actual && | |
305 | test_cmp expect actual && | |
306 | git commit-graph write --reachable && | |
307 | git -c core.commitGraph=false --no-replace-objects log >expect && | |
308 | git -c core.commitGraph=true --no-replace-objects log >actual && | |
309 | test_cmp expect actual && | |
310 | rm -rf .git/objects/info/commit-graph && | |
311 | git commit-graph write --reachable && | |
312 | test_path_is_missing .git/objects/info/commit-graph | |
313 | ) | |
314 | ' | |
315 | ||
316 | test_expect_success 'replace-objects invalidates commit-graph' ' | |
317 | cd "$TRASH_DIRECTORY" && | |
318 | test_when_finished rm -rf shallow && | |
319 | git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow && | |
320 | ( | |
321 | cd shallow && | |
322 | git commit-graph write --reachable && | |
323 | test_path_is_missing .git/objects/info/commit-graph && | |
324 | git fetch origin --unshallow && | |
325 | git commit-graph write --reachable && | |
326 | test_path_is_file .git/objects/info/commit-graph | |
327 | ) | |
328 | ' | |
329 | ||
d9b9f8a6 DS |
330 | # the verify tests below expect the commit-graph to contain |
331 | # exactly the commits reachable from the commits/8 branch. | |
332 | # If the file changes the set of commits in the list, then the | |
333 | # offsets into the binary file will result in different edits | |
334 | # and the tests will likely break. | |
335 | ||
283e68c7 DS |
336 | test_expect_success 'git commit-graph verify' ' |
337 | cd "$TRASH_DIRECTORY/full" && | |
d9b9f8a6 | 338 | git rev-parse commits/8 | git commit-graph write --stdin-commits && |
283e68c7 DS |
339 | git commit-graph verify >output |
340 | ' | |
341 | ||
96af91d4 | 342 | NUM_COMMITS=9 |
437787ae | 343 | NUM_OCTOPUS_EDGES=2 |
ae0c89d4 | 344 | HASH_LEN="$(test_oid rawsz)" |
d9b9f8a6 DS |
345 | GRAPH_BYTE_VERSION=4 |
346 | GRAPH_BYTE_HASH=5 | |
2bd0365f DS |
347 | GRAPH_BYTE_CHUNK_COUNT=6 |
348 | GRAPH_CHUNK_LOOKUP_OFFSET=8 | |
349 | GRAPH_CHUNK_LOOKUP_WIDTH=12 | |
350 | GRAPH_CHUNK_LOOKUP_ROWS=5 | |
351 | GRAPH_BYTE_OID_FANOUT_ID=$GRAPH_CHUNK_LOOKUP_OFFSET | |
352 | GRAPH_BYTE_OID_LOOKUP_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \ | |
353 | 1 * $GRAPH_CHUNK_LOOKUP_WIDTH)) | |
354 | GRAPH_BYTE_COMMIT_DATA_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \ | |
355 | 2 * $GRAPH_CHUNK_LOOKUP_WIDTH)) | |
9bda8467 DS |
356 | GRAPH_FANOUT_OFFSET=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \ |
357 | $GRAPH_CHUNK_LOOKUP_WIDTH * $GRAPH_CHUNK_LOOKUP_ROWS)) | |
358 | GRAPH_BYTE_FANOUT1=$(($GRAPH_FANOUT_OFFSET + 4 * 4)) | |
359 | GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255)) | |
360 | GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256)) | |
361 | GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8)) | |
96af91d4 | 362 | GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10)) |
2e3c0737 DS |
363 | GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS)) |
364 | GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET | |
53614b13 DS |
365 | GRAPH_BYTE_COMMIT_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN)) |
366 | GRAPH_BYTE_COMMIT_EXTRA_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4)) | |
367 | GRAPH_BYTE_COMMIT_WRONG_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3)) | |
1373e547 | 368 | GRAPH_BYTE_COMMIT_GENERATION=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11)) |
88968ebf | 369 | GRAPH_BYTE_COMMIT_DATE=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12)) |
437787ae DS |
370 | GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16)) |
371 | GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \ | |
372 | $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS)) | |
373 | GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4)) | |
41df0e30 | 374 | GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES)) |
d9b9f8a6 | 375 | |
f6761faa ÆAB |
376 | corrupt_graph_setup() { |
377 | cd "$TRASH_DIRECTORY/full" && | |
378 | test_when_finished mv commit-graph-backup $objdir/info/commit-graph && | |
379 | cp $objdir/info/commit-graph commit-graph-backup | |
380 | } | |
381 | ||
382 | corrupt_graph_verify() { | |
383 | grepstr=$1 | |
384 | test_must_fail git commit-graph verify 2>test_err && | |
385 | grep -v "^+" test_err >err && | |
2ac138d5 | 386 | test_i18ngrep "$grepstr" err && |
43d35618 ÆAB |
387 | if test "$2" != "no-copy" |
388 | then | |
389 | cp $objdir/info/commit-graph commit-graph-pre-write-test | |
390 | fi && | |
391 | git status --short && | |
392 | GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write && | |
393 | git commit-graph verify | |
f6761faa ÆAB |
394 | } |
395 | ||
d2b86fba | 396 | # usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>] |
d9b9f8a6 | 397 | # Manipulates the commit-graph file at the position |
d2b86fba JS |
398 | # by inserting the data, optionally zeroing the file |
399 | # starting at <zero_pos>, then runs 'git commit-graph verify' | |
d9b9f8a6 DS |
400 | # and places the output in the file 'err'. Test 'err' for |
401 | # the given string. | |
402 | corrupt_graph_and_verify() { | |
403 | pos=$1 | |
404 | data="${2:-\0}" | |
405 | grepstr=$3 | |
f6761faa | 406 | corrupt_graph_setup && |
d2b86fba JS |
407 | orig_size=$(wc -c < $objdir/info/commit-graph) && |
408 | zero_pos=${4:-${orig_size}} && | |
d9b9f8a6 | 409 | printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc && |
b9cc4056 | 410 | dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null && |
24b451e7 | 411 | generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" && |
f6761faa ÆAB |
412 | corrupt_graph_verify "$grepstr" |
413 | ||
d9b9f8a6 DS |
414 | } |
415 | ||
7b8ce9c6 ÆAB |
416 | test_expect_success POSIXPERM,SANITY 'detect permission problem' ' |
417 | corrupt_graph_setup && | |
418 | chmod 000 $objdir/info/commit-graph && | |
43d35618 | 419 | corrupt_graph_verify "Could not open" "no-copy" |
7b8ce9c6 ÆAB |
420 | ' |
421 | ||
945944ca ÆAB |
422 | test_expect_success 'detect too small' ' |
423 | corrupt_graph_setup && | |
424 | echo "a small graph" >$objdir/info/commit-graph && | |
425 | corrupt_graph_verify "too small" | |
426 | ' | |
427 | ||
d9b9f8a6 DS |
428 | test_expect_success 'detect bad signature' ' |
429 | corrupt_graph_and_verify 0 "\0" \ | |
430 | "graph signature" | |
431 | ' | |
432 | ||
433 | test_expect_success 'detect bad version' ' | |
434 | corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \ | |
435 | "graph version" | |
436 | ' | |
437 | ||
438 | test_expect_success 'detect bad hash version' ' | |
439 | corrupt_graph_and_verify $GRAPH_BYTE_HASH "\02" \ | |
440 | "hash version" | |
441 | ' | |
442 | ||
2bd0365f DS |
443 | test_expect_success 'detect low chunk count' ' |
444 | corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\02" \ | |
445 | "missing the .* chunk" | |
446 | ' | |
447 | ||
448 | test_expect_success 'detect missing OID fanout chunk' ' | |
449 | corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \ | |
450 | "missing the OID Fanout chunk" | |
451 | ' | |
452 | ||
453 | test_expect_success 'detect missing OID lookup chunk' ' | |
454 | corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \ | |
455 | "missing the OID Lookup chunk" | |
456 | ' | |
457 | ||
458 | test_expect_success 'detect missing commit data chunk' ' | |
459 | corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \ | |
460 | "missing the Commit Data chunk" | |
461 | ' | |
462 | ||
9bda8467 DS |
463 | test_expect_success 'detect incorrect fanout' ' |
464 | corrupt_graph_and_verify $GRAPH_BYTE_FANOUT1 "\01" \ | |
465 | "fanout value" | |
466 | ' | |
467 | ||
468 | test_expect_success 'detect incorrect fanout final value' ' | |
469 | corrupt_graph_and_verify $GRAPH_BYTE_FANOUT2 "\01" \ | |
470 | "fanout value" | |
471 | ' | |
472 | ||
473 | test_expect_success 'detect incorrect OID order' ' | |
474 | corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ORDER "\01" \ | |
475 | "incorrect OID order" | |
476 | ' | |
477 | ||
96af91d4 DS |
478 | test_expect_success 'detect OID not in object database' ' |
479 | corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \ | |
480 | "from object database" | |
481 | ' | |
482 | ||
2e3c0737 DS |
483 | test_expect_success 'detect incorrect tree OID' ' |
484 | corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \ | |
485 | "root tree OID for commit" | |
486 | ' | |
487 | ||
53614b13 DS |
488 | test_expect_success 'detect incorrect parent int-id' ' |
489 | corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_PARENT "\01" \ | |
490 | "invalid parent" | |
491 | ' | |
492 | ||
493 | test_expect_success 'detect extra parent int-id' ' | |
494 | corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_EXTRA_PARENT "\00" \ | |
495 | "is too long" | |
496 | ' | |
497 | ||
498 | test_expect_success 'detect wrong parent' ' | |
499 | corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_WRONG_PARENT "\01" \ | |
500 | "commit-graph parent for" | |
501 | ' | |
502 | ||
1373e547 DS |
503 | test_expect_success 'detect incorrect generation number' ' |
504 | corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\070" \ | |
505 | "generation for commit" | |
506 | ' | |
507 | ||
508 | test_expect_success 'detect incorrect generation number' ' | |
509 | corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \ | |
510 | "non-zero generation number" | |
511 | ' | |
512 | ||
88968ebf DS |
513 | test_expect_success 'detect incorrect commit date' ' |
514 | corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \ | |
515 | "commit date" | |
516 | ' | |
517 | ||
437787ae DS |
518 | test_expect_success 'detect incorrect parent for octopus merge' ' |
519 | corrupt_graph_and_verify $GRAPH_BYTE_OCTOPUS "\01" \ | |
520 | "invalid parent" | |
521 | ' | |
522 | ||
41df0e30 DS |
523 | test_expect_success 'detect invalid checksum hash' ' |
524 | corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ | |
525 | "incorrect checksum" | |
526 | ' | |
527 | ||
d2b86fba JS |
528 | test_expect_success 'detect incorrect chunk count' ' |
529 | corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\377" \ | |
530 | "chunk lookup table entry missing" $GRAPH_CHUNK_LOOKUP_OFFSET | |
531 | ' | |
532 | ||
e0fd51e1 DS |
533 | test_expect_success 'git fsck (checks commit-graph)' ' |
534 | cd "$TRASH_DIRECTORY/full" && | |
535 | git fsck && | |
536 | corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ | |
537 | "incorrect checksum" && | |
43d35618 | 538 | cp commit-graph-pre-write-test $objdir/info/commit-graph && |
e0fd51e1 DS |
539 | test_must_fail git fsck |
540 | ' | |
541 | ||
dade47c0 JT |
542 | test_expect_success 'setup non-the_repository tests' ' |
543 | rm -rf repo && | |
544 | git init repo && | |
545 | test_commit -C repo one && | |
546 | test_commit -C repo two && | |
547 | git -C repo config core.commitGraph true && | |
548 | git -C repo rev-parse two | \ | |
549 | git -C repo commit-graph write --stdin-commits | |
550 | ' | |
551 | ||
552 | test_expect_success 'parse_commit_in_graph works for non-the_repository' ' | |
553 | test-tool repository parse_commit_in_graph \ | |
554 | repo/.git repo "$(git -C repo rev-parse two)" >actual && | |
3c458630 SG |
555 | { |
556 | git -C repo log --pretty=format:"%ct " -1 && | |
557 | git -C repo rev-parse one | |
558 | } >expect && | |
dade47c0 JT |
559 | test_cmp expect actual && |
560 | ||
561 | test-tool repository parse_commit_in_graph \ | |
562 | repo/.git repo "$(git -C repo rev-parse one)" >actual && | |
3c458630 | 563 | git -C repo log --pretty="%ct" -1 one >expect && |
dade47c0 JT |
564 | test_cmp expect actual |
565 | ' | |
566 | ||
567 | test_expect_success 'get_commit_tree_in_graph works for non-the_repository' ' | |
568 | test-tool repository get_commit_tree_in_graph \ | |
569 | repo/.git repo "$(git -C repo rev-parse two)" >actual && | |
3c458630 | 570 | git -C repo rev-parse two^{tree} >expect && |
dade47c0 JT |
571 | test_cmp expect actual && |
572 | ||
573 | test-tool repository get_commit_tree_in_graph \ | |
574 | repo/.git repo "$(git -C repo rev-parse one)" >actual && | |
3c458630 | 575 | git -C repo rev-parse one^{tree} >expect && |
dade47c0 JT |
576 | test_cmp expect actual |
577 | ' | |
578 | ||
f237c8b6 | 579 | test_done |