#!/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 \
 '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 \
 'Reason:.* all previously pushed versions were found to have been removed from NEW' \
t-dgit push-source --new

t-expect-push-fail-tainted \
 '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 <../t.output -P -c \
	 'History contains commits .* previously REJECTed from NEW' 
)
test $advice_count = 1

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

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

egrep '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
