convert: modernize tests
[git/git-svn.git] / t / t0021-conversion.sh
blobdc509381c9a590e6b92cac116567c0df7ca2dc4f
1 #!/bin/sh
3 test_description='blob conversion via gitattributes'
5 . ./test-lib.sh
7 cat <<EOF >rot13.sh
8 #!$SHELL_PATH
9 tr \
10 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
11 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
12 EOF
13 chmod +x rot13.sh
15 test_expect_success setup '
16 git config filter.rot13.smudge ./rot13.sh &&
17 git config filter.rot13.clean ./rot13.sh &&
20 echo "*.t filter=rot13"
21 echo "*.i ident"
22 } >.gitattributes &&
25 echo a b c d e f g h i j k l m
26 echo n o p q r s t u v w x y z
27 echo '\''$Id$'\''
28 } >test &&
29 cat test >test.t &&
30 cat test >test.o &&
31 cat test >test.i &&
32 git add test test.t test.i &&
33 rm -f test test.t test.i &&
34 git checkout -- test test.t test.i
37 script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
39 test_expect_success check '
41 test_cmp test.o test &&
42 test_cmp test.o test.t &&
44 # ident should be stripped in the repository
45 git diff --raw --exit-code :test :test.i &&
46 id=$(git rev-parse --verify :test) &&
47 embedded=$(sed -ne "$script" test.i) &&
48 test "z$id" = "z$embedded" &&
50 git cat-file blob :test.t >test.r &&
52 ./rot13.sh <test.o >test.t &&
53 test_cmp test.r test.t
56 # If an expanded ident ever gets into the repository, we want to make sure that
57 # it is collapsed before being expanded again on checkout
58 test_expect_success expanded_in_repo '
60 echo "File with expanded keywords"
61 echo "\$Id\$"
62 echo "\$Id:\$"
63 echo "\$Id: 0000000000000000000000000000000000000000 \$"
64 echo "\$Id: NoSpaceAtEnd\$"
65 echo "\$Id:NoSpaceAtFront \$"
66 echo "\$Id:NoSpaceAtEitherEnd\$"
67 echo "\$Id: NoTerminatingSymbol"
68 echo "\$Id: Foreign Commit With Spaces \$"
69 } >expanded-keywords.0 &&
72 cat expanded-keywords.0 &&
73 printf "\$Id: NoTerminatingSymbolAtEOF"
74 } >expanded-keywords &&
75 cat expanded-keywords >expanded-keywords-crlf &&
76 git add expanded-keywords expanded-keywords-crlf &&
77 git commit -m "File with keywords expanded" &&
78 id=$(git rev-parse --verify :expanded-keywords) &&
81 echo "File with expanded keywords"
82 echo "\$Id: $id \$"
83 echo "\$Id: $id \$"
84 echo "\$Id: $id \$"
85 echo "\$Id: $id \$"
86 echo "\$Id: $id \$"
87 echo "\$Id: $id \$"
88 echo "\$Id: NoTerminatingSymbol"
89 echo "\$Id: Foreign Commit With Spaces \$"
90 } >expected-output.0 &&
92 cat expected-output.0 &&
93 printf "\$Id: NoTerminatingSymbolAtEOF"
94 } >expected-output &&
96 append_cr <expected-output.0 &&
97 printf "\$Id: NoTerminatingSymbolAtEOF"
98 } >expected-output-crlf &&
100 echo "expanded-keywords ident"
101 echo "expanded-keywords-crlf ident text eol=crlf"
102 } >>.gitattributes &&
104 rm -f expanded-keywords expanded-keywords-crlf &&
106 git checkout -- expanded-keywords &&
107 test_cmp expanded-keywords expected-output &&
109 git checkout -- expanded-keywords-crlf &&
110 test_cmp expanded-keywords-crlf expected-output-crlf
113 # The use of %f in a filter definition is expanded to the path to
114 # the filename being smudged or cleaned. It must be shell escaped.
115 # First, set up some interesting file names and pet them in
116 # .gitattributes.
117 test_expect_success 'filter shell-escaped filenames' '
118 cat >argc.sh <<-EOF &&
119 #!$SHELL_PATH
120 cat >/dev/null
121 echo argc: \$# "\$@"
123 normal=name-no-magic &&
124 special="name with '\''sq'\'' and \$x" &&
125 echo some test text >"$normal" &&
126 echo some test text >"$special" &&
127 git add "$normal" "$special" &&
128 git commit -q -m "add files" &&
129 echo "name* filter=argc" >.gitattributes &&
131 # delete the files and check them out again, using a smudge filter
132 # that will count the args and echo the command-line back to us
133 test_config filter.argc.smudge "sh ./argc.sh %f" &&
134 rm "$normal" "$special" &&
135 git checkout -- "$normal" "$special" &&
137 # make sure argc.sh counted the right number of args
138 echo "argc: 1 $normal" >expect &&
139 test_cmp expect "$normal" &&
140 echo "argc: 1 $special" >expect &&
141 test_cmp expect "$special" &&
143 # do the same thing, but with more args in the filter expression
144 test_config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
145 rm "$normal" "$special" &&
146 git checkout -- "$normal" "$special" &&
148 # make sure argc.sh counted the right number of args
149 echo "argc: 2 $normal --my-extra-arg" >expect &&
150 test_cmp expect "$normal" &&
151 echo "argc: 2 $special --my-extra-arg" >expect &&
152 test_cmp expect "$special" &&
156 test_expect_success 'required filter should filter data' '
157 test_config filter.required.smudge ./rot13.sh &&
158 test_config filter.required.clean ./rot13.sh &&
159 test_config filter.required.required true &&
161 echo "*.r filter=required" >.gitattributes &&
163 cat test.o >test.r &&
164 git add test.r &&
166 rm -f test.r &&
167 git checkout -- test.r &&
168 test_cmp test.o test.r &&
170 ./rot13.sh <test.o >expected &&
171 git cat-file blob :test.r >actual &&
172 test_cmp expected actual
175 test_expect_success 'required filter smudge failure' '
176 test_config filter.failsmudge.smudge false &&
177 test_config filter.failsmudge.clean cat &&
178 test_config filter.failsmudge.required true &&
180 echo "*.fs filter=failsmudge" >.gitattributes &&
182 echo test >test.fs &&
183 git add test.fs &&
184 rm -f test.fs &&
185 test_must_fail git checkout -- test.fs
188 test_expect_success 'required filter clean failure' '
189 test_config filter.failclean.smudge cat &&
190 test_config filter.failclean.clean false &&
191 test_config filter.failclean.required true &&
193 echo "*.fc filter=failclean" >.gitattributes &&
195 echo test >test.fc &&
196 test_must_fail git add test.fc
199 test_expect_success 'filtering large input to small output should use little memory' '
200 test_config filter.devnull.clean "cat >/dev/null" &&
201 test_config filter.devnull.required true &&
202 for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB &&
203 echo "30MB filter=devnull" >.gitattributes &&
204 GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
207 test_expect_success 'filter that does not read is fine' '
208 test-genrandom foo $((128 * 1024 + 1)) >big &&
209 echo "big filter=epipe" >.gitattributes &&
210 test_config filter.epipe.clean "echo xyzzy" &&
211 git add big &&
212 git cat-file blob :big >actual &&
213 echo xyzzy >expect &&
214 test_cmp expect actual
217 test_expect_success EXPENSIVE 'filter large file' '
218 test_config filter.largefile.smudge cat &&
219 test_config filter.largefile.clean cat &&
220 for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
221 echo "2GB filter=largefile" >.gitattributes &&
222 git add 2GB 2>err &&
223 test_must_be_empty err &&
224 rm -f 2GB &&
225 git checkout -- 2GB 2>err &&
226 test_must_be_empty err
229 test_expect_success "filter: clean empty file" '
230 test_config filter.in-repo-header.clean "echo cleaned && cat" &&
231 test_config filter.in-repo-header.smudge "sed 1d" &&
233 echo "empty-in-worktree filter=in-repo-header" >>.gitattributes &&
234 >empty-in-worktree &&
236 echo cleaned >expected &&
237 git add empty-in-worktree &&
238 git show :empty-in-worktree >actual &&
239 test_cmp expected actual
242 test_expect_success "filter: smudge empty file" '
243 test_config filter.empty-in-repo.clean "cat >/dev/null" &&
244 test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
246 echo "empty-in-repo filter=empty-in-repo" >>.gitattributes &&
247 echo dead data walking >empty-in-repo &&
248 git add empty-in-repo &&
250 echo smudged >expected &&
251 git checkout-index --prefix=filtered- empty-in-repo &&
252 test_cmp expected filtered-empty-in-repo
255 test_expect_success 'disable filter with empty override' '
256 test_config_global filter.disable.smudge false &&
257 test_config_global filter.disable.clean false &&
258 test_config filter.disable.smudge false &&
259 test_config filter.disable.clean false &&
261 echo "*.disable filter=disable" >.gitattributes &&
263 echo test >test.disable &&
264 git -c filter.disable.clean= add test.disable 2>err &&
265 test_must_be_empty err &&
266 rm -f test.disable &&
267 git -c filter.disable.smudge= checkout -- test.disable 2>err &&
268 test_must_be_empty err
271 test_expect_success 'diff does not reuse worktree files that need cleaning' '
272 test_config filter.counter.clean "echo . >>count; sed s/^/clean:/" &&
273 echo "file filter=counter" >.gitattributes &&
274 test_commit one file &&
275 test_commit two file &&
277 >count &&
278 git diff-tree -p HEAD &&
279 test_line_count = 0 count
282 test_done