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