summaryrefslogtreecommitdiff
path: root/tests/tests/gitattributes
blob: bdc61f8afd980b80d6d35309b08623ba025a456b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
set -e
. tests/lib

t-dependencies bsdgames
t-dependencies man-db git-man
t-tstunt-parsechangelog

t-archive-none example
t-git-none
bv=1.0
t-worktree $bv

: ----- prepare badnesses -----

mkdir af

badattr1 () {
	local filename=$1
	local attrspec=$2
	echo >>af/$filename "Test file with $attrspec"
	printf >>af/$filename 'crlf: \r\n'
	echo >>af/$filename 'id $Id: $'
	echo >>af/$filename 'id $Id: SPLARK $'
	printf >>af/$filename '\xEF\xBB\xBF <- UTF-8 BOM\n'
	echo >>gitattrs "af/$filename" "$attrspec"
}

badattr () {
	attrname=$1; shift

	case "$attrname" in
	working-tree-encoding) ;;
	*)
		badattr1 $attrname-set $attrname
		;;
	esac

	badattr1 $attrname-unset -$attrname
	badattr1 $attrname-unspec \!$attrname
	local val
	for val in "$@"; do
		badattr1 $attrname=$val $attrname=$val
	done
}

# xxx want to make each of these files into a quilt patch

t-git-config core.eol crlf

printf >>.dotfile-attr 'dotfiles too?\n'
echo >>gitattrs '.dotfile-attr filter=dgit-test-crazy-f'

badattr	text auto
badattr eol lf crlf
badattr ident

t-git-config filter.dgit-test-crazy-f.smudge '/usr/games/rot13 2'
t-git-config filter.dgit-test-crazy-f.clean  '/usr/games/rot13 24'
t-git-config filter.dgit-test-crazy-f.requrired true

badattr filter dgit-test-crazy-f

badattr diff
badattr merge text binary union
badattr whitespace
badattr export-ignore
badattr export-subst
badattr delta
badattr encoding no-such-encoding
badattr working-tree-encoding ISO-8859-1 UTF-16

man gitattributes \
| perl -ne 'print $1,"\n" if m/^ *(\w[-a-z]*)$/' \
> grepped-attrs

exec <grepped-attrs
while read attr; do
	badattr $attr
done

sha256sum .dotfile-attr af/* >sums

# ----- common to source formats -----

sfmt_setup () {
	v=$1
	sfmt=$2

	pdb=$p.$sfmt

	local addpatch=${sfmt}_addpatch
	local convert=${sfmt}_convert

	cp -a $p $pdb-edit
	cd $pdb-edit

	$convert

	dch -v $v -m convert

	rm -rf .git

	cp ../gitattrs .gitattributes
	$addpatch gitattrs

	cp -a ../af ../.dotfile-attr .
	$addpatch files

	cp ../sums .
	$addpatch sums

	dpkg-source -b .

	cd ..
}

sums_check () {
	# caller should cd into working directory, set
	#   $sums  $branch
	# and check out $branch

	sha256sum .dotfile-attr af/* >../$sums.checkout
	diff -U0 ../sums ../$sums.checkout

	for f in .dotfile-attr af/*; do
		git cat-file blob "refs/heads/$branch:$f" \
			| sha256sum \
			| sed -e 's#-$#'$f'#' \
		>>../$sums
	done

	diff -U0 ../sums ../$sums
}

sums_check_broken () {
	# caller should cd into working directory, set
	#   $sums
	# and check out the broken branch

	sha256sum .dotfile-attr af/* >../$sums.broken

	for s in ../sums ../$sums.broken; do
		sed 's/[0-9a-f]* //' $s >$s.nosums
	done
	diff -U0 ../sums.nosums ../$sums.broken.nosums
	set +e
	diff -U0 ../sums ../$sums.broken
	rc=$?
	set -e
	test $rc = 1
}

t-dgit-warn-check () {
	local warnok=$1; shift
	# warnok should be  0 if the warning is expected
	#                   1 if the warning is NOT expected

	local err=stderr.$wd

	LC_MESSAGES=C t-dgit "$@" 2>&1 |tee ../$err

	set +e
	egrep 'warning: .* contains \.gitattributes' ../$err
	rc=$?
	set -e

	test "$rc" = "$warnok"
}

sfmt_import () {
	inst=$1
	dgitargs=$2
	branch="import.$sfmt-$inst"
	dscf=${p}_${v}.dsc
	sums=sums.$sfmt-$inst
	wd=$pdb-import-$inst

	mkdir $wd
	cd $wd
	git init

	t-dgit-warn-check 0 $dgitargs import-dsc ../$dscf +$branch.broken

	git checkout $branch.broken

	sums_check_broken

	t-dgit setup-new-tree

	t-dgit-warn-check 1 $dgitargs import-dsc ../$dscf +$branch
	git checkout $branch
	touch .dotfile-attr af/*
	git reset --hard

	sums_check

	cd ..
}

: ----- generate the orig -----

origtar=${p}_${bv}.orig.tar.gz

tar --exclude=debian --exclude=.git -zcf $origtar $p

: ----- test 1.0 native -----

native_addpatch () { :; }
native_convert () { :; }

sfmt_setup 1.1 native
sfmt_import norm

: ----- test 1.0 diff -----

diff_addpatch () { :; }
diff_convert () { :; }

sfmt_setup 1.1 diff
sfmt_import norm

: ----- test "3.0 (quilt)" -----

quilt_addpatch () {
	pname=$1
	cat >../editor.pl <<END
		next if m/^$/..0;
		s{^(description:).*}{\$1 dgit test patch $pname}i;
		\$_='' if m/^ /;
END
	EDITOR="perl -pi $tmp/editor.pl" dpkg-source -iX --commit . $pname
	test -f debian/patches/$pname
}

quilt_convert () {
	mkdir -p debian/source
	echo '3.0 (quilt)' >debian/source/format
}

sfmt_setup 1.0-1 quilt
sfmt_import norm
sfmt_import absurd --force-import-gitapply-absurd

: ----- 'test clone (with "3.0 (quilt)")' -----

mv $origtar ${dscf%.dsc}.* $tmp/mirror/pool/main/
t-archive-query sid

t-dgit-warn-check 0 -cdgit.default.setup-gitattributes=false \
	clone $p sid $p.clone.broken
cd $p.clone.broken

sums=sums.broken
sums_check_broken

cd ..

t-dgit-warn-check 1 clone $p sid $p.clone

cd $p.clone
sums=sums.clone
branch=dgit/sid
sums_check

cd ..

t-dgit-warn-check 0 -cdgit.default.setup-gitattributes=false \
	clone $p sid $p.clone.old

cd $p.clone.old

mkdir -p .git/info
cat >.git/info/attributes <<'END'
*       dgit-defuse-attrs
[attr]dgit-defuse-attrs -text -eol -crlf -ident -filter
# ^ see GITATTRIBUTES in dgit(7) and dgit setup-new-tree in dgit(1)
END

t-dgit setup-gitattributes
git reset --hard

sums=sums.old
sums_check

cd ..

t-ok