#!/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 fails with:
# <<< Started new transaction, based on original revision 7
# svnadmin: File not found: transaction '8-8', path 'other/new-name/bar/myfile'
#     * editing path : other/new-name/bar/myfile ...
# Because the revision with the directory renaming is not included

REPOS=/tmp/dummy-svn-repos-${USER}
REPOS2=/tmp/dummy-svn-repos2-${USER}
WC=/tmp/dummy-svn-wc-${USER}
WC2=/tmp/dummy-svn-wc2-${USER}
DUMP=/tmp/dummy-svn-dump-${USER}.svn

set -e

rm -rf ${REPOS} ${REPOS2} ${WC} ${WC2} ${DUMP}
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
svn commit -m 'Renaming'
echo "Test 4" >> other/new-name/bar/myfile
svn commit -m 'Modification of new-name'
svn update # Else, svn log won't work

# The only way to make it work is to filter /other/new-name but then it includes things 
# we don't want (/other/new-name/toto)
svnadmin dump ${REPOS} | \
    svndumpfilter include other/new-name/bar /other/new-name/bar /foo/old-name/bar > ${DUMP}
#svnadmin dump ${REPOS} | \
#    svndumpfilter include other/new-name /other/new-name /foo/old-name > ${DUMP}

svnadmin create ${REPOS2}
svn mkdir -m 'Creating foo/old-name in the new repository' --parents \
    file://${REPOS2}/foo/old-name
svn mkdir -m 'Creating other in the new repository' --parents \
    file://${REPOS2}/other/new-name # Or other/new-name/bar; it changes nothing
svnadmin load ${REPOS2} < ${DUMP}
svn co file://${REPOS2} ${WC2}
echo "${DUMP} loaded into ${REPOS2}, Working copy in ${WC2}"

