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

test $DARCS || DARCS=$PWD/../darcs
ACTUAL_DARCS=`which $DARCS`
DARCSPATH=`dirname $ACTUAL_DARCS`
PATH="$DARCSPATH:$PATH"
export PATH

rm -rf temp0 temp1 temp2

# step 1
mkdir temp0
cd temp0
$DARCS init --darcs-2
echo m1 > foo
$DARCS add foo
$DARCS record -a -m m1 -A moi --ignore-times
cd ..

# step 2
$DARCS get temp0 temp1
cd temp1
echo a1 > foo
$DARCS record foo -a -m a1 -A moi --ignore-times
cd ..


# step 3
cd temp0
echo m2 > foo
$DARCS record -a -m m2 -A moi --ignore-times
cd ..


# step 4
cd temp1
$DARCS pull -a
echo m2-a1 > foo
$DARCS record -a -m 'Fix conflict m2-a1' -A moi --ignore-times
cd ..

#step 5
cd temp0
echo m3 > foo
$DARCS record -a -m m3 -A moi --ignore-times
cd ..

#step 6
$DARCS get temp0 temp2
cd temp2
echo b1 > foo
$DARCS record -a -m b1 -A moi --ignore-times
cd ..

#step 7
cd temp0
echo m4 > foo
$DARCS record -a -m m4 -A moi --ignore-times
cd ..

#step 8
cd temp1
$DARCS pull -a
echo m2-a1-m4 > foo
echo y | $DARCS mark-conflicts
cd ..

rm -rf temp0 temp1 temp2
