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