]>
Commit | Line | Data |
---|---|---|
3fed15f5 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='blob conversion via gitattributes' | |
4 | ||
06d53148 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
3fed15f5 | 8 | . ./test-lib.sh |
7a132c62 | 9 | . "$TEST_DIRECTORY"/lib-terminal.sh |
3fed15f5 | 10 | |
95494c6f JS |
11 | PATH=$PWD:$PATH |
12 | TEST_ROOT="$(pwd)" | |
edcc8581 | 13 | |
cbb6707b | 14 | write_script <<\EOF "$TEST_ROOT/rot13.sh" |
7339eb08 JK |
15 | tr \ |
16 | 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \ | |
17 | 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM' | |
aa4ed402 | 18 | EOF |
edcc8581 LS |
19 | |
20 | generate_random_characters () { | |
21 | LEN=$1 | |
22 | NAME=$2 | |
c680668d | 23 | test-tool genrandom some-seed $LEN | |
edcc8581 LS |
24 | perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME" |
25 | } | |
26 | ||
edcc8581 | 27 | filter_git () { |
e1ec4721 | 28 | rm -f *.log && |
a0d8b60d | 29 | git "$@" |
edcc8581 LS |
30 | } |
31 | ||
32 | # Compare two files and ensure that `clean` and `smudge` respectively are | |
33 | # called at least once if specified in the `expect` file. The actual | |
34 | # invocation count is not relevant because their number can vary. | |
6eda9ac9 | 35 | # c.f. https://lore.kernel.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/ |
edcc8581 LS |
36 | test_cmp_count () { |
37 | expect=$1 | |
38 | actual=$2 | |
39 | for FILE in "$expect" "$actual" | |
40 | do | |
038212c4 | 41 | sort "$FILE" | uniq -c | |
58ec9cb3 | 42 | sed -e "s/^ *[0-9][0-9]*[ ]*IN: /x IN: /" >"$FILE.tmp" |
edcc8581 | 43 | done && |
58ec9cb3 LS |
44 | test_cmp "$expect.tmp" "$actual.tmp" && |
45 | rm "$expect.tmp" "$actual.tmp" | |
edcc8581 LS |
46 | } |
47 | ||
48 | # Compare two files but exclude all `clean` invocations because Git can | |
49 | # call `clean` zero or more times. | |
6eda9ac9 | 50 | # c.f. https://lore.kernel.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/ |
edcc8581 LS |
51 | test_cmp_exclude_clean () { |
52 | expect=$1 | |
53 | actual=$2 | |
54 | for FILE in "$expect" "$actual" | |
55 | do | |
58ec9cb3 | 56 | grep -v "IN: clean" "$FILE" >"$FILE.tmp" |
edcc8581 | 57 | done && |
58ec9cb3 LS |
58 | test_cmp "$expect.tmp" "$actual.tmp" && |
59 | rm "$expect.tmp" "$actual.tmp" | |
edcc8581 LS |
60 | } |
61 | ||
62 | # Check that the contents of two files are equal and that their rot13 version | |
63 | # is equal to the committed content. | |
64 | test_cmp_committed_rot13 () { | |
65 | test_cmp "$1" "$2" && | |
30030a36 | 66 | rot13.sh <"$1" >expected && |
edcc8581 LS |
67 | git cat-file blob :"$2" >actual && |
68 | test_cmp expected actual | |
69 | } | |
aa4ed402 | 70 | |
3fed15f5 | 71 | test_expect_success setup ' |
aa4ed402 JH |
72 | git config filter.rot13.smudge ./rot13.sh && |
73 | git config filter.rot13.clean ./rot13.sh && | |
74 | ||
3fed15f5 | 75 | { |
7abcbcb7 | 76 | echo "*.t filter=rot13" && |
3fed15f5 JH |
77 | echo "*.i ident" |
78 | } >.gitattributes && | |
79 | ||
80 | { | |
7abcbcb7 ES |
81 | echo a b c d e f g h i j k l m && |
82 | echo n o p q r s t u v w x y z && | |
af9b54bb | 83 | echo '\''$Id$'\'' |
3fed15f5 JH |
84 | } >test && |
85 | cat test >test.t && | |
86 | cat test >test.o && | |
87 | cat test >test.i && | |
88 | git add test test.t test.i && | |
89 | rm -f test test.t test.i && | |
edcc8581 LS |
90 | git checkout -- test test.t test.i && |
91 | ||
92 | echo "content-test2" >test2.o && | |
c6b0831c | 93 | echo "content-test3 - filename with special characters" >"test3 '\''sq'\'',\$x=.o" |
3fed15f5 JH |
94 | ' |
95 | ||
af9b54bb | 96 | script='s/^\$Id: \([0-9a-f]*\) \$/\1/p' |
3fed15f5 JH |
97 | |
98 | test_expect_success check ' | |
99 | ||
ed549703 LS |
100 | test_cmp test.o test && |
101 | test_cmp test.o test.t && | |
3fed15f5 JH |
102 | |
103 | # ident should be stripped in the repository | |
104 | git diff --raw --exit-code :test :test.i && | |
105 | id=$(git rev-parse --verify :test) && | |
106 | embedded=$(sed -ne "$script" test.i) && | |
a0ae35ae JS |
107 | test "z$id" = "z$embedded" && |
108 | ||
ed549703 | 109 | git cat-file blob :test.t >test.r && |
a0ae35ae | 110 | |
ed549703 LS |
111 | ./rot13.sh <test.o >test.t && |
112 | test_cmp test.r test.t | |
3fed15f5 JH |
113 | ' |
114 | ||
dfab71cb AP |
115 | # If an expanded ident ever gets into the repository, we want to make sure that |
116 | # it is collapsed before being expanded again on checkout | |
117 | test_expect_success expanded_in_repo ' | |
020b813f ES |
118 | cat >expanded-keywords.0 <<-\EOF && |
119 | File with expanded keywords | |
120 | $Id$ | |
121 | $Id:$ | |
122 | $Id: 0000000000000000000000000000000000000000 $ | |
123 | $Id: NoSpaceAtEnd$ | |
124 | $Id:NoSpaceAtFront $ | |
125 | $Id:NoSpaceAtEitherEnd$ | |
126 | $Id: NoTerminatingSymbol | |
127 | $Id: Foreign Commit With Spaces $ | |
128 | EOF | |
dfab71cb | 129 | |
6b6cab3f JH |
130 | { |
131 | cat expanded-keywords.0 && | |
132 | printf "\$Id: NoTerminatingSymbolAtEOF" | |
133 | } >expanded-keywords && | |
134 | cat expanded-keywords >expanded-keywords-crlf && | |
135 | git add expanded-keywords expanded-keywords-crlf && | |
dd555d8b RS |
136 | git commit -m "File with keywords expanded" && |
137 | id=$(git rev-parse --verify :expanded-keywords) && | |
138 | ||
020b813f ES |
139 | cat >expected-output.0 <<-EOF && |
140 | File with expanded keywords | |
141 | \$Id: $id \$ | |
142 | \$Id: $id \$ | |
143 | \$Id: $id \$ | |
144 | \$Id: $id \$ | |
145 | \$Id: $id \$ | |
146 | \$Id: $id \$ | |
147 | \$Id: NoTerminatingSymbol | |
148 | \$Id: Foreign Commit With Spaces \$ | |
149 | EOF | |
6b6cab3f JH |
150 | { |
151 | cat expected-output.0 && | |
dd555d8b | 152 | printf "\$Id: NoTerminatingSymbolAtEOF" |
6b6cab3f JH |
153 | } >expected-output && |
154 | { | |
155 | append_cr <expected-output.0 && | |
156 | printf "\$Id: NoTerminatingSymbolAtEOF" | |
157 | } >expected-output-crlf && | |
158 | { | |
7abcbcb7 | 159 | echo "expanded-keywords ident" && |
6b6cab3f JH |
160 | echo "expanded-keywords-crlf ident text eol=crlf" |
161 | } >>.gitattributes && | |
dfab71cb | 162 | |
6b6cab3f | 163 | rm -f expanded-keywords expanded-keywords-crlf && |
dfab71cb | 164 | |
dfab71cb | 165 | git checkout -- expanded-keywords && |
dcbaa0b3 | 166 | test_cmp expected-output expanded-keywords && |
6b6cab3f JH |
167 | |
168 | git checkout -- expanded-keywords-crlf && | |
dcbaa0b3 | 169 | test_cmp expected-output-crlf expanded-keywords-crlf |
dfab71cb AP |
170 | ' |
171 | ||
a2b665de PW |
172 | # The use of %f in a filter definition is expanded to the path to |
173 | # the filename being smudged or cleaned. It must be shell escaped. | |
174 | # First, set up some interesting file names and pet them in | |
175 | # .gitattributes. | |
176 | test_expect_success 'filter shell-escaped filenames' ' | |
177 | cat >argc.sh <<-EOF && | |
178 | #!$SHELL_PATH | |
4290f690 | 179 | cat >/dev/null |
a2b665de PW |
180 | echo argc: \$# "\$@" |
181 | EOF | |
182 | normal=name-no-magic && | |
183 | special="name with '\''sq'\'' and \$x" && | |
184 | echo some test text >"$normal" && | |
185 | echo some test text >"$special" && | |
186 | git add "$normal" "$special" && | |
187 | git commit -q -m "add files" && | |
188 | echo "name* filter=argc" >.gitattributes && | |
189 | ||
190 | # delete the files and check them out again, using a smudge filter | |
191 | # that will count the args and echo the command-line back to us | |
ed549703 | 192 | test_config filter.argc.smudge "sh ./argc.sh %f" && |
a2b665de PW |
193 | rm "$normal" "$special" && |
194 | git checkout -- "$normal" "$special" && | |
195 | ||
196 | # make sure argc.sh counted the right number of args | |
197 | echo "argc: 1 $normal" >expect && | |
198 | test_cmp expect "$normal" && | |
199 | echo "argc: 1 $special" >expect && | |
200 | test_cmp expect "$special" && | |
201 | ||
202 | # do the same thing, but with more args in the filter expression | |
ed549703 | 203 | test_config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" && |
a2b665de PW |
204 | rm "$normal" "$special" && |
205 | git checkout -- "$normal" "$special" && | |
206 | ||
207 | # make sure argc.sh counted the right number of args | |
208 | echo "argc: 2 $normal --my-extra-arg" >expect && | |
209 | test_cmp expect "$normal" && | |
210 | echo "argc: 2 $special --my-extra-arg" >expect && | |
211 | test_cmp expect "$special" && | |
212 | : | |
213 | ' | |
214 | ||
9035d75a | 215 | test_expect_success 'required filter should filter data' ' |
ed549703 LS |
216 | test_config filter.required.smudge ./rot13.sh && |
217 | test_config filter.required.clean ./rot13.sh && | |
218 | test_config filter.required.required true && | |
36daaaca JB |
219 | |
220 | echo "*.r filter=required" >.gitattributes && | |
221 | ||
9035d75a | 222 | cat test.o >test.r && |
36daaaca | 223 | git add test.r && |
9035d75a | 224 | |
36daaaca | 225 | rm -f test.r && |
9035d75a | 226 | git checkout -- test.r && |
ed549703 | 227 | test_cmp test.o test.r && |
9035d75a SP |
228 | |
229 | ./rot13.sh <test.o >expected && | |
230 | git cat-file blob :test.r >actual && | |
ed549703 | 231 | test_cmp expected actual |
36daaaca JB |
232 | ' |
233 | ||
234 | test_expect_success 'required filter smudge failure' ' | |
ed549703 LS |
235 | test_config filter.failsmudge.smudge false && |
236 | test_config filter.failsmudge.clean cat && | |
237 | test_config filter.failsmudge.required true && | |
36daaaca JB |
238 | |
239 | echo "*.fs filter=failsmudge" >.gitattributes && | |
240 | ||
241 | echo test >test.fs && | |
242 | git add test.fs && | |
243 | rm -f test.fs && | |
244 | test_must_fail git checkout -- test.fs | |
245 | ' | |
246 | ||
247 | test_expect_success 'required filter clean failure' ' | |
ed549703 LS |
248 | test_config filter.failclean.smudge cat && |
249 | test_config filter.failclean.clean false && | |
250 | test_config filter.failclean.required true && | |
36daaaca JB |
251 | |
252 | echo "*.fc filter=failclean" >.gitattributes && | |
253 | ||
254 | echo test >test.fc && | |
255 | test_must_fail git add test.fc | |
256 | ' | |
257 | ||
6fab35f7 MT |
258 | test_expect_success 'required filter with absent clean field' ' |
259 | test_config filter.absentclean.smudge cat && | |
260 | test_config filter.absentclean.required true && | |
261 | ||
262 | echo "*.ac filter=absentclean" >.gitattributes && | |
263 | ||
264 | echo test >test.ac && | |
265 | test_must_fail git add test.ac 2>stderr && | |
6789275d | 266 | test_grep "fatal: test.ac: clean filter .absentclean. failed" stderr |
6fab35f7 MT |
267 | ' |
268 | ||
269 | test_expect_success 'required filter with absent smudge field' ' | |
270 | test_config filter.absentsmudge.clean cat && | |
271 | test_config filter.absentsmudge.required true && | |
272 | ||
273 | echo "*.as filter=absentsmudge" >.gitattributes && | |
274 | ||
275 | echo test >test.as && | |
276 | git add test.as && | |
277 | rm -f test.as && | |
278 | test_must_fail git checkout -- test.as 2>stderr && | |
6789275d | 279 | test_grep "fatal: test.as: smudge filter absentsmudge failed" stderr |
6fab35f7 MT |
280 | ' |
281 | ||
9035d75a | 282 | test_expect_success 'filtering large input to small output should use little memory' ' |
ed549703 LS |
283 | test_config filter.devnull.clean "cat >/dev/null" && |
284 | test_config filter.devnull.required true && | |
db5875aa | 285 | for i in $(test_seq 1 30); do printf "%1048576d" 1 || return 1; done >30MB && |
9035d75a SP |
286 | echo "30MB filter=devnull" >.gitattributes && |
287 | GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB | |
288 | ' | |
289 | ||
0c4dd67a | 290 | test_expect_success 'filter that does not read is fine' ' |
c680668d | 291 | test-tool genrandom foo $((128 * 1024 + 1)) >big && |
0c4dd67a | 292 | echo "big filter=epipe" >.gitattributes && |
ed549703 | 293 | test_config filter.epipe.clean "echo xyzzy" && |
0c4dd67a JH |
294 | git add big && |
295 | git cat-file blob :big >actual && | |
296 | echo xyzzy >expect && | |
297 | test_cmp expect actual | |
298 | ' | |
299 | ||
0b6806b9 | 300 | test_expect_success EXPENSIVE 'filter large file' ' |
ed549703 LS |
301 | test_config filter.largefile.smudge cat && |
302 | test_config filter.largefile.clean cat && | |
db5875aa | 303 | for i in $(test_seq 1 2048); do printf "%1048576d" 1 || return 1; done >2GB && |
0b6806b9 SP |
304 | echo "2GB filter=largefile" >.gitattributes && |
305 | git add 2GB 2>err && | |
ed549703 | 306 | test_must_be_empty err && |
0b6806b9 SP |
307 | rm -f 2GB && |
308 | git checkout -- 2GB 2>err && | |
ed549703 | 309 | test_must_be_empty err |
0b6806b9 SP |
310 | ' |
311 | ||
f6a1e1e2 | 312 | test_expect_success "filter: clean empty file" ' |
ed549703 LS |
313 | test_config filter.in-repo-header.clean "echo cleaned && cat" && |
314 | test_config filter.in-repo-header.smudge "sed 1d" && | |
f6a1e1e2 JH |
315 | |
316 | echo "empty-in-worktree filter=in-repo-header" >>.gitattributes && | |
317 | >empty-in-worktree && | |
318 | ||
319 | echo cleaned >expected && | |
320 | git add empty-in-worktree && | |
321 | git show :empty-in-worktree >actual && | |
322 | test_cmp expected actual | |
323 | ' | |
324 | ||
325 | test_expect_success "filter: smudge empty file" ' | |
ed549703 LS |
326 | test_config filter.empty-in-repo.clean "cat >/dev/null" && |
327 | test_config filter.empty-in-repo.smudge "echo smudged && cat" && | |
f6a1e1e2 JH |
328 | |
329 | echo "empty-in-repo filter=empty-in-repo" >>.gitattributes && | |
330 | echo dead data walking >empty-in-repo && | |
331 | git add empty-in-repo && | |
332 | ||
333 | echo smudged >expected && | |
334 | git checkout-index --prefix=filtered- empty-in-repo && | |
335 | test_cmp expected filtered-empty-in-repo | |
336 | ' | |
337 | ||
1a8630dc LS |
338 | test_expect_success 'disable filter with empty override' ' |
339 | test_config_global filter.disable.smudge false && | |
340 | test_config_global filter.disable.clean false && | |
341 | test_config filter.disable.smudge false && | |
342 | test_config filter.disable.clean false && | |
343 | ||
344 | echo "*.disable filter=disable" >.gitattributes && | |
345 | ||
346 | echo test >test.disable && | |
347 | git -c filter.disable.clean= add test.disable 2>err && | |
348 | test_must_be_empty err && | |
349 | rm -f test.disable && | |
350 | git -c filter.disable.smudge= checkout -- test.disable 2>err && | |
351 | test_must_be_empty err | |
352 | ' | |
353 | ||
06dec439 JK |
354 | test_expect_success 'diff does not reuse worktree files that need cleaning' ' |
355 | test_config filter.counter.clean "echo . >>count; sed s/^/clean:/" && | |
356 | echo "file filter=counter" >.gitattributes && | |
357 | test_commit one file && | |
358 | test_commit two file && | |
359 | ||
360 | >count && | |
361 | git diff-tree -p HEAD && | |
362 | test_line_count = 0 count | |
363 | ' | |
364 | ||
4d1d843b MT |
365 | test_expect_success 'required process filter should filter data' ' |
366 | test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" && | |
edcc8581 LS |
367 | test_config_global filter.protocol.required true && |
368 | rm -rf repo && | |
369 | mkdir repo && | |
370 | ( | |
371 | cd repo && | |
372 | git init && | |
373 | ||
edcc8581 LS |
374 | echo "*.r filter=protocol" >.gitattributes && |
375 | git add . && | |
9c48b4fb | 376 | git commit -m "test commit 1" && |
edcc8581 LS |
377 | git branch empty-branch && |
378 | ||
379 | cp "$TEST_ROOT/test.o" test.r && | |
380 | cp "$TEST_ROOT/test2.o" test2.r && | |
381 | mkdir testsubdir && | |
c6b0831c | 382 | cp "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" && |
edcc8581 LS |
383 | >test4-empty.r && |
384 | ||
53b67a80 JS |
385 | S=$(test_file_size test.r) && |
386 | S2=$(test_file_size test2.r) && | |
387 | S3=$(test_file_size "testsubdir/test3 '\''sq'\'',\$x=.r") && | |
13e7ed6a | 388 | M=$(git hash-object test.r) && |
389 | M2=$(git hash-object test2.r) && | |
390 | M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") && | |
391 | EMPTY=$(git hash-object /dev/null) && | |
edcc8581 LS |
392 | |
393 | filter_git add . && | |
394 | cat >expected.log <<-EOF && | |
395 | START | |
396 | init handshake complete | |
397 | IN: clean test.r $S [OK] -- OUT: $S . [OK] | |
398 | IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK] | |
399 | IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK] | |
c6b0831c | 400 | IN: clean testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK] |
edcc8581 LS |
401 | STOP |
402 | EOF | |
e1ec4721 | 403 | test_cmp_count expected.log debug.log && |
edcc8581 | 404 | |
7eeda8b8 | 405 | git commit -m "test commit 2" && |
06d53148 JS |
406 | MAIN=$(git rev-parse --verify main) && |
407 | META="ref=refs/heads/main treeish=$MAIN" && | |
c6b0831c | 408 | rm -f test2.r "testsubdir/test3 '\''sq'\'',\$x=.r" && |
edcc8581 LS |
409 | |
410 | filter_git checkout --quiet --no-progress . && | |
411 | cat >expected.log <<-EOF && | |
412 | START | |
413 | init handshake complete | |
13e7ed6a | 414 | IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK] |
415 | IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r blob=$M3 $S3 [OK] -- OUT: $S3 . [OK] | |
edcc8581 LS |
416 | STOP |
417 | EOF | |
e1ec4721 | 418 | test_cmp_exclude_clean expected.log debug.log && |
edcc8581 | 419 | |
58166c2e TG |
420 | # Make sure that the file appears dirty, so checkout below has to |
421 | # run the configured filter. | |
422 | touch test.r && | |
edcc8581 LS |
423 | filter_git checkout --quiet --no-progress empty-branch && |
424 | cat >expected.log <<-EOF && | |
425 | START | |
426 | init handshake complete | |
427 | IN: clean test.r $S [OK] -- OUT: $S . [OK] | |
428 | STOP | |
429 | EOF | |
e1ec4721 | 430 | test_cmp_exclude_clean expected.log debug.log && |
edcc8581 | 431 | |
06d53148 | 432 | filter_git checkout --quiet --no-progress main && |
edcc8581 LS |
433 | cat >expected.log <<-EOF && |
434 | START | |
435 | init handshake complete | |
13e7ed6a | 436 | IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK] |
437 | IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK] | |
438 | IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK] | |
439 | IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK] | |
edcc8581 LS |
440 | STOP |
441 | EOF | |
e1ec4721 | 442 | test_cmp_exclude_clean expected.log debug.log && |
edcc8581 LS |
443 | |
444 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r && | |
445 | test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r && | |
c6b0831c | 446 | test_cmp_committed_rot13 "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" |
edcc8581 LS |
447 | ) |
448 | ' | |
449 | ||
4d1d843b MT |
450 | test_expect_success 'required process filter should filter data for various subcommands' ' |
451 | test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" && | |
3f267856 | 452 | test_config_global filter.protocol.required true && |
453 | ( | |
454 | cd repo && | |
455 | ||
53b67a80 JS |
456 | S=$(test_file_size test.r) && |
457 | S2=$(test_file_size test2.r) && | |
458 | S3=$(test_file_size "testsubdir/test3 '\''sq'\'',\$x=.r") && | |
3f267856 | 459 | M=$(git hash-object test.r) && |
460 | M2=$(git hash-object test2.r) && | |
461 | M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") && | |
462 | EMPTY=$(git hash-object /dev/null) && | |
463 | ||
06d53148 | 464 | MAIN=$(git rev-parse --verify main) && |
3f267856 | 465 | |
466 | cp "$TEST_ROOT/test.o" test5.r && | |
467 | git add test5.r && | |
468 | git commit -m "test commit 3" && | |
469 | git checkout empty-branch && | |
06d53148 JS |
470 | filter_git rebase --onto empty-branch main^^ main && |
471 | MAIN2=$(git rev-parse --verify main) && | |
472 | META="ref=refs/heads/main treeish=$MAIN2" && | |
3f267856 | 473 | cat >expected.log <<-EOF && |
474 | START | |
475 | init handshake complete | |
476 | IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK] | |
477 | IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK] | |
478 | IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK] | |
479 | IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK] | |
480 | IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK] | |
481 | STOP | |
482 | EOF | |
4cf76f6b | 483 | test_cmp_exclude_clean expected.log debug.log && |
484 | ||
485 | git reset --hard empty-branch && | |
06d53148 JS |
486 | filter_git reset --hard $MAIN && |
487 | META="treeish=$MAIN" && | |
4cf76f6b | 488 | cat >expected.log <<-EOF && |
489 | START | |
490 | init handshake complete | |
491 | IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK] | |
492 | IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK] | |
493 | IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK] | |
494 | IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK] | |
495 | STOP | |
496 | EOF | |
497 | test_cmp_exclude_clean expected.log debug.log && | |
498 | ||
06d53148 | 499 | git branch old-main $MAIN && |
4cf76f6b | 500 | git reset --hard empty-branch && |
06d53148 JS |
501 | filter_git reset --hard old-main && |
502 | META="ref=refs/heads/old-main treeish=$MAIN" && | |
4cf76f6b | 503 | cat >expected.log <<-EOF && |
504 | START | |
505 | init handshake complete | |
506 | IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK] | |
507 | IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK] | |
508 | IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK] | |
509 | IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK] | |
510 | STOP | |
511 | EOF | |
0c0f8a7f | 512 | test_cmp_exclude_clean expected.log debug.log && |
513 | ||
514 | git checkout -b merge empty-branch && | |
06d53148 JS |
515 | git branch -f main $MAIN2 && |
516 | filter_git merge main && | |
517 | META="treeish=$MAIN2" && | |
0c0f8a7f | 518 | cat >expected.log <<-EOF && |
519 | START | |
520 | init handshake complete | |
521 | IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK] | |
522 | IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK] | |
523 | IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK] | |
524 | IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK] | |
525 | IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK] | |
526 | STOP | |
527 | EOF | |
528 | test_cmp_exclude_clean expected.log debug.log && | |
529 | ||
06d53148 JS |
530 | filter_git archive main >/dev/null && |
531 | META="ref=refs/heads/main treeish=$MAIN2" && | |
0c0f8a7f | 532 | cat >expected.log <<-EOF && |
533 | START | |
534 | init handshake complete | |
535 | IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK] | |
536 | IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK] | |
537 | IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK] | |
538 | IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK] | |
539 | IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK] | |
540 | STOP | |
541 | EOF | |
542 | test_cmp_exclude_clean expected.log debug.log && | |
543 | ||
06d53148 | 544 | TREE="$(git rev-parse $MAIN2^{tree})" && |
0c0f8a7f | 545 | filter_git archive $TREE >/dev/null && |
546 | META="treeish=$TREE" && | |
547 | cat >expected.log <<-EOF && | |
548 | START | |
549 | init handshake complete | |
550 | IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK] | |
551 | IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK] | |
552 | IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK] | |
553 | IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK] | |
554 | IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK] | |
555 | STOP | |
556 | EOF | |
3f267856 | 557 | test_cmp_exclude_clean expected.log debug.log |
558 | ) | |
559 | ' | |
560 | ||
4d1d843b | 561 | test_expect_success 'required process filter takes precedence' ' |
edcc8581 | 562 | test_config_global filter.protocol.clean false && |
4d1d843b | 563 | test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean" && |
edcc8581 LS |
564 | test_config_global filter.protocol.required true && |
565 | rm -rf repo && | |
566 | mkdir repo && | |
567 | ( | |
568 | cd repo && | |
569 | git init && | |
570 | ||
571 | echo "*.r filter=protocol" >.gitattributes && | |
572 | cp "$TEST_ROOT/test.o" test.r && | |
53b67a80 | 573 | S=$(test_file_size test.r) && |
edcc8581 LS |
574 | |
575 | # Check that the process filter is invoked here | |
576 | filter_git add . && | |
577 | cat >expected.log <<-EOF && | |
578 | START | |
579 | init handshake complete | |
580 | IN: clean test.r $S [OK] -- OUT: $S . [OK] | |
581 | STOP | |
582 | EOF | |
e1ec4721 | 583 | test_cmp_count expected.log debug.log |
edcc8581 LS |
584 | ) |
585 | ' | |
586 | ||
4d1d843b MT |
587 | test_expect_success 'required process filter should be used only for "clean" operation only' ' |
588 | test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean" && | |
edcc8581 LS |
589 | rm -rf repo && |
590 | mkdir repo && | |
591 | ( | |
592 | cd repo && | |
593 | git init && | |
594 | ||
595 | echo "*.r filter=protocol" >.gitattributes && | |
596 | cp "$TEST_ROOT/test.o" test.r && | |
53b67a80 | 597 | S=$(test_file_size test.r) && |
edcc8581 LS |
598 | |
599 | filter_git add . && | |
600 | cat >expected.log <<-EOF && | |
601 | START | |
602 | init handshake complete | |
603 | IN: clean test.r $S [OK] -- OUT: $S . [OK] | |
604 | STOP | |
605 | EOF | |
e1ec4721 | 606 | test_cmp_count expected.log debug.log && |
edcc8581 LS |
607 | |
608 | rm test.r && | |
609 | ||
610 | filter_git checkout --quiet --no-progress . && | |
611 | # If the filter would be used for "smudge", too, we would see | |
612 | # "IN: smudge test.r 57 [OK] -- OUT: 57 . [OK]" here | |
613 | cat >expected.log <<-EOF && | |
614 | START | |
615 | init handshake complete | |
616 | STOP | |
617 | EOF | |
e1ec4721 | 618 | test_cmp_exclude_clean expected.log debug.log |
edcc8581 LS |
619 | ) |
620 | ' | |
621 | ||
4d1d843b MT |
622 | test_expect_success 'required process filter should process multiple packets' ' |
623 | test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" && | |
edcc8581 LS |
624 | test_config_global filter.protocol.required true && |
625 | ||
626 | rm -rf repo && | |
627 | mkdir repo && | |
628 | ( | |
629 | cd repo && | |
630 | git init && | |
631 | ||
632 | # Generate data requiring 1, 2, 3 packets | |
633 | S=65516 && # PKTLINE_DATA_MAXLEN -> Maximal size of a packet | |
634 | generate_random_characters $(($S )) 1pkt_1__.file && | |
635 | generate_random_characters $(($S +1)) 2pkt_1+1.file && | |
636 | generate_random_characters $(($S*2-1)) 2pkt_2-1.file && | |
637 | generate_random_characters $(($S*2 )) 2pkt_2__.file && | |
638 | generate_random_characters $(($S*2+1)) 3pkt_2+1.file && | |
639 | ||
640 | for FILE in "$TEST_ROOT"/*.file | |
641 | do | |
642 | cp "$FILE" . && | |
db5875aa | 643 | rot13.sh <"$FILE" >"$FILE.rot13" || return 1 |
edcc8581 LS |
644 | done && |
645 | ||
646 | echo "*.file filter=protocol" >.gitattributes && | |
647 | filter_git add *.file .gitattributes && | |
648 | cat >expected.log <<-EOF && | |
649 | START | |
650 | init handshake complete | |
651 | IN: clean 1pkt_1__.file $(($S )) [OK] -- OUT: $(($S )) . [OK] | |
652 | IN: clean 2pkt_1+1.file $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK] | |
653 | IN: clean 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK] | |
654 | IN: clean 2pkt_2__.file $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK] | |
655 | IN: clean 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK] | |
656 | STOP | |
657 | EOF | |
e1ec4721 | 658 | test_cmp_count expected.log debug.log && |
edcc8581 | 659 | |
13e7ed6a | 660 | M1="blob=$(git hash-object 1pkt_1__.file)" && |
661 | M2="blob=$(git hash-object 2pkt_1+1.file)" && | |
662 | M3="blob=$(git hash-object 2pkt_2-1.file)" && | |
663 | M4="blob=$(git hash-object 2pkt_2__.file)" && | |
664 | M5="blob=$(git hash-object 3pkt_2+1.file)" && | |
665 | rm -f *.file debug.log && | |
edcc8581 LS |
666 | |
667 | filter_git checkout --quiet --no-progress -- *.file && | |
668 | cat >expected.log <<-EOF && | |
669 | START | |
670 | init handshake complete | |
13e7ed6a | 671 | IN: smudge 1pkt_1__.file $M1 $(($S )) [OK] -- OUT: $(($S )) . [OK] |
672 | IN: smudge 2pkt_1+1.file $M2 $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK] | |
673 | IN: smudge 2pkt_2-1.file $M3 $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK] | |
674 | IN: smudge 2pkt_2__.file $M4 $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK] | |
675 | IN: smudge 3pkt_2+1.file $M5 $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK] | |
edcc8581 LS |
676 | STOP |
677 | EOF | |
e1ec4721 | 678 | test_cmp_exclude_clean expected.log debug.log && |
edcc8581 LS |
679 | |
680 | for FILE in *.file | |
681 | do | |
db5875aa | 682 | test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE || return 1 |
edcc8581 LS |
683 | done |
684 | ) | |
685 | ' | |
686 | ||
4d1d843b MT |
687 | test_expect_success 'required process filter with clean error should fail' ' |
688 | test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" && | |
edcc8581 LS |
689 | test_config_global filter.protocol.required true && |
690 | rm -rf repo && | |
691 | mkdir repo && | |
692 | ( | |
693 | cd repo && | |
694 | git init && | |
695 | ||
696 | echo "*.r filter=protocol" >.gitattributes && | |
697 | ||
698 | cp "$TEST_ROOT/test.o" test.r && | |
699 | echo "this is going to fail" >clean-write-fail.r && | |
700 | echo "content-test3-subdir" >test3.r && | |
701 | ||
702 | test_must_fail git add . | |
703 | ) | |
704 | ' | |
705 | ||
4d1d843b MT |
706 | test_expect_success 'process filter should restart after unexpected write failure' ' |
707 | test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" && | |
edcc8581 LS |
708 | rm -rf repo && |
709 | mkdir repo && | |
710 | ( | |
711 | cd repo && | |
712 | git init && | |
713 | ||
714 | echo "*.r filter=protocol" >.gitattributes && | |
715 | ||
716 | cp "$TEST_ROOT/test.o" test.r && | |
717 | cp "$TEST_ROOT/test2.o" test2.r && | |
718 | echo "this is going to fail" >smudge-write-fail.o && | |
719 | cp smudge-write-fail.o smudge-write-fail.r && | |
720 | ||
53b67a80 JS |
721 | S=$(test_file_size test.r) && |
722 | S2=$(test_file_size test2.r) && | |
723 | SF=$(test_file_size smudge-write-fail.r) && | |
13e7ed6a | 724 | M=$(git hash-object test.r) && |
725 | M2=$(git hash-object test2.r) && | |
726 | MF=$(git hash-object smudge-write-fail.r) && | |
727 | rm -f debug.log && | |
edcc8581 LS |
728 | |
729 | git add . && | |
730 | rm -f *.r && | |
731 | ||
e1ec4721 | 732 | rm -f debug.log && |
edcc8581 LS |
733 | git checkout --quiet --no-progress . 2>git-stderr.log && |
734 | ||
bed89477 | 735 | grep "smudge write error" git-stderr.log && |
6789275d | 736 | test_grep "error: external filter" git-stderr.log && |
edcc8581 LS |
737 | |
738 | cat >expected.log <<-EOF && | |
739 | START | |
740 | init handshake complete | |
13e7ed6a | 741 | IN: smudge smudge-write-fail.r blob=$MF $SF [OK] -- [WRITE FAIL] |
edcc8581 LS |
742 | START |
743 | init handshake complete | |
13e7ed6a | 744 | IN: smudge test.r blob=$M $S [OK] -- OUT: $S . [OK] |
745 | IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK] | |
edcc8581 LS |
746 | STOP |
747 | EOF | |
e1ec4721 | 748 | test_cmp_exclude_clean expected.log debug.log && |
edcc8581 LS |
749 | |
750 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r && | |
751 | test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r && | |
752 | ||
753 | # Smudge failed | |
754 | ! test_cmp smudge-write-fail.o smudge-write-fail.r && | |
30030a36 | 755 | rot13.sh <smudge-write-fail.o >expected && |
edcc8581 LS |
756 | git cat-file blob :smudge-write-fail.r >actual && |
757 | test_cmp expected actual | |
758 | ) | |
759 | ' | |
760 | ||
4d1d843b MT |
761 | test_expect_success 'process filter should not be restarted if it signals an error' ' |
762 | test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" && | |
edcc8581 LS |
763 | rm -rf repo && |
764 | mkdir repo && | |
765 | ( | |
766 | cd repo && | |
767 | git init && | |
768 | ||
769 | echo "*.r filter=protocol" >.gitattributes && | |
770 | ||
771 | cp "$TEST_ROOT/test.o" test.r && | |
772 | cp "$TEST_ROOT/test2.o" test2.r && | |
773 | echo "this will cause an error" >error.o && | |
774 | cp error.o error.r && | |
775 | ||
53b67a80 JS |
776 | S=$(test_file_size test.r) && |
777 | S2=$(test_file_size test2.r) && | |
778 | SE=$(test_file_size error.r) && | |
13e7ed6a | 779 | M=$(git hash-object test.r) && |
780 | M2=$(git hash-object test2.r) && | |
781 | ME=$(git hash-object error.r) && | |
782 | rm -f debug.log && | |
edcc8581 LS |
783 | |
784 | git add . && | |
785 | rm -f *.r && | |
786 | ||
787 | filter_git checkout --quiet --no-progress . && | |
788 | cat >expected.log <<-EOF && | |
789 | START | |
790 | init handshake complete | |
13e7ed6a | 791 | IN: smudge error.r blob=$ME $SE [OK] -- [ERROR] |
792 | IN: smudge test.r blob=$M $S [OK] -- OUT: $S . [OK] | |
793 | IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK] | |
edcc8581 LS |
794 | STOP |
795 | EOF | |
e1ec4721 | 796 | test_cmp_exclude_clean expected.log debug.log && |
edcc8581 LS |
797 | |
798 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r && | |
799 | test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r && | |
800 | test_cmp error.o error.r | |
801 | ) | |
802 | ' | |
803 | ||
4d1d843b MT |
804 | test_expect_success 'process filter abort stops processing of all further files' ' |
805 | test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" && | |
edcc8581 LS |
806 | rm -rf repo && |
807 | mkdir repo && | |
808 | ( | |
809 | cd repo && | |
810 | git init && | |
811 | ||
812 | echo "*.r filter=protocol" >.gitattributes && | |
813 | ||
814 | cp "$TEST_ROOT/test.o" test.r && | |
815 | cp "$TEST_ROOT/test2.o" test2.r && | |
816 | echo "error this blob and all future blobs" >abort.o && | |
817 | cp abort.o abort.r && | |
818 | ||
13e7ed6a | 819 | M="blob=$(git hash-object abort.r)" && |
820 | rm -f debug.log && | |
53b67a80 | 821 | SA=$(test_file_size abort.r) && |
edcc8581 LS |
822 | |
823 | git add . && | |
824 | rm -f *.r && | |
825 | ||
13e7ed6a | 826 | |
edcc8581 LS |
827 | # Note: This test assumes that Git filters files in alphabetical |
828 | # order ("abort.r" before "test.r"). | |
829 | filter_git checkout --quiet --no-progress . && | |
830 | cat >expected.log <<-EOF && | |
831 | START | |
832 | init handshake complete | |
13e7ed6a | 833 | IN: smudge abort.r $M $SA [OK] -- [ABORT] |
edcc8581 LS |
834 | STOP |
835 | EOF | |
e1ec4721 | 836 | test_cmp_exclude_clean expected.log debug.log && |
edcc8581 LS |
837 | |
838 | test_cmp "$TEST_ROOT/test.o" test.r && | |
839 | test_cmp "$TEST_ROOT/test2.o" test2.r && | |
840 | test_cmp abort.o abort.r | |
841 | ) | |
842 | ' | |
843 | ||
844 | test_expect_success PERL 'invalid process filter must fail (and not hang!)' ' | |
845 | test_config_global filter.protocol.process cat && | |
846 | test_config_global filter.protocol.required true && | |
847 | rm -rf repo && | |
848 | mkdir repo && | |
849 | ( | |
850 | cd repo && | |
851 | git init && | |
852 | ||
853 | echo "*.r filter=protocol" >.gitattributes && | |
854 | ||
855 | cp "$TEST_ROOT/test.o" test.r && | |
856 | test_must_fail git add . 2>git-stderr.log && | |
fa64a2fd | 857 | grep "expected git-filter-server" git-stderr.log |
edcc8581 LS |
858 | ) |
859 | ' | |
860 | ||
4d1d843b MT |
861 | test_expect_success 'delayed checkout in process filter' ' |
862 | test_config_global filter.a.process "test-tool rot13-filter --log=a.log clean smudge delay" && | |
2841e8f8 | 863 | test_config_global filter.a.required true && |
4d1d843b | 864 | test_config_global filter.b.process "test-tool rot13-filter --log=b.log clean smudge delay" && |
2841e8f8 LS |
865 | test_config_global filter.b.required true && |
866 | ||
867 | rm -rf repo && | |
868 | mkdir repo && | |
869 | ( | |
870 | cd repo && | |
871 | git init && | |
872 | echo "*.a filter=a" >.gitattributes && | |
873 | echo "*.b filter=b" >>.gitattributes && | |
874 | cp "$TEST_ROOT/test.o" test.a && | |
875 | cp "$TEST_ROOT/test.o" test-delay10.a && | |
876 | cp "$TEST_ROOT/test.o" test-delay11.a && | |
877 | cp "$TEST_ROOT/test.o" test-delay20.a && | |
878 | cp "$TEST_ROOT/test.o" test-delay10.b && | |
879 | git add . && | |
880 | git commit -m "test commit" | |
881 | ) && | |
882 | ||
53b67a80 | 883 | S=$(test_file_size "$TEST_ROOT/test.o") && |
06d53148 JS |
884 | PM="ref=refs/heads/main treeish=$(git -C repo rev-parse --verify main) " && |
885 | M="${PM}blob=$(git -C repo rev-parse --verify main:test.a)" && | |
2841e8f8 LS |
886 | cat >a.exp <<-EOF && |
887 | START | |
888 | init handshake complete | |
13e7ed6a | 889 | IN: smudge test.a $M $S [OK] -- OUT: $S . [OK] |
890 | IN: smudge test-delay10.a $M $S [OK] -- [DELAYED] | |
891 | IN: smudge test-delay11.a $M $S [OK] -- [DELAYED] | |
892 | IN: smudge test-delay20.a $M $S [OK] -- [DELAYED] | |
2841e8f8 | 893 | IN: list_available_blobs test-delay10.a test-delay11.a [OK] |
13e7ed6a | 894 | IN: smudge test-delay10.a $M 0 [OK] -- OUT: $S . [OK] |
895 | IN: smudge test-delay11.a $M 0 [OK] -- OUT: $S . [OK] | |
2841e8f8 | 896 | IN: list_available_blobs test-delay20.a [OK] |
13e7ed6a | 897 | IN: smudge test-delay20.a $M 0 [OK] -- OUT: $S . [OK] |
2841e8f8 LS |
898 | IN: list_available_blobs [OK] |
899 | STOP | |
900 | EOF | |
901 | cat >b.exp <<-EOF && | |
902 | START | |
903 | init handshake complete | |
13e7ed6a | 904 | IN: smudge test-delay10.b $M $S [OK] -- [DELAYED] |
2841e8f8 | 905 | IN: list_available_blobs test-delay10.b [OK] |
13e7ed6a | 906 | IN: smudge test-delay10.b $M 0 [OK] -- OUT: $S . [OK] |
2841e8f8 LS |
907 | IN: list_available_blobs [OK] |
908 | STOP | |
909 | EOF | |
910 | ||
911 | rm -rf repo-cloned && | |
912 | filter_git clone repo repo-cloned && | |
913 | test_cmp_count a.exp repo-cloned/a.log && | |
914 | test_cmp_count b.exp repo-cloned/b.log && | |
915 | ||
916 | ( | |
917 | cd repo-cloned && | |
918 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a && | |
919 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a && | |
920 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a && | |
921 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a && | |
922 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b && | |
923 | ||
924 | rm *.a *.b && | |
925 | filter_git checkout . && | |
dfc8cdc6 | 926 | # We are not checking out a ref here, so filter out ref metadata. |
927 | sed -e "s!$PM!!" ../a.exp >a.exp.filtered && | |
928 | sed -e "s!$PM!!" ../b.exp >b.exp.filtered && | |
929 | test_cmp_count a.exp.filtered a.log && | |
930 | test_cmp_count b.exp.filtered b.log && | |
2841e8f8 LS |
931 | |
932 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a && | |
933 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a && | |
934 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a && | |
935 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a && | |
936 | test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b | |
937 | ) | |
938 | ' | |
939 | ||
4d1d843b MT |
940 | test_expect_success 'missing file in delayed checkout' ' |
941 | test_config_global filter.bug.process "test-tool rot13-filter --log=bug.log clean smudge delay" && | |
2841e8f8 LS |
942 | test_config_global filter.bug.required true && |
943 | ||
944 | rm -rf repo && | |
945 | mkdir repo && | |
946 | ( | |
947 | cd repo && | |
948 | git init && | |
949 | echo "*.a filter=bug" >.gitattributes && | |
75651fd7 | 950 | cp "$TEST_ROOT/test.o" missing-delay.a && |
2841e8f8 LS |
951 | git add . && |
952 | git commit -m "test commit" | |
953 | ) && | |
954 | ||
955 | rm -rf repo-cloned && | |
956 | test_must_fail git clone repo repo-cloned 2>git-stderr.log && | |
2841e8f8 LS |
957 | grep "error: .missing-delay\.a. was not filtered properly" git-stderr.log |
958 | ' | |
959 | ||
4d1d843b MT |
960 | test_expect_success 'invalid file in delayed checkout' ' |
961 | test_config_global filter.bug.process "test-tool rot13-filter --log=bug.log clean smudge delay" && | |
2841e8f8 LS |
962 | test_config_global filter.bug.required true && |
963 | ||
964 | rm -rf repo && | |
965 | mkdir repo && | |
966 | ( | |
967 | cd repo && | |
968 | git init && | |
969 | echo "*.a filter=bug" >.gitattributes && | |
970 | cp "$TEST_ROOT/test.o" invalid-delay.a && | |
75651fd7 | 971 | cp "$TEST_ROOT/test.o" unfiltered && |
2841e8f8 LS |
972 | git add . && |
973 | git commit -m "test commit" | |
974 | ) && | |
975 | ||
976 | rm -rf repo-cloned && | |
977 | test_must_fail git clone repo repo-cloned 2>git-stderr.log && | |
978 | grep "error: external filter .* signaled that .unfiltered. is now available although it has not been delayed earlier" git-stderr.log | |
979 | ' | |
980 | ||
684dd4c2 MT |
981 | for mode in 'case' 'utf-8' |
982 | do | |
983 | case "$mode" in | |
984 | case) dir='A' symlink='a' mode_prereq='CASE_INSENSITIVE_FS' ;; | |
985 | utf-8) | |
986 | dir=$(printf "\141\314\210") symlink=$(printf "\303\244") | |
987 | mode_prereq='UTF8_NFD_TO_NFC' ;; | |
988 | esac | |
989 | ||
4d1d843b | 990 | test_expect_success SYMLINKS,$mode_prereq \ |
684dd4c2 MT |
991 | "delayed checkout with $mode-collision don't write to the wrong place" ' |
992 | test_config_global filter.delay.process \ | |
4d1d843b | 993 | "test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay" && |
684dd4c2 MT |
994 | test_config_global filter.delay.required true && |
995 | ||
996 | git init $mode-collision && | |
997 | ( | |
998 | cd $mode-collision && | |
999 | mkdir target-dir && | |
1000 | ||
1001 | empty_oid=$(printf "" | git hash-object -w --stdin) && | |
1002 | symlink_oid=$(printf "%s" "$PWD/target-dir" | git hash-object -w --stdin) && | |
1003 | attr_oid=$(echo "$dir/z filter=delay" | git hash-object -w --stdin) && | |
1004 | ||
1005 | cat >objs <<-EOF && | |
1006 | 100644 blob $empty_oid $dir/x | |
1007 | 100644 blob $empty_oid $dir/y | |
1008 | 100644 blob $empty_oid $dir/z | |
1009 | 120000 blob $symlink_oid $symlink | |
1010 | 100644 blob $attr_oid .gitattributes | |
1011 | EOF | |
1012 | ||
1013 | git update-index --index-info <objs && | |
1014 | git commit -m "test commit" | |
1015 | ) && | |
1016 | ||
1017 | git clone $mode-collision $mode-collision-cloned && | |
1018 | # Make sure z was really delayed | |
1019 | grep "IN: smudge $dir/z .* \\[DELAYED\\]" $mode-collision-cloned/delayed.log && | |
1020 | ||
1021 | # Should not create $dir/z at $symlink/z | |
1022 | test_path_is_missing $mode-collision/target-dir/z | |
1023 | ' | |
1024 | done | |
1025 | ||
4d1d843b | 1026 | test_expect_success SYMLINKS,CASE_INSENSITIVE_FS \ |
0d58fef5 JS |
1027 | "delayed checkout with submodule collision don't write to the wrong place" ' |
1028 | git init collision-with-submodule && | |
1029 | ( | |
1030 | cd collision-with-submodule && | |
4d1d843b | 1031 | git config filter.delay.process "test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay" && |
0d58fef5 JS |
1032 | git config filter.delay.required true && |
1033 | ||
1034 | # We need Git to treat the submodule "a" and the | |
1035 | # leading dir "A" as different paths in the index. | |
1036 | git config --local core.ignoreCase false && | |
1037 | ||
1038 | empty_oid=$(printf "" | git hash-object -w --stdin) && | |
1039 | attr_oid=$(echo "A/B/y filter=delay" | git hash-object -w --stdin) && | |
1040 | cat >objs <<-EOF && | |
1041 | 100644 blob $empty_oid A/B/x | |
1042 | 100644 blob $empty_oid A/B/y | |
1043 | 100644 blob $attr_oid .gitattributes | |
1044 | EOF | |
1045 | git update-index --index-info <objs && | |
1046 | ||
1047 | git init a && | |
1048 | mkdir target-dir && | |
1049 | symlink_oid=$(printf "%s" "$PWD/target-dir" | git -C a hash-object -w --stdin) && | |
1050 | echo "120000 blob $symlink_oid b" >objs && | |
1051 | git -C a update-index --index-info <objs && | |
1052 | git -C a commit -m sub && | |
1053 | git submodule add ./a && | |
1054 | git commit -m super && | |
1055 | ||
1056 | git checkout --recurse-submodules . && | |
1057 | grep "IN: smudge A/B/y .* \\[DELAYED\\]" delayed.log && | |
1058 | test_path_is_missing target-dir/y | |
1059 | ) | |
1060 | ' | |
1061 | ||
4d1d843b | 1062 | test_expect_success 'setup for progress tests' ' |
7a132c62 MT |
1063 | git init progress && |
1064 | ( | |
1065 | cd progress && | |
4d1d843b | 1066 | git config filter.delay.process "test-tool rot13-filter --log=delay-progress.log clean smudge delay" && |
7a132c62 MT |
1067 | git config filter.delay.required true && |
1068 | ||
1069 | echo "*.a filter=delay" >.gitattributes && | |
1070 | touch test-delay10.a && | |
1071 | git add . && | |
1072 | git commit -m files | |
1073 | ) | |
1074 | ' | |
1075 | ||
1076 | test_delayed_checkout_progress () { | |
1077 | if test "$1" = "!" | |
1078 | then | |
1079 | local expect_progress=N && | |
1080 | shift | |
1081 | else | |
1082 | local expect_progress= | |
1083 | fi && | |
1084 | ||
1085 | if test $# -lt 1 | |
1086 | then | |
1087 | BUG "no command given to test_delayed_checkout_progress" | |
1088 | fi && | |
1089 | ||
1090 | ( | |
1091 | cd progress && | |
1092 | GIT_PROGRESS_DELAY=0 && | |
1093 | export GIT_PROGRESS_DELAY && | |
1094 | rm -f *.a delay-progress.log && | |
1095 | ||
1096 | "$@" 2>err && | |
1097 | grep "IN: smudge test-delay10.a .* \\[DELAYED\\]" delay-progress.log && | |
1098 | if test "$expect_progress" = N | |
1099 | then | |
1100 | ! grep "Filtering content" err | |
1101 | else | |
1102 | grep "Filtering content" err | |
1103 | fi | |
1104 | ) | |
1105 | } | |
1106 | ||
1107 | for mode in pathspec branch | |
1108 | do | |
1109 | case "$mode" in | |
1110 | pathspec) opt='.' ;; | |
1111 | branch) opt='-f HEAD' ;; | |
1112 | esac | |
1113 | ||
1114 | test_expect_success PERL,TTY "delayed checkout shows progress by default on tty ($mode checkout)" ' | |
1115 | test_delayed_checkout_progress test_terminal git checkout $opt | |
1116 | ' | |
1117 | ||
1118 | test_expect_success PERL "delayed checkout ommits progress on non-tty ($mode checkout)" ' | |
1119 | test_delayed_checkout_progress ! git checkout $opt | |
1120 | ' | |
1121 | ||
1122 | test_expect_success PERL,TTY "delayed checkout ommits progress with --quiet ($mode checkout)" ' | |
1123 | test_delayed_checkout_progress ! test_terminal git checkout --quiet $opt | |
1124 | ' | |
1125 | ||
1126 | test_expect_success PERL,TTY "delayed checkout honors --[no]-progress ($mode checkout)" ' | |
1127 | test_delayed_checkout_progress ! test_terminal git checkout --no-progress $opt && | |
1128 | test_delayed_checkout_progress test_terminal git checkout --quiet --progress $opt | |
1129 | ' | |
1130 | done | |
1131 | ||
4d1d843b | 1132 | test_expect_success 'delayed checkout correctly reports the number of updated entries' ' |
ed602c3f MT |
1133 | rm -rf repo && |
1134 | git init repo && | |
1135 | ( | |
1136 | cd repo && | |
4d1d843b | 1137 | git config filter.delay.process "test-tool rot13-filter --log=delayed.log clean smudge delay" && |
ed602c3f MT |
1138 | git config filter.delay.required true && |
1139 | ||
1140 | echo "*.a filter=delay" >.gitattributes && | |
1141 | echo a >test-delay10.a && | |
1142 | echo a >test-delay11.a && | |
1143 | git add . && | |
1144 | git commit -m files && | |
1145 | ||
1146 | rm *.a && | |
1147 | git checkout . 2>err && | |
1148 | grep "IN: smudge test-delay10.a .* \\[DELAYED\\]" delayed.log && | |
1149 | grep "IN: smudge test-delay11.a .* \\[DELAYED\\]" delayed.log && | |
1150 | grep "Updated 2 paths from the index" err | |
1151 | ) | |
1152 | ' | |
1153 | ||
3fed15f5 | 1154 | test_done |