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

test $DARCS || DARCS=$PWD/../darcs

rm -rf temp
mkdir temp
cd temp

$DARCS init
touch fee fi fo fum
$DARCS add f*
$DARCS record --author me --all --no-test --patch-name add
mkdir d
$DARCS add d
$DARCS mv f* d
$DARCS remove d/fi
cd d
$DARCS remove fo
echo let us have fun > fun
$DARCS add fun
$DARCS mv fun fum ..
$DARCS record --author me --all --no-test --patch-name mv
cd ..

if $DARCS show files | egrep '^./fee$'; then false; else true; fi
test ! -f fee
$DARCS show contents d/fee | cmp d/fee -

test ! -f fi
test -f d/fi
if $DARCS show files | egrep '^./fi$'; then false; else true; fi
if $DARCS show files | egrep '^./d/fi$'; then false; else true; fi

test ! -f fo
test -f d/fo
if $DARCS show files | egrep '^./fo$'; then false; else true; fi
if $DARCS show files | egrep '^./d/fo$'; then false; else true; fi

$DARCS show contents fun | cmp fun -
$DARCS show contents fum | cmp fum -

$DARCS mv fun d
$DARCS record -A me -a --no-test -m "fun again"
$DARCS show content d/fun | cmp d/fun -
test ! -f fun
if $DARCS show files | egrep '^./fun$'; then false; else true; fi

# Now clean up.
cd ..
rm -rf temp

