chiark / gitweb /
test suite: gitattributes: Test that checkout is good too
[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
132         mkdir $pdb-import-$inst
133         cd $pdb-import-$inst
134         git init
135
136         LC_MESSAGES=C \
137         t-dgit $dgitargs import-dsc ../$dscf +$branch.broken \
138                 2>&1 |tee ../$brkerr
139         fgrep 'warning: source tree contains .gitattributes' ../$brkerr
140         git checkout $branch.broken
141         sha256sum 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         t-dgit setup-new-tree
154
155         t-dgit $dgitargs import-dsc ../$dscf +$branch
156         git checkout $branch
157         git reset --hard
158
159         sums_check
160
161         cd ..
162 }
163
164 : ----- generate the orig -----
165
166 origtar=${p}_${bv}.orig.tar.gz
167
168 tar --exclude=debian --exclude=.git -zcf $origtar $p
169
170 : ----- test 1.0 native -----
171
172 native_addpatch () { :; }
173 native_convert () { :; }
174
175 sfmt_setup 1.1 native
176 sfmt_import norm
177
178 : ----- test 1.0 diff -----
179
180 diff_addpatch () { :; }
181 diff_convert () { :; }
182
183 sfmt_setup 1.1 diff
184 sfmt_import norm
185
186 : ----- test "3.0 (quilt)" -----
187
188 quilt_addpatch () {
189         pname=$1
190         cat >../editor.pl <<END
191                 next if m/^$/..0;
192                 s{^(description:).*}{\$1 dgit test patch $pname}i;
193                 \$_='' if m/^ /;
194 END
195         EDITOR="perl -pi $tmp/editor.pl" dpkg-source -iX --commit . $pname
196         test -f debian/patches/$pname
197 }
198
199 quilt_convert () {
200         mkdir -p debian/source
201         echo '3.0 (quilt)' >debian/source/format
202 }
203
204 sfmt_setup 1.0-1 quilt
205 sfmt_import norm
206 sfmt_import absurd --force-import-gitapply-absurd
207
208 #t-ok