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