chiark / gitweb /
test suite: gitattributes: Break out wd= setting
[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 sfmt_import () {
125         inst=$1
126         dgitargs=$2
127         branch="import.$sfmt-$inst"
128         brkerr=stderr.$sfmt-$inst.broken
129         dscf=${p}_${v}.dsc
130         sums=sums.$sfmt-$inst
131         wd=$pdb-import-$inst
132
133         mkdir $wd
134         cd $wd
135         git init
136
137         LC_MESSAGES=C \
138         t-dgit $dgitargs import-dsc ../$dscf +$branch.broken \
139                 2>&1 |tee ../$brkerr
140         fgrep 'warning: source tree contains .gitattributes' ../$brkerr
141         git checkout $branch.broken
142         sha256sum af/* >../$sums.broken
143
144         for s in ../sums ../$sums.broken; do
145                 sed 's/[0-9a-f]* //' $s >$s.nosums
146         done
147         diff -U0 ../sums.nosums ../$sums.broken.nosums
148         set +e
149         diff -U0 ../sums ../$sums.broken
150         rc=$?
151         set -e
152         test $rc = 1
153
154         t-dgit setup-new-tree
155
156         t-dgit $dgitargs import-dsc ../$dscf +$branch
157         git checkout $branch
158         git reset --hard
159
160         sums_check
161
162         cd ..
163 }
164
165 : ----- generate the orig -----
166
167 origtar=${p}_${bv}.orig.tar.gz
168
169 tar --exclude=debian --exclude=.git -zcf $origtar $p
170
171 : ----- test 1.0 native -----
172
173 native_addpatch () { :; }
174 native_convert () { :; }
175
176 sfmt_setup 1.1 native
177 sfmt_import norm
178
179 : ----- test 1.0 diff -----
180
181 diff_addpatch () { :; }
182 diff_convert () { :; }
183
184 sfmt_setup 1.1 diff
185 sfmt_import norm
186
187 : ----- test "3.0 (quilt)" -----
188
189 quilt_addpatch () {
190         pname=$1
191         cat >../editor.pl <<END
192                 next if m/^$/..0;
193                 s{^(description:).*}{\$1 dgit test patch $pname}i;
194                 \$_='' if m/^ /;
195 END
196         EDITOR="perl -pi $tmp/editor.pl" dpkg-source -iX --commit . $pname
197         test -f debian/patches/$pname
198 }
199
200 quilt_convert () {
201         mkdir -p debian/source
202         echo '3.0 (quilt)' >debian/source/format
203 }
204
205 sfmt_setup 1.0-1 quilt
206 sfmt_import norm
207 sfmt_import absurd --force-import-gitapply-absurd
208
209 #t-ok