#!/bin/bash

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

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


shift $((OPTIND-1))

# replace "N=1" with however many non-flag args you require
N=1
if [ -t 0 ] && (( $# != $N )) ; then
    echo >&2 "$me: ERROR: Must provide URL to a greek tree."
    exit 1
fi

URL="$1"

mkdir "$me"

cd "$me"

$SVN co "$URL" 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
)

