chiark / gitweb /
fcbe313b623d7a8b1cde10f648bb7a20ce86c493
[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 origtar=${p}_${bv}.orig.tar.gz
154
155 tar --exclude=debian --exclude=.git -zcf $origtar $p
156
157 : ----- test 1.0 native -----
158
159 native_addpatch () { :; }
160 native_convert () { :; }
161
162 sfmt_setup 1.1 native
163 sfmt_import norm
164
165 : ----- test 1.0 diff -----
166
167 diff_addpatch () { :; }
168 diff_convert () { :; }
169
170 sfmt_setup 1.1 diff
171 sfmt_import norm
172
173 : ----- test "3.0 (quilt)" -----
174
175 quilt_addpatch () {
176         pname=$1
177         cat >../editor.pl <<END
178                 next if m/^$/..0;
179                 s{^(description:).*}{\$1 dgit test patch $pname}i;
180                 \$_='' if m/^ /;
181 END
182         EDITOR="perl -pi $tmp/editor.pl" dpkg-source -iX --commit . $pname
183         test -f debian/patches/$pname
184 }
185
186 quilt_convert () {
187         mkdir -p debian/source
188         echo '3.0 (quilt)' >debian/source/format
189 }
190
191 sfmt_setup 1.0-1 quilt
192 sfmt_import norm
193 sfmt_import absurd --force-import-gitapply-absurd
194
195 #t-ok