#!/bin/sh

PATH=/usr/local/subversion-1.4/bin:$PATH
export PATH

rm -rf /tmp/repos /tmp/wc

svnadmin create /tmp/repos
svn mkdir -m 'creating trunk' file:///tmp/repos/trunk  # r1
svn mkdir -m 'creating branches dir' file:///tmp/repos/branches  # r2

svn co file:///tmp/repos/trunk /tmp/wc
echo 'created file in r3' > /tmp/wc/foo.txt
svn add /tmp/wc/foo.txt
svn ci -m 'created file in r3' /tmp/wc/foo.txt  # r3
for i in 4 5 6; do \
    echo "content from r$i" >> /tmp/wc/foo.txt
    svn ci -m "Adding content for r$i" /tmp/wc/foo.txt
done

svn cp -r1 -m 'creating branch1' \
  file:///tmp/repos/trunk file:///tmp/repos/branches/branch1  # r7
svn switch file:///tmp/repos/branches/branch1 /tmp/wc

### If we do 'merge -r2:7', the correct content will be in the
### repository!  I'm assuming that we're sending the wrong copied-from
### information, probably not adjusting it after the second merge.
svn merge -r2:5 file:///tmp/repos/trunk /tmp/wc
svn merge -r5:7 file:///tmp/repos/trunk /tmp/wc
#svn merge -r2:7 file:///tmp/repos/trunk /tmp/wc

svn ci -m 'adding content to branch1' /tmp/wc  # r8

echo '-- start WC/foo.txt --'
cat /tmp/wc/foo.txt
echo '-- end --'
echo
echo '-- start REPOS/foo.txt --'
svn cat file:///tmp/repos/branches/branch1/foo.txt
echo '-- end --'

