3 test_description
='split commit graph'
6 GIT_TEST_COMMIT_GRAPH
=0
7 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS
=0
9 test_expect_success
'setup repo' '
11 git config core.commitGraph true &&
12 git config gc.writeCommitGraph false &&
13 infodir=".git/objects/info" &&
14 graphdir="$infodir/commit-graphs" &&
32 header: 43475048 1 1 3 $NUM_BASE
34 chunks: oid_fanout oid_lookup commit_metadata
36 test-tool read-graph
>output
&&
37 test_cmp expect output
40 test_expect_success
'create commits and write commit-graph' '
41 for i in $(test_seq 3)
44 git branch commits/$i || return 1
46 git commit-graph write --reachable &&
47 test_path_is_file $infodir/commit-graph &&
51 graph_git_two_modes
() {
52 git
-c core.commitGraph
=true
$1 >output
53 git
-c core.commitGraph
=false
$1 >expect
54 test_cmp expect output
57 graph_git_behavior
() {
61 test_expect_success
"check normal git operations: $MSG" '
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"
70 graph_git_behavior
'graph exists' commits
/3 commits
/1
72 verify_chain_files_exist
() {
73 for hash in $
(cat $1/commit-graph-chain
)
75 test_path_is_file
$1/graph-
$hash.graph ||
return 1
79 test_expect_success
'add more commits, and write a new base graph' '
80 git reset --hard commits/1 &&
81 for i in $(test_seq 4 5)
84 git branch commits/$i || return 1
86 git reset --hard commits/2 &&
87 for i in $(test_seq 6 10)
90 git branch commits/$i || return 1
92 git reset --hard commits/2 &&
93 git merge commits/4 &&
95 git reset --hard commits/4 &&
96 git merge commits/6 &&
98 git commit-graph write --reachable &&
102 test_expect_success
'fork and fail to base a chain on a commit-graph file' '
103 test_when_finished rm -rf fork &&
107 rm .git/objects/info/commit-graph &&
108 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
109 test_commit new-commit &&
110 git commit-graph write --reachable --split &&
111 test_path_is_file $graphdir/commit-graph-chain &&
112 test_line_count = 1 $graphdir/commit-graph-chain &&
113 verify_chain_files_exist $graphdir
117 test_expect_success
'add three more commits, write a tip graph' '
118 git reset --hard commits/3 &&
120 git merge commits/5 &&
122 git branch merge/3 &&
123 git commit-graph write --reachable --split &&
124 test_path_is_missing $infodir/commit-graph &&
125 test_path_is_file $graphdir/commit-graph-chain &&
126 ls $graphdir/graph-*.graph >graph-files &&
127 test_line_count = 2 graph-files &&
128 verify_chain_files_exist $graphdir
131 graph_git_behavior
'split commit-graph: merge 3 vs 2' merge
/3 merge
/2
133 test_expect_success
'add one commit, write a tip graph' '
135 git branch commits/11 &&
136 git commit-graph write --reachable --split &&
137 test_path_is_missing $infodir/commit-graph &&
138 test_path_is_file $graphdir/commit-graph-chain &&
139 ls $graphdir/graph-*.graph >graph-files &&
140 test_line_count = 3 graph-files &&
141 verify_chain_files_exist $graphdir
144 graph_git_behavior
'three-layer commit-graph: commit 11 vs 6' commits
/11 commits
/6
146 test_expect_success
'add one commit, write a merged graph' '
148 git branch commits/12 &&
149 git commit-graph write --reachable --split &&
150 test_path_is_file $graphdir/commit-graph-chain &&
151 test_line_count = 2 $graphdir/commit-graph-chain &&
152 ls $graphdir/graph-*.graph >graph-files &&
153 test_line_count = 2 graph-files &&
154 verify_chain_files_exist $graphdir
157 graph_git_behavior
'merged commit-graph: commit 12 vs 6' commits
/12 commits
/6
159 test_expect_success
'create fork and chain across alternate' '
163 git config core.commitGraph true &&
165 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
167 git branch commits/13 &&
168 git commit-graph write --reachable --split &&
169 test_path_is_file $graphdir/commit-graph-chain &&
170 test_line_count = 3 $graphdir/commit-graph-chain &&
171 ls $graphdir/graph-*.graph >graph-files &&
172 test_line_count = 1 graph-files &&
173 git -c core.commitGraph=true rev-list HEAD >expect &&
174 git -c core.commitGraph=false rev-list HEAD >actual &&
175 test_cmp expect actual &&
177 git commit-graph write --reachable --split --object-dir=.git/objects/ &&
178 test_line_count = 3 $graphdir/commit-graph-chain &&
179 ls $graphdir/graph-*.graph >graph-files &&
180 test_line_count = 1 graph-files
184 graph_git_behavior
'alternate: commit 13 vs 6' commits
/13 commits
/6
186 test_expect_success
'test merge stragety constants' '
187 git clone . merge-2 &&
190 git config core.commitGraph true &&
191 test_line_count = 2 $graphdir/commit-graph-chain &&
193 git commit-graph write --reachable --split --size-multiple=2 &&
194 test_line_count = 3 $graphdir/commit-graph-chain
197 git clone . merge-10 &&
200 git config core.commitGraph true &&
201 test_line_count = 2 $graphdir/commit-graph-chain &&
203 git commit-graph write --reachable --split --size-multiple=10 &&
204 test_line_count = 1 $graphdir/commit-graph-chain &&
205 ls $graphdir/graph-*.graph >graph-files &&
206 test_line_count = 1 graph-files
208 git clone . merge-10-expire &&
210 cd merge-10-expire &&
211 git config core.commitGraph true &&
212 test_line_count = 2 $graphdir/commit-graph-chain &&
214 git commit-graph write --reachable --split --size-multiple=10 --expire-time=1980-01-01 &&
215 test_line_count = 1 $graphdir/commit-graph-chain &&
216 ls $graphdir/graph-*.graph >graph-files &&
217 test_line_count = 3 graph-files
219 git clone --no-hardlinks . max-commits &&
222 git config core.commitGraph true &&
223 test_line_count = 2 $graphdir/commit-graph-chain &&
226 git commit-graph write --reachable --split --max-commits=1 &&
227 test_line_count = 1 $graphdir/commit-graph-chain &&
228 ls $graphdir/graph-*.graph >graph-files &&
229 test_line_count = 1 graph-files
233 test_expect_success
'remove commit-graph-chain file after flattening' '
234 git clone . flatten &&
237 test_line_count = 2 $graphdir/commit-graph-chain &&
238 git commit-graph write --reachable &&
239 test_path_is_missing $graphdir/commit-graph-chain &&
240 ls $graphdir >graph-files &&
241 test_line_count = 0 graph-files
250 printf "$data" |
dd of
="$file" bs
=1 seek
="$pos" conv
=notrunc
253 test_expect_success
'verify hashes along chain, even in shallow' '
254 git clone --no-hardlinks . verify &&
257 git commit-graph verify &&
258 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
259 corrupt_file "$base_file" $(test_oid shallow) "\01" &&
260 test_must_fail git commit-graph verify --shallow 2>test_err &&
261 grep -v "^+" test_err >err &&
262 test_i18ngrep "incorrect checksum" err
266 test_expect_success
'verify --shallow does not check base contents' '
267 git clone --no-hardlinks . verify-shallow &&
270 git commit-graph verify &&
271 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
272 corrupt_file "$base_file" 1000 "\01" &&
273 git commit-graph verify --shallow &&
274 test_must_fail git commit-graph verify 2>test_err &&
275 grep -v "^+" test_err >err &&
276 test_i18ngrep "incorrect checksum" err
280 test_expect_success
'warn on base graph chunk incorrect' '
281 git clone --no-hardlinks . base-chunk &&
284 git commit-graph verify &&
285 base_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
286 corrupt_file "$base_file" $(test_oid base) "\01" &&
287 git commit-graph verify --shallow 2>test_err &&
288 grep -v "^+" test_err >err &&
289 test_i18ngrep "commit-graph chain does not match" err
293 test_expect_success
'verify after commit-graph-chain corruption' '
294 git clone --no-hardlinks . verify-chain &&
297 corrupt_file "$graphdir/commit-graph-chain" 60 "G" &&
298 git commit-graph verify 2>test_err &&
299 grep -v "^+" test_err >err &&
300 test_i18ngrep "invalid commit-graph chain" err &&
301 corrupt_file "$graphdir/commit-graph-chain" 60 "A" &&
302 git commit-graph verify 2>test_err &&
303 grep -v "^+" test_err >err &&
304 test_i18ngrep "unable to find all commit-graph files" err
308 test_expect_success
'verify across alternates' '
309 git clone --no-hardlinks . verify-alt &&
313 altdir="$(pwd)/../.git/objects" &&
314 echo "$altdir" >.git/objects/info/alternates &&
315 git commit-graph verify --object-dir="$altdir/" &&
317 git commit-graph write --reachable --split &&
318 tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
319 corrupt_file "$tip_file" 100 "\01" &&
320 test_must_fail git commit-graph verify --shallow 2>test_err &&
321 grep -v "^+" test_err >err &&
322 test_i18ngrep "commit-graph has incorrect fanout value" err
326 test_expect_success
'add octopus merge' '
327 git reset --hard commits/10 &&
328 git merge commits/3 commits/4 &&
329 git branch merge/octopus &&
330 git commit-graph write --reachable --split &&
331 git commit-graph verify --progress 2>err &&
332 test_line_count = 3 err &&
333 test_i18ngrep ! warning err &&
334 test_line_count = 3 $graphdir/commit-graph-chain
337 graph_git_behavior
'graph exists' merge
/octopus commits
/12
339 test_expect_success
'split across alternate where alternate is not split' '
340 git commit-graph write --reachable &&
341 test_path_is_file .git/objects/info/commit-graph &&
342 cp .git/objects/info/commit-graph . &&
343 git clone --no-hardlinks . alt-split &&
346 rm -f .git/objects/info/commit-graph &&
347 echo "$(pwd)"/../.git/objects >.git/objects/info/alternates &&
349 git commit-graph write --reachable --split &&
350 test_line_count = 1 $graphdir/commit-graph-chain
352 test_cmp commit-graph .git/objects/info/commit-graph