]>
Commit | Line | Data |
---|---|---|
3fed15f5 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='blob conversion via gitattributes' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
fa7151a6 JS |
7 | cat <<EOF >rot13.sh |
8 | #!$SHELL_PATH | |
7339eb08 JK |
9 | tr \ |
10 | 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \ | |
11 | 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM' | |
aa4ed402 JH |
12 | EOF |
13 | chmod +x rot13.sh | |
14 | ||
3fed15f5 | 15 | test_expect_success setup ' |
aa4ed402 JH |
16 | git config filter.rot13.smudge ./rot13.sh && |
17 | git config filter.rot13.clean ./rot13.sh && | |
18 | ||
3fed15f5 | 19 | { |
aa4ed402 | 20 | echo "*.t filter=rot13" |
3fed15f5 JH |
21 | echo "*.i ident" |
22 | } >.gitattributes && | |
23 | ||
24 | { | |
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 | |
af9b54bb | 27 | echo '\''$Id$'\'' |
3fed15f5 JH |
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 | |
35 | ' | |
36 | ||
af9b54bb | 37 | script='s/^\$Id: \([0-9a-f]*\) \$/\1/p' |
3fed15f5 JH |
38 | |
39 | test_expect_success check ' | |
40 | ||
41 | cmp test.o test && | |
42 | cmp test.o test.t && | |
43 | ||
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) && | |
a0ae35ae JS |
48 | test "z$id" = "z$embedded" && |
49 | ||
50 | git cat-file blob :test.t > test.r && | |
51 | ||
52 | ./rot13.sh < test.o > test.t && | |
53 | cmp test.r test.t | |
3fed15f5 JH |
54 | ' |
55 | ||
dfab71cb AP |
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 ' | |
59 | { | |
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" | |
a9f3049f | 68 | echo "\$Id: Foreign Commit With Spaces \$" |
6b6cab3f | 69 | } >expanded-keywords.0 && |
dfab71cb | 70 | |
6b6cab3f JH |
71 | { |
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 && | |
dd555d8b RS |
77 | git commit -m "File with keywords expanded" && |
78 | id=$(git rev-parse --verify :expanded-keywords) && | |
79 | ||
dfab71cb AP |
80 | { |
81 | echo "File with expanded keywords" | |
dd555d8b RS |
82 | echo "\$Id: $id \$" |
83 | echo "\$Id: $id \$" | |
84 | echo "\$Id: $id \$" | |
85 | echo "\$Id: $id \$" | |
86 | echo "\$Id: $id \$" | |
87 | echo "\$Id: $id \$" | |
dfab71cb | 88 | echo "\$Id: NoTerminatingSymbol" |
07814d90 | 89 | echo "\$Id: Foreign Commit With Spaces \$" |
6b6cab3f JH |
90 | } >expected-output.0 && |
91 | { | |
92 | cat expected-output.0 && | |
dd555d8b | 93 | printf "\$Id: NoTerminatingSymbolAtEOF" |
6b6cab3f JH |
94 | } >expected-output && |
95 | { | |
96 | append_cr <expected-output.0 && | |
97 | printf "\$Id: NoTerminatingSymbolAtEOF" | |
98 | } >expected-output-crlf && | |
99 | { | |
100 | echo "expanded-keywords ident" | |
101 | echo "expanded-keywords-crlf ident text eol=crlf" | |
102 | } >>.gitattributes && | |
dfab71cb | 103 | |
6b6cab3f | 104 | rm -f expanded-keywords expanded-keywords-crlf && |
dfab71cb | 105 | |
dfab71cb | 106 | git checkout -- expanded-keywords && |
6b6cab3f JH |
107 | test_cmp expanded-keywords expected-output && |
108 | ||
109 | git checkout -- expanded-keywords-crlf && | |
110 | test_cmp expanded-keywords-crlf expected-output-crlf | |
dfab71cb AP |
111 | ' |
112 | ||
a2b665de PW |
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 | |
4290f690 | 120 | cat >/dev/null |
a2b665de PW |
121 | echo argc: \$# "\$@" |
122 | EOF | |
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 && | |
130 | ||
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 | git config filter.argc.smudge "sh ./argc.sh %f" && | |
134 | rm "$normal" "$special" && | |
135 | git checkout -- "$normal" "$special" && | |
136 | ||
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" && | |
142 | ||
143 | # do the same thing, but with more args in the filter expression | |
144 | git config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" && | |
145 | rm "$normal" "$special" && | |
146 | git checkout -- "$normal" "$special" && | |
147 | ||
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" && | |
153 | : | |
154 | ' | |
155 | ||
36daaaca JB |
156 | test_expect_success 'required filter success' ' |
157 | git config filter.required.smudge cat && | |
158 | git config filter.required.clean cat && | |
159 | git config filter.required.required true && | |
160 | ||
161 | echo "*.r filter=required" >.gitattributes && | |
162 | ||
163 | echo test >test.r && | |
164 | git add test.r && | |
165 | rm -f test.r && | |
166 | git checkout -- test.r | |
167 | ' | |
168 | ||
169 | test_expect_success 'required filter smudge failure' ' | |
170 | git config filter.failsmudge.smudge false && | |
171 | git config filter.failsmudge.clean cat && | |
172 | git config filter.failsmudge.required true && | |
173 | ||
174 | echo "*.fs filter=failsmudge" >.gitattributes && | |
175 | ||
176 | echo test >test.fs && | |
177 | git add test.fs && | |
178 | rm -f test.fs && | |
179 | test_must_fail git checkout -- test.fs | |
180 | ' | |
181 | ||
182 | test_expect_success 'required filter clean failure' ' | |
183 | git config filter.failclean.smudge cat && | |
184 | git config filter.failclean.clean false && | |
185 | git config filter.failclean.required true && | |
186 | ||
187 | echo "*.fc filter=failclean" >.gitattributes && | |
188 | ||
189 | echo test >test.fc && | |
190 | test_must_fail git add test.fc | |
191 | ' | |
192 | ||
0b6806b9 SP |
193 | test_expect_success EXPENSIVE 'filter large file' ' |
194 | git config filter.largefile.smudge cat && | |
195 | git config filter.largefile.clean cat && | |
196 | for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB && | |
197 | echo "2GB filter=largefile" >.gitattributes && | |
198 | git add 2GB 2>err && | |
199 | ! test -s err && | |
200 | rm -f 2GB && | |
201 | git checkout -- 2GB 2>err && | |
202 | ! test -s err | |
203 | ' | |
204 | ||
3fed15f5 | 205 | test_done |