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