#!/bin/sh

# Creates a Subversion repository to test the bug 
# <http://serverfault.com/questions/41481/keeping-a-part-of-a-subversion-repository-but-there-is-a-path-change-in-the-midd>
# This script seems to work.

REPOS=/tmp/dummy-svn-repos-${USER}
REPOS2=/tmp/dummy-svn-repos2-${USER}
WC=/tmp/dummy-svn-wc-${USER}
WC2=/tmp/dummy-svn-wc2-${USER}
DUMP1=/tmp/dummy-svn-dump1-${USER}.svn
DUMP2=/tmp/dummy-svn-dump2-${USER}.svn
FILTER_OPTS="--drop-empty-revs --renumber-revs"

set -e

rm -rf ${REPOS} ${REPOS2} ${WC} ${WC2} ${DUMP1} ${DUMP2}
svnadmin create ${REPOS}
svn co file://${REPOS} ${WC}
cd ${WC}
mkdir -p foo/old-name/bar
echo "Test 1" > foo/old-name/bar/myfile
svn add foo
svn commit -m 'First commit of old-name' 
mkdir -p foo/old-name/toto
echo "Test 2" > foo/old-name/toto/useless
svn add foo/old-name/toto
svn commit -m 'Commit of another dir' 
mkdir -p foo/stuff
echo "Test 3" > foo/stuff/thing
svn add foo/stuff
svn commit -m 'Commit of yet another dir' 
echo "Test 4" >> foo/old-name/bar/myfile
svn commit -m 'Modification of old-name/bar/myfile' 
svn update
mkdir other
svn add other
svn commit -m 'Other top-level dir'
svn rename foo/old-name other/new-name
# This will be r6
svn commit -m 'Renaming'
echo "Test 5" >> other/new-name/bar/myfile
svn commit -m 'Modification of new-name'
echo "Test 6" >> other/new-name/bar/myfile
svn commit -m 'Re-Modification of new-name'
svn update # Else, svn log won't work

# The revision numbers are made to exclude the revision with the renaming
svnadmin dump -r 1:5 ${REPOS} | \
    svndumpfilter ${FILTER_OPTS} include /foo/old-name/bar > ${DUMP1}
svnadmin dump --incremental -r 7:HEAD ${REPOS} | \
    svndumpfilter ${FILTER_OPTS} include /other/new-name/bar > ${DUMP2}

svnadmin create ${REPOS2}
svn mkdir -m 'Creating foo/old-name in the new repository' --parents \
    file://${REPOS2}/foo/old-name
svnadmin load ${REPOS2} < ${DUMP1}
svn mkdir -m 'Creating other in the new repository' --parents \
    file://${REPOS2}/other
svn rename -m 'Renaming in the new repository' \
    file://${REPOS2}/foo/old-name file://${REPOS2}/other/new-name
svn delete -m 'Deleting the empty foo in the new repository' file://${REPOS2}/foo
svnadmin load ${REPOS2} < ${DUMP2}
svn co file://${REPOS2} ${WC2}
echo "${DUMP} loaded into ${REPOS2}, Working copy in ${WC2}"

