#!/bin/sh

# $Id: svn-example.sh 3416 2007-03-27 19:49:51Z erich $

# Alas, you need Cygwin installed in order for the shell script to run
# on Windows.  But don't install the Cygwin svn, since I don't know if
# that behaves the same as the Win32 version.

PATH=$PATH:/usr/local/src/svn-live/subversion/svn

case "$OSTYPE" in
    cygwin*)
        case "$(type -p svn)" in
            */program\ files/subversion/bin/svn)
            TMP="$(cygpath -m /tmp)"
            ;;
        esac
        ;;
    *)
        TMP=/tmp
        ;;
esac

r="$TMP/repos"
w1="$TMP/wc1"
w2="$TMP/wc2"

u1=file://localhost$TMP/repos
u2=svn+ssh://localhost$TMP/repos

rm -rf $r "$w1" "$w2"  /tmp/hook-log
svnadmin create $r

###

cat > $r/hooks/pre-commit <<EOF
#!/bin/sh
(echo -n "hi, I am a hook: "; date) >> /tmp/hook-log
/bin/false
EOF

chmod +x $r/hooks/pre-commit

###

(set -x
svn co $u1 $w1)

h=hum-de-dum
f1=$w1/$h

echo First set of data > $f1
svn add $f1

echo I expect the commit to fail with a message about the pre-commit hook failing.
svn ci -m "" $w1

(set -x
svn co $u2 $w2)

h=hum-de-dum
f2=$w2/$h

echo Second set of data >> $f2

echo I expect the commit to fail with a message about the pre-commit hook failing.
svn ci -m "" $w2

echo 'I expect to see neither commit in this file:'
cat $f2

echo 'I expect to see two lines that say "I am a hook":'
cat /tmp/hook-log

