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