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

t-tstunt-parsechangelog

t-debpolicy
t-prep-newpackage example 1.0

cd $p
revision=1
git tag start
t-dgit setup-mergechangelogs


: upload

t-dgit push-source --new

t-commit 'edit after first push'

t-expect-push-fail-tainted-new \
 'Package is in NEW and has not been accepted or rejected yet' \
t-dgit push-source --new

: cut

rm $tmp/incoming/*
t-archive-none example

touch -d 'now -1 day' $tmp/git/example*

t-policy-periodic # TODO maybe want test both with and without this

: edit
t-commit 'edit after cut'

: push, needs --deliberately

t-expect-push-fail-tainted-new \
 'Reason:.* all previously pushed versions were found to have been removed from NEW' \
t-dgit push-source --new
grep -P '^History is based on .* REJECTed from NEW' ../t.output.precheck
grep -P '^remote: History contains commits .* REJECTed' ../t.output.remote

t-expect-push-fail-tainted-new \
 'Reason:.* all previously pushed versions were found to have been removed from NEW' \
t-dgit push-source --new --deliberately-not-fast-forward \
	--force-reusing-version

advice_count=$(
    grep -P <../t.output.precheck -P -c \
	 '^History is based on .* REJECTed from NEW'
)
test $advice_count = 1

t-dgit push-source --new --untaint-history \
	--force-reusing-version \
	>../deliberately-forced.log 2>&1

cat ../deliberately-forced.log >&2

grep -P '^remote: Forcing due to --deliberately-include-questionable-history' \
      ../deliberately-forced.log

t-archive-process-incoming new

# : t-policy-periodic # maybe want test with this

: accept

mv -f $tmp/aq/package.{new,sid}.$p
t-aq-archive-updated sid $p

# : t-policy-periodic # maybe want test with this

t-git-dir-time-passes

: 3rd push, no deliberately

t-commit 'edit after accept'
t-dgit push-source

t-ok
