#!/bin/bash

me=${0##*/}
here=${0%/*}

flags="hqds:a:"
SVN=svn
Usage () {
    args="$*"
    if [[ -n "$args" ]] ; then
        echo >&2 "$args"
    fi
    echo >&2 "Usage: $me [-$flags] 
Check out a greek trunk, do some stuff with suprising results."
}
while getopts "$flags" flag; do
    case "$flag" in
	s) SVN=$OPTARG ;;
	a) SVNADMIN=$OPTARG ;;
        h) Usage; exit 0;;
	q) quiet=1 ;;
	d) debug=1; set -xv ;;
    esac
done


shift $((OPTIND-1))

rm -fr "$me"
mkdir "$me"

cd "$me"

${SVNADMIN} create repos

echo "### Making a Greek Tree for import..."
mkdir import-me
mkdir import-me/trunk
mkdir import-me/tags
mkdir import-me/branches
mkdir import-me/trunk/A
mkdir import-me/trunk/A/B/
mkdir import-me/trunk/A/C/
mkdir import-me/trunk/A/D/
mkdir import-me/trunk/A/B/E/
mkdir import-me/trunk/A/B/F/
mkdir import-me/trunk/A/D/G/
mkdir import-me/trunk/A/D/H/
echo "This is the file 'iota'."        > import-me/trunk/iota
echo "This is the file 'A/mu'."        > import-me/trunk/A/mu
echo "This is the file 'A/B/lambda'."  > import-me/trunk/A/B/lambda
echo "This is the file 'A/B/E/alpha'." > import-me/trunk/A/B/E/alpha
echo "This is the file 'A/B/E/beta'."  > import-me/trunk/A/B/E/beta
echo "This is the file 'A/D/gamma'."   > import-me/trunk/A/D/gamma
echo "This is the file 'A/D/G/pi'."    > import-me/trunk/A/D/G/pi
echo "This is the file 'A/D/G/rho'."   > import-me/trunk/A/D/G/rho
echo "This is the file 'A/D/G/tau'."   > import-me/trunk/A/D/G/tau
echo "This is the file 'A/D/H/chi'."   > import-me/trunk/A/D/H/chi
echo "This is the file 'A/D/H/omega'." > import-me/trunk/A/D/H/omega
echo "This is the file 'A/D/H/psi'."   > import-me/trunk/A/D/H/psi
echo "### Done."
echo ""
echo "### Importing it..."
(cd import-me; ${SVN} import -q -m "Initial import." ${URL})
echo "### Done."
echo ""

URL=file://`pwd`/repos

$SVN co "$URL"/trunk greek

cd greek/A

################
echo; echo; echo $me: OK: Initial status:
(
set -x
ls -l
$SVN ls -v
$SVN stat
)
echo; echo; echo $me: 'Subversion tool to be used (from $PATH):' `which $SVN`
(
set -x
$SVN --version
)

################
echo; echo; echo $me: OK: Removing and restoring something: seems to work, restores D
(
set -x
rm -fr D
$SVN up
ls -l
$SVN ls -v
$SVN stat
)


################
echo; echo; echo $me: FAIL: Removing, obscuring, and attempting to restore: unworks, no error
echo $me: end up with file-named-D instead of error, or dir-named-D
(set -x
rm -fr D
touch D
$SVN up
ls -l
$SVN ls -v
$SVN stat
)

################
echo; echo; echo $me: FAIL: Clear obstruction, attempt to restore: unworks, no error
echo $me: end up with no '"D"' at all!
(set -x
rm D
$SVN up
ls -l
$SVN ls -v
$SVN stat
)

################
echo; echo; echo $me: FAIL: Force doesn"'"t help, either
(set -x
$SVN up --force
ls -l
$SVN ls -v
$SVN stat
)


################
echo; echo; echo $me: FAIL: Depth doesn"'"t help, either
(set -x
$SVN up --depth infinity
ls -l
$SVN ls -v
$SVN stat
)

