#! /bin/sh

### This must be an absolute path.
#datadir="/tmp/svn_external2local"
datadir="`pwd`"

if [ -z "$SVN" ]; then
  SVN=`which svn`
  SVNADMIN=`which svnadmin`
fi

# Make sure we don't use $HOME/.subversion/.
SVN="${SVN} --config-dir=`pwd`/svn-repro-config-dir"
SVNADMIN="${SVNADMIN} --config-dir=`pwd`/svn-repro-config-dir"

# Use English output.
LC_ALL=C; export LC_ALL

if [ -e "$datadir/repo1" ]; then rm -rf "$datadir/repo1"; fi
if [ -e "$datadir/repo2" ]; then rm -rf "$datadir/repo2"; fi
if [ -e "$datadir/wc1" ]; then rm -rf "$datadir/wc1"; fi
if [ -e "$datadir/wc2" ]; then rm -rf "$datadir/wc2"; fi
mkdir -p "$datadir"

set -x
${SVN} --version --quiet
${SVNADMIN} create "$datadir/repo1"
${SVNADMIN} create "$datadir/repo2"
cd "$datadir"
${SVN} co "file://$datadir/repo1" wc1
cd wc1
${SVN} mkdir dir1
touch file1
touch dir1/file2
${SVN} add file1 dir1/file2
${SVN} ci -m "initial data repo1"
cd ..
rm -rf wc1
${SVN} co "file://$datadir/repo2" wc2
cd wc2
${SVN} mkdir dir2
touch file3
touch dir2/file4
${SVN} add file3 dir2/file4
${SVN} ci -m "initial data repo2"
${SVN} ps svn:externals "file://$datadir/repo1 dir3" .
${SVN} up
${SVN} ci -m "added external definition"
${SVN} up
${SVN} pd svn:externals .
${SVN} up
${SVN} export "file://$datadir/repo1" dir3
${SVN} add dir3
${SVN} ci -m "dir3 from external to local"
${SVN} up
${SVN} up -r2
${SVN} st -u
${SVN} cleanup
${SVN} st -u
${SVN} st
rm -rf dir3
${SVN} up
