#!/usr/bin/env bash
set -ev

DARCS_EMAIL=tester
export DARCS_EMAIL
test $DARCS || DARCS=$PWD/../darcs

rm -rf temp
mkdir temp
cd temp

$DARCS init

echo "X X X" > foo
$DARCS rec -alm "Added"

# This should fail until replace handles spaces
$DARCS replace ' X ' ' XX ' --token-chars '[ X]' foo && exit 1 || true

# Check that replace is not fooled by duplicate file names
# (i.e. not trying to performe the replace twice in the same file)
$DARCS replace X Y foo foo
$DARCS replace Y Z foo ../temp/foo
$DARCS replace Z Q foo foo --repodir=../temp/
$DARCS rec -am "xyzq"


# Try to "overwrite" a hunk with a replace.
#
# v1.0.8 accepts this without error or warning,
# but should perhaps require the --force option?
#
# current unstable sometimes(!) fails with bug: invalid pending
# which is surely a bug.

# this succeeds
echo "x" > foo
$DARCS rec -am xx
echo "y" > foo
$DARCS replace --ignore-times x y foo

# this fails
echo "hej" > foo
$DARCS rec -am hej
echo "hopp" > foo
$DARCS replace hej hopp foo

$DARCS whatsnew

echo "src" > foo
echo "dst" >> foo
$DARCS rec -am hop
$DARCS replace src dst foo || true
$DARCS replace --force src dst foo

$DARCS whatsnew
$DARCS whatsnew -ls

cd ..
rm -rf temp
