chiark / gitweb /
test suite: git-debrebase: provide GDR "macro" for dependencies
[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         touch af/*
182         git reset --hard
183
184         sums_check
185
186         cd ..
187 }
188
189 : ----- generate the orig -----
190
191 origtar=${p}_${bv}.orig.tar.gz
192
193 tar --exclude=debian --exclude=.git -zcf $origtar $p
194
195 : ----- test 1.0 native -----
196
197 native_addpatch () { :; }
198 native_convert () { :; }
199
200 sfmt_setup 1.1 native
201 sfmt_import norm
202
203 : ----- test 1.0 diff -----
204
205 diff_addpatch () { :; }
206 diff_convert () { :; }
207
208 sfmt_setup 1.1 diff
209 sfmt_import norm
210
211 : ----- test "3.0 (quilt)" -----
212
213 quilt_addpatch () {
214         pname=$1
215         cat >../editor.pl <<END
216                 next if m/^$/..0;
217                 s{^(description:).*}{\$1 dgit test patch $pname}i;
218                 \$_='' if m/^ /;
219 END
220         EDITOR="perl -pi $tmp/editor.pl" dpkg-source -iX --commit . $pname
221         test -f debian/patches/$pname
222 }
223
224 quilt_convert () {
225         mkdir -p debian/source
226         echo '3.0 (quilt)' >debian/source/format
227 }
228
229 sfmt_setup 1.0-1 quilt
230 sfmt_import norm
231 sfmt_import absurd --force-import-gitapply-absurd
232
233 : ----- 'test clone (with "3.0 (quilt)")' -----
234
235 mv $origtar ${dscf%.dsc}.* $tmp/mirror/pool/main/
236 t-archive-query sid
237
238 t-dgit-warn-check 0 -cdgit.default.setup-gitattributes=false \
239         clone $p sid $p.clone.broken
240 cd $p.clone.broken
241
242 sums=$p.clone.broken
243 sums_check_broken
244
245 cd ..
246
247 t-dgit-warn-check 1 clone $p sid $p.clone
248
249 cd $p.clone
250 sums=sums.clone
251 branch=dgit/sid
252 sums_check
253
254 cd ..
255
256 t-ok