summaryrefslogtreecommitdiff
path: root/tests/tests/gitattributes
blob: fd3faa35899acc3e43bd5870ee5b7e7c4773150e (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
#!/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 $'
	echo >>gitattrs "af/$filename" "$attrspec"
}

badattr () {
	attrname=$1; shift
	badattr1 $attrname-set $attrname
	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

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

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 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 .
	$addpatch files

	cp ../sums .
	$addpatch sums

	dpkg-source -b .

	cd ..
}

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

	mkdir $pdb-import-$inst
	cd $pdb-import-$inst
	git init

	LC_MESSAGES=C \
	t-dgit $dgitargs import-dsc ../$dscf +$branch.broken \
		2>&1 |tee ../$brkerr
	fgrep 'warning: source tree contains .gitattributes' ../$brkerr
	git checkout $branch.broken
	sha256sum 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 setup-new-tree

	t-dgit $dgitargs import-dsc ../$dscf +$branch
	git checkout $branch

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

	cd ..
	diff -U0 sums $sums
}

: ----- 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

#t-ok