#!/bin/bash
set -e
. tests/lib
. $troot/lib-baredebian

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

t-t2u-settings
t-debpolicy

t-setup-import baredebian

cd $p

baredebian-test-vars
t-t2u-setup-repo

baredebian-test-minimum
baredebian-test-core-prepush


sed -i '15icorruption' debian/patches/0002-Edit-the-.c-file.patch
git add debian/patches/0002-Edit-the-.c-file.patch
git commit -m"corrupt a quilt patch to test the patches-nonapplicable check"

t-expect-fail "'git apply' failed to apply patch 0002-Edit-the-.c-file.patch ('patches-nonapplicable' check)" \
t-t2u-test --baredebian

git reset --hard HEAD~1

touch debian/src2.c
t-expect-fail "there are untracked files in debian/," \
t-t2u-test --baredebian
rm debian/src2.c

t-t2u-test --baredebian
t-t2u-succeeded

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

baredebian-test-core-postpush

t-t2u-gittarxz-unpack
t-dgit -wn --quilt=$quiltmode --dgit-view-save=split.t quilt-fixup
t-t2u-gittarxz-reproduced

t-archive-process-incoming sid

: 'test mismatching upstream tag'

git worktree add ../example2
cd ../example2
git checkout -b broken-upstream v1.0
echo discrepancy >upstream-discrepancy
git add upstream-discrepancy
git commit -m discrepancy
git tag broken-upstream-1.0
cd ../example

t-dch-commit-bump mismatch-in-upstream
t-refs-same-start
t-t2u-test-core irrecoverable --upstream=broken-upstream-1.0
grep -P  'git tree differs from orig in upstream files' \
    ../t2u/worker-cwd/w0/dgit-tmp/t2u.log

t-ok
