+ 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
+}