chiark / gitweb /
test suite: gitattributes: Break out dscf= 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 bv=1.0
11 t-worktree $bv
12
13 : ----- prepare badnesses -----
14
15 mkdir af
16
17 badattr1 () {
18         local filename=$1
19         local attrspec=$2
20         echo >>af/$filename "Test file with $attrspec"
21         printf >>af/$filename 'crlf: \r\n'
22         echo >>af/$filename 'id $Id: $'
23         echo >>af/$filename 'id $Id: SPLARK $'
24         echo >>gitattrs "af/$filename" "$attrspec"
25 }
26
27 badattr () {
28         attrname=$1; shift
29         badattr1 $attrname-set $attrname
30         badattr1 $attrname-unset -$attrname
31         badattr1 $attrname-unspec \!$attrname
32         local val
33         for val in "$@"; do
34                 badattr1 $attrname=$val $attrname=$val
35         done
36 }
37
38 # xxx want to make each of these files into a quilt patch
39
40 t-git-config core.eol crlf
41
42 badattr text auto
43 badattr eol lf crlf
44 badattr ident
45
46 t-git-config filter.dgit-test-crazy-f.smudge '/usr/games/rot13 2'
47 t-git-config filter.dgit-test-crazy-f.clean  '/usr/games/rot13 24'
48 t-git-config filter.dgit-test-crazy-f.requrired true
49
50 badattr filter dgit-test-crazy-f
51
52 badattr diff
53 badattr merge text binary union
54 badattr whitespace
55 badattr export-ignore
56 badattr export-subst
57 badattr delta
58 badattr encoding no-such-encoding
59
60 man gitattributes \
61 | perl -ne 'print $1,"\n" if m/^ *(\w[-a-z]*)$/' \
62 > grepped-attrs
63
64 exec <grepped-attrs
65 while read attr; do
66         badattr $attr
67 done
68
69 sha256sum af/* >sums
70
71 # ----- common to source formats -----
72
73 sfmt_setup () {
74         v=$1
75         sfmt=$2
76
77         pdb=$p.$sfmt
78
79         local addpatch=${sfmt}_addpatch
80         local convert=${sfmt}_convert
81
82         cp -a $p $pdb-edit
83         cd $pdb-edit
84
85         $convert
86
87         dch -v $v -m convert
88
89         rm -rf .git
90
91         cp ../gitattrs .gitattributes
92         $addpatch gitattrs
93
94         cp -a ../af .
95         $addpatch files
96
97         cp ../sums .
98         $addpatch sums
99
100         dpkg-source -b .
101
102         cd ..
103 }
104
105 sfmt_import () {
106         inst=$1
107         dgitargs=$2
108         refname="import.$sfmt-$inst"
109         brkerr=stderr.$sfmt-$inst.broken
110         dscf=${p}_${v}.dsc
111
112         mkdir $pdb-import-$inst
113         cd $pdb-import-$inst
114         git init
115
116         LC_MESSAGES=C \
117         t-dgit $dgitargs import-dsc ../$dscf +$refname.broken \
118                 2>&1 |tee ../$brkerr
119         fgrep 'warning: source tree contains .gitattributes' ../$brkerr
120         git checkout $refname.broken
121         sha256sum af/* >../$sums.broken
122
123         for s in ../sums ../$sums.broken; do
124                 sed 's/[0-9a-f]* //' $s >$s.nosums
125         done
126         diff -U0 ../sums.nosums ../$sums.broken.nosums
127         set +e
128         diff -U0 ../sums ../$sums.broken
129         rc=$?
130         set -e
131         test $rc = 1
132
133         t-dgit setup-new-tree
134
135         t-dgit $dgitargs import-dsc ../$dscf +$refname
136         git checkout $refname
137
138         sums=sums.$sfmt-$inst
139
140         for f in af/*; do
141                 git cat-file blob "refs/heads/$refname:$f" \
142                         | sha256sum \
143                         | sed -e 's#-$#'$f'#' \
144                 >>../$sums
145         done
146
147         cd ..
148         diff -U0 sums $sums
149 }
150
151 : ----- generate the orig -----
152
153 tar --exclude=debian --exclude=.git -zcf ${p}_${bv}.orig.tar.gz $p
154
155 : ----- test 1.0 native -----
156
157 native_addpatch () { :; }
158 native_convert () { :; }
159
160 sfmt_setup 1.1 native
161 sfmt_import norm
162
163 : ----- test 1.0 diff -----
164
165 diff_addpatch () { :; }
166 diff_convert () { :; }
167
168 sfmt_setup 1.1 diff
169 sfmt_import norm
170
171 : ----- test "3.0 (quilt)"
172
173 quilt_addpatch () {
174         pname=$1
175         cat >../editor.pl <<END
176                 next if m/^$/..0;
177                 s{^(description:).*}{\$1 dgit test patch $pname}i;
178                 \$_='' if m/^ /;
179 END
180         EDITOR="perl -pi $tmp/editor.pl" dpkg-source -iX --commit . $pname
181         test -f debian/patches/$pname
182 }
183
184 quilt_convert () {
185         mkdir -p debian/source
186         echo '3.0 (quilt)' >debian/source/format
187 }
188
189 sfmt_setup 1.0-1 quilt
190 sfmt_import norm
191 sfmt_import absurd --force-import-gitapply-absurd
192
193 #t-ok