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