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

t-restrict x-dgit-skip-suite,bullseye
t-restrict x-dgit-skip-suite,buster
t-dependencies T2U DEBORIG

t-setup-import gbp

t-t2u-settings
t-debpolicy

export XZ_OPT=-0

cd $p

git deborig

t-t2u-setup-repo

tagname=test-dummy/$v
t-expect-fail "please supply a --quilt= argument" t-t2u-test

# Seed a quilt mode with an upload that never was.
# Also test git-debpush's --print-tag-text option.
${DGIT_DEBPUSH_TEST-git debpush} --tag-only --print-tag-text \
				 --quilt=gbp --distro=test-dummy \
				 -u Senatus >$tmp/t.output
t-grep-mpat E:'^\[dgit distro=test-dummy split --quilt=gbp\]$' \
	    $tmp/t.output

v=1.0-2
t-dch-commit -v $v -m bump
t-dch-commit-r

t-dgit -wgf --quilt=gbp --dgit-view-save=split.b quilt-fixup

# Test that git-debpush can now figure out the quilt mode for itself.
tagname=test-dummy/$v
t-t2u-test
t-t2u-succeeded

git branch split.p dgit/dgit/sid # we didn't generate this here

t-gbp-pushed-good sid

t-t2u-gittarxz-unpack
t-dgit --quilt=gbp --dgit-view-save=split.t quilt-fixup
t-t2u-gittarxz-reproduced

# Test changing suite while in NEW

v=1.0-3
tagname=test-dummy/$v
t-dch-commit -v $v -m bump
t-dch-commit-r experimental
t-t2u-test-core irrecoverable
grep 'Package is in NEW and has not been accepted or rejected yet' \
    ../t2u/worker-cwd/w0/dgit-tmp/t2u.log

# Test orig handling when we change suites (#1105766)

v=1.0-2
t-archive-process-incoming unstable

t-refs-same-start
export XZ_OPT=-1 # change the generated orig

v=1.0-4
tagname=test-dummy/$v
t-dch-commit -v $v -m bump
t-dch-commit-r experimental
t-t2u-test
t-t2u-succeeded

origs_from_dsc () { grep -P "^ [0-9a-f].* ${p}.*orig.tar"; }

origs_from_dsc >../old-orig <../mirror/pool/main/${p}_1.0-2.dsc
origs_from_dsc >../new-orig <../incoming/${p}_${v}.dsc
diff -u ../{old,new}-orig

t-ok
