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