#!/bin/bash
set -e
. tests/lib

t-dependencies DEBORIG

t-setup-import gbp

# TODO Test defusing of export-subst and export-ignore Git attributes.

uv=${v%-*}
otz=../${p}_${uv}.orig.tar.xz

cd $p

mv debian/changelog debian/change
t-expect-fail "pwd doesn't look like a Debian source package" \
t-git-deborig
mv debian/change debian/changelog

t-git-deborig
test -e $otz

rm debian/source/format
t-git-deborig
test -e ../${p}_${uv}.orig.tar.gz
git checkout debian/source/format

t-dch-commit -v2.0 bump
t-expect-fail "this looks like a native package" \
t-git-deborig
t-git-deborig HEAD~ --version=2.0
test -e ../${p}_2.0.orig.tar.xz
git revert --no-edit HEAD

t-expect-fail "already exists" \
t-git-deborig
t-git-deborig -f
test -e $otz

t-git-deborig --just-print >../just-print-actual
cat <<EOF >../just-print-expected
upstream/$uv
$otz
git -c 'tar.tar.xz.command=xz -c' archive --prefix=$p-$uv/ -o $otz upstream/$uv
EOF
diff -u ../just-print-{expected,actual}

t-git-deborig --just-print-tag-names >../just-print-tag-names-actual
cat <<EOF >../just-print-tag-names-expected
$uv
v$uv
upstream/$uv
EOF
diff -u ../just-print-tag-names-{expected,actual}

t-expect-fail "version number 1 2 is not valid" \
t-git-deborig --version="1 2"

t-expect-fail "couldn't find any of the following tags: 14%15_16, " \
t-git-deborig --version="13:14:15~16"

rm ../${p}_${uv}.orig.tar.*

git tag -a -m v$uv v$uv
t-expect-fail "all exist in this repository" \
t-git-deborig

git tag -d v$uv upstream/$uv
t-expect-fail "couldn't find any of the following tags: $uv, v$uv, upstream/$uv" \
t-git-deborig
