chiark / gitweb /
test suite: gitattributes: Test that old macros are updated
[dgit.git] / tests / tests / gitattributes
1 #!/bin/bash
2 set -e
3 . tests/lib
4
5 t-dependencies bsdgames
6 t-dependencies man-db git-man
7 t-tstunt-parsechangelog
8
9 t-archive-none example
10 t-git-none
11 bv=1.0
12 t-worktree $bv
13
14 : ----- prepare badnesses -----
15
16 mkdir af
17
18 badattr1 () {
19         local filename=$1
20         local attrspec=$2
21         echo >>af/$filename "Test file with $attrspec"
22         printf >>af/$filename 'crlf: \r\n'
23         echo >>af/$filename 'id $Id: $'
24         echo >>af/$filename 'id $Id: SPLARK $'
25         printf >>af/$filename '\xEF\xBB\xBF <- UTF-8 BOM\n'
26         echo >>gitattrs "af/$filename" "$attrspec"
27 }
28
29 badattr () {
30         attrname=$1; shift
31
32         case "$attrname" in
33         working-tree-encoding) ;;
34         *)
35                 badattr1 $attrname-set $attrname
36                 ;;
37         esac
38
39         badattr1 $attrname-unset -$attrname
40         badattr1 $attrname-unspec \!$attrname
41         local val
42         for val in "$@"; do
43                 badattr1 $attrname=$val $attrname=$val
44         done
45 }
46
47 # xxx want to make each of these files into a quilt patch
48
49 t-git-config core.eol crlf
50
51 badattr text auto
52 badattr eol lf crlf
53 badattr ident
54
55 t-git-config filter.dgit-test-crazy-f.smudge '/usr/games/rot13 2'
56 t-git-config filter.dgit-test-crazy-f.clean  '/usr/games/rot13 24'
57 t-git-config filter.dgit-test-crazy-f.requrired true
58
59 badattr filter dgit-test-crazy-f
60
61 badattr diff
62 badattr merge text binary union
63 badattr whitespace
64 badattr export-ignore
65 badattr export-subst
66 badattr delta
67 badattr encoding no-such-encoding
68 badattr working-tree-encoding ISO-8859-1 UTF-16
69
70 man gitattributes \
71 | perl -ne 'print $1,"\n" if m/^ *(\w[-a-z]*)$/' \
72 > grepped-attrs
73
74 exec <grepped-attrs
75 while read attr; do
76         badattr $attr
77 done
78
79 sha256sum af/* >sums
80
81 # ----- common to source formats -----
82
83 sfmt_setup () {
84         v=$1
85         sfmt=$2
86
87         pdb=$p.$sfmt
88
89         local addpatch=${sfmt}_addpatch
90         local convert=${sfmt}_convert
91
92         cp -a $p $pdb-edit
93         cd $pdb-edit
94
95         $convert
96
97         dch -v $v -m convert
98
99         rm -rf .git
100
101         cp ../gitattrs .gitattributes
102         $addpatch gitattrs
103
104         cp -a ../af .
105         $addpatch files
106
107         cp ../sums .
108         $addpatch sums
109
110         dpkg-source -b .
111
112         cd ..
113 }
114
115 sums_check () {
116         # caller should cd into working directory, set
117         #   $sums  $branch
118         # and check out $branch
119
120         sha256sum af/* >../$sums.checkout
121         diff -U0 ../sums ../$sums.checkout
122
123         for f in af/*; do
124                 git cat-file blob "refs/heads/$branch:$f" \
125                         | sha256sum \
126                         | sed -e 's#-$#'$f'#' \
127                 >>../$sums
128         done
129
130         diff -U0 ../sums ../$sums
131 }
132
133 sums_check_broken () {
134         # caller should cd into working directory, set
135         #   $sums
136         # and check out the broken branch
137
138         sha256sum af/* >../$sums.broken
139
140         for s in ../sums ../$sums.broken; do
141                 sed 's/[0-9a-f]* //' $s >$s.nosums
142         done
143         diff -U0 ../sums.nosums ../$sums.broken.nosums
144         set +e
145         diff -U0 ../sums ../$sums.broken
146         rc=$?
147         set -e
148         test $rc = 1
149 }
150
151 t-dgit-warn-check () {
152         local warnok=$1; shift
153         # warnok should be  0 if the warning is expected
154         #                   1 if the warning is NOT expected
155
156         local err=stderr.$wd
157
158         LC_MESSAGES=C t-dgit "$@" 2>&1 |tee ../$err
159
160         set +e
161         egrep 'warning: .* contains \.gitattributes' ../$err
162         rc=$?
163         set -e
164
165         test "$rc" = "$warnok"
166 }
167
168 sfmt_import () {
169         inst=$1
170         dgitargs=$2
171         branch="import.$sfmt-$inst"
172         dscf=${p}_${v}.dsc
173         sums=sums.$sfmt-$inst
174         wd=$pdb-import-$inst
175
176         mkdir $wd
177         cd $wd
178         git init
179
180         t-dgit-warn-check 0 $dgitargs import-dsc ../$dscf +$branch.broken
181
182         git checkout $branch.broken
183
184         sums_check_broken
185
186         t-dgit setup-new-tree
187
188         t-dgit-warn-check 1 $dgitargs import-dsc ../$dscf +$branch
189         git checkout $branch
190         touch af/*
191         git reset --hard
192
193         sums_check
194
195         cd ..
196 }
197
198 : ----- generate the orig -----
199
200 origtar=${p}_${bv}.orig.tar.gz
201
202 tar --exclude=debian --exclude=.git -zcf $origtar $p
203
204 : ----- test 1.0 native -----
205
206 native_addpatch () { :; }
207 native_convert () { :; }
208
209 sfmt_setup 1.1 native
210 sfmt_import norm
211
212 : ----- test 1.0 diff -----
213
214 diff_addpatch () { :; }
215 diff_convert () { :; }
216
217 sfmt_setup 1.1 diff
218 sfmt_import norm
219
220 : ----- test "3.0 (quilt)" -----
221
222 quilt_addpatch () {
223         pname=$1
224         cat >../editor.pl <<END
225                 next if m/^$/..0;
226                 s{^(description:).*}{\$1 dgit test patch $pname}i;
227                 \$_='' if m/^ /;
228 END
229         EDITOR="perl -pi $tmp/editor.pl" dpkg-source -iX --commit . $pname
230         test -f debian/patches/$pname
231 }
232
233 quilt_convert () {
234         mkdir -p debian/source
235         echo '3.0 (quilt)' >debian/source/format
236 }
237
238 sfmt_setup 1.0-1 quilt
239 sfmt_import norm
240 sfmt_import absurd --force-import-gitapply-absurd
241
242 : ----- 'test clone (with "3.0 (quilt)")' -----
243
244 mv $origtar ${dscf%.dsc}.* $tmp/mirror/pool/main/
245 t-archive-query sid
246
247 t-dgit-warn-check 0 -cdgit.default.setup-gitattributes=false \
248         clone $p sid $p.clone.broken
249 cd $p.clone.broken
250
251 sums=sums.broken
252 sums_check_broken
253
254 cd ..
255
256 t-dgit-warn-check 1 clone $p sid $p.clone
257
258 cd $p.clone
259 sums=sums.clone
260 branch=dgit/sid
261 sums_check
262
263 cd ..
264
265 t-dgit-warn-check 0 -cdgit.default.setup-gitattributes=false \
266         clone $p sid $p.clone.old
267
268 cd $p.clone.old
269
270 mkdir -p .git/info
271 cat >.git/info/attributes <<'END'
272 *       dgit-defuse-attrs
273 [attr]dgit-defuse-attrs -text -eol -crlf -ident -filter
274 # ^ see GITATTRIBUTES in dgit(7) and dgit setup-new-tree in dgit(1)
275 END
276
277 t-dgit setup-gitattributes
278 git reset --hard
279
280 sums=sums.old
281 sums_check
282
283 cd ..
284
285 t-ok