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

t-tstunt-parsechangelog

t-prep-newpackage example 1.1

ln -s $troot/pkg-srcs/${p}_${v%-*}.orig.tar.* .

cd $p

start () { git checkout quilt-tip-1.1~0; }
attempt () { t-dgit -wgf --quilt=smash quilt-fixup; }
good () {
	attempt
	t-dgit --quilt=nofix -wgf build-source
	t-dgit -wgf --dry-run push --new
}

badly-1 () {
	wrongfn=$1
	wrongmsg=$2
	start
}

badly-2-raw () {
	git commit -m "Commit wrongness $wrongfn ($wrongmsg)"
	t-expect-fail "$1" \
	attempt
}
badly-2 () {
	badly-2-raw E:"cannot represent change: $wrongmsg .*: $wrongfn"
}

badly-1 orig-symlink 'modified symlink'
	ln -sf NEWTARGET orig-symlink
	git add orig-symlink
badly-2

badly-1 orig-symlink 'deletion of symlink'
	git rm -f orig-symlink
badly-2

badly-1
	ln -s hi new
	git add new
badly-2-raw 'new version is symlink' 

start
	git rm src.c
	git commit -m deleted
good

start
	git rm orig-exec
	git rm -f orig-unwriteable
	git commit -m 'deleted funny'
good

badly-1 src.c 'mode or type changed'
	chmod +x src.c
	git add src.c
badly-2

start
good

t-ok
