#!/bin/sh

echo "* Removing old directories"
# Cleanup
rm -rf test1
mkdir test1
cd test1

# Create repo
svnadmin create repo
URL=file://`pwd`/repo
TRUNK=$URL/trunk
A=$URL/branches/a


echo "* Performing initial import"
# Initial import
mkdir -p tmp/trunk tmp/branches tmp/tags
echo hello > tmp/trunk/foo.c
echo world > tmp/trunk/bar.c
svn import -m "Initial import" tmp $URL
rm -rf tmp

echo "* Checking out WC of trunk"
# Checkout WC of trunk
svn co $TRUNK

echo "* Creating branch a"
# Create branch
svn cp -m "Create branchA" $TRUNK $A

echo "* Checking out WC of branch a"
# Checkout WC of a
svn co $A

echo "* Adding line to foo.c on branch a"
# Add line to foo.c in branch a
cd a
echo "new line" >> foo.c
svn ci -m "add new line on branch a"

echo "* Merge --reintegrate from branch a to trunk"
# Reintegrate to trunk
cd ../trunk
svn up
svn merge --reintegrate $A
svn ci -m "reintegrate from branch a"

# Remove line from foo.c in trunk
echo hello > foo.c
svn ci -m "Remove merged line from trunk"


# Reintegrate from branch a again.  Shouldn't
# add line again, but it does!
svn up
svn merge --reintegrate $A
svn ci -m "2nd reintegrate from branch a"

# Do empty merge up to rev 4, to change which rev
# will be used in the 2-URL merge for reintegrate.
cd ../a
svn up
svn merge -r 1:4 $A
svn ci -m "Empty merge of revs 1:4 from trunk"

# This time reintegrate should be smart enough
# to know the changes have already been reintegrated.
cd ../trunk
svn up
svn merge --reintegrate $A
svn ci -m "reintegrate from branch a"

cd ..

