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