commit-graph: check all leading directories in changed path Bloom filters
[git] / t / t5324-split-commit-graph.sh
1 #!/bin/sh
2
3 test_description='split commit graph'
4 . ./test-lib.sh
5
6 GIT_TEST_COMMIT_GRAPH=0
7 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
8
9 test_expect_success 'setup repo' '
10         git init &&
11         git config core.commitGraph true &&
12         git config gc.writeCommitGraph false &&
13         infodir=".git/objects/info" &&
14         graphdir="$infodir/commit-graphs" &&
15         test_oid_init &&
16         test_oid_cache <<-EOM
17         shallow sha1:1760
18         shallow sha256:2064
19
20         base sha1:1376
21         base sha256:1496
22         EOM
23 '
24
25 graph_read_expect() {
26         NUM_BASE=0
27         if test ! -z $2
28         then
29                 NUM_BASE=$2
30         fi
31         cat >expect <<- EOF
32         header: 43475048 1 1 3 $NUM_BASE
33         num_commits: $1
34         chunks: oid_fanout oid_lookup commit_metadata
35         EOF
36         test-tool read-graph >output &&
37         test_cmp expect output
38 }
39
40 test_expect_success 'create commits and write commit-graph' '
41         for i in $(test_seq 3)
42         do
43                 test_commit $i &&
44                 git branch commits/$i || return 1
45         done &&
46         git commit-graph write --reachable &&
47         test_path_is_file $infodir/commit-graph &&
48         graph_read_expect 3
49 '
50
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
55 }
56
57 graph_git_behavior() {
58         MSG=$1
59         BRANCH=$2
60         COMPARE=$3
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"
67         '
68 }
69
70 graph_git_behavior 'graph exists' commits/3 commits/1
71
72 verify_chain_files_exist() {
73         for hash in $(cat $1/commit-graph-chain)
74         do
75                 test_path_is_file $1/graph-$hash.graph || return 1
76         done
77 }
78
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)
82         do
83                 test_commit $i &&
84                 git branch commits/$i || return 1
85         done &&
86         git reset --hard commits/2 &&
87         for i in $(test_seq 6 10)
88         do
89                 test_commit $i &&
90                 git branch commits/$i || return 1
91         done &&
92         git reset --hard commits/2 &&
93         git merge commits/4 &&
94         git branch merge/1 &&
95         git reset --hard commits/4 &&
96         git merge commits/6 &&
97         git branch merge/2 &&
98         git commit-graph write --reachable &&
99         graph_read_expect 12
100 '
101
102 test_expect_success 'fork and fail to base a chain on a commit-graph file' '
103         test_when_finished rm -rf fork &&
104         git clone . fork &&
105         (
106                 cd 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
114         )
115 '
116
117 test_expect_success 'add three more commits, write a tip graph' '
118         git reset --hard commits/3 &&
119         git merge merge/1 &&
120         git merge commits/5 &&
121         git merge merge/2 &&
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
129 '
130
131 graph_git_behavior 'split commit-graph: merge 3 vs 2' merge/3 merge/2
132
133 test_expect_success 'add one commit, write a tip graph' '
134         test_commit 11 &&
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
142 '
143
144 graph_git_behavior 'three-layer commit-graph: commit 11 vs 6' commits/11 commits/6
145
146 test_expect_success 'add one commit, write a merged graph' '
147         test_commit 12 &&
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
155 '
156
157 graph_git_behavior 'merged commit-graph: commit 12 vs 6' commits/12 commits/6
158
159 test_expect_success 'create fork and chain across alternate' '
160         git clone . fork &&
161         (
162                 cd fork &&
163                 git config core.commitGraph true &&
164                 rm -rf $graphdir &&
165                 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
166                 test_commit 13 &&
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 &&
176                 test_commit 14 &&
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
181         )
182 '
183
184 graph_git_behavior 'alternate: commit 13 vs 6' commits/13 commits/6
185
186 test_expect_success 'test merge stragety constants' '
187         git clone . merge-2 &&
188         (
189                 cd merge-2 &&
190                 git config core.commitGraph true &&
191                 test_line_count = 2 $graphdir/commit-graph-chain &&
192                 test_commit 14 &&
193                 git commit-graph write --reachable --split --size-multiple=2 &&
194                 test_line_count = 3 $graphdir/commit-graph-chain
195
196         ) &&
197         git clone . merge-10 &&
198         (
199                 cd merge-10 &&
200                 git config core.commitGraph true &&
201                 test_line_count = 2 $graphdir/commit-graph-chain &&
202                 test_commit 14 &&
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
207         ) &&
208         git clone . merge-10-expire &&
209         (
210                 cd merge-10-expire &&
211                 git config core.commitGraph true &&
212                 test_line_count = 2 $graphdir/commit-graph-chain &&
213                 test_commit 15 &&
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
218         ) &&
219         git clone --no-hardlinks . max-commits &&
220         (
221                 cd max-commits &&
222                 git config core.commitGraph true &&
223                 test_line_count = 2 $graphdir/commit-graph-chain &&
224                 test_commit 16 &&
225                 test_commit 17 &&
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
230         )
231 '
232
233 test_expect_success 'remove commit-graph-chain file after flattening' '
234         git clone . flatten &&
235         (
236                 cd 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
242         )
243 '
244
245 corrupt_file() {
246         file=$1
247         pos=$2
248         data="${3:-\0}"
249         chmod a+w "$file" &&
250         printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
251 }
252
253 test_expect_success 'verify hashes along chain, even in shallow' '
254         git clone --no-hardlinks . verify &&
255         (
256                 cd 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
263         )
264 '
265
266 test_expect_success 'verify --shallow does not check base contents' '
267         git clone --no-hardlinks . verify-shallow &&
268         (
269                 cd 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
277         )
278 '
279
280 test_expect_success 'warn on base graph chunk incorrect' '
281         git clone --no-hardlinks . base-chunk &&
282         (
283                 cd 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
290         )
291 '
292
293 test_expect_success 'verify after commit-graph-chain corruption' '
294         git clone --no-hardlinks . verify-chain &&
295         (
296                 cd 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
305         )
306 '
307
308 test_expect_success 'verify across alternates' '
309         git clone --no-hardlinks . verify-alt &&
310         (
311                 cd verify-alt &&
312                 rm -rf $graphdir &&
313                 altdir="$(pwd)/../.git/objects" &&
314                 echo "$altdir" >.git/objects/info/alternates &&
315                 git commit-graph verify --object-dir="$altdir/" &&
316                 test_commit extra &&
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
323         )
324 '
325
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
335 '
336
337 graph_git_behavior 'graph exists' merge/octopus commits/12
338
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 &&
344         (
345                 cd alt-split &&
346                 rm -f .git/objects/info/commit-graph &&
347                 echo "$(pwd)"/../.git/objects >.git/objects/info/alternates &&
348                 test_commit 18 &&
349                 git commit-graph write --reachable --split &&
350                 test_line_count = 1 $graphdir/commit-graph-chain
351         ) &&
352         test_cmp commit-graph .git/objects/info/commit-graph
353 '
354
355 test_done