#!/usr/bin/env bash

## TO MAKE THIS RUN YOUR CUSTOM COMPILED SVN, two simple options:
## 1. Adjust your PATH to point at your custom installed location:
##      export PATH="$HOME/prefix/svn_trunk/bin:$PATH"
## OR
## 2. Uncomment the four lines below to use aliases into your
##    built source tree. The next line is the only line you should
##    need to adjust.
# SVNDIR=/path/to/built_subversion_source_tree
# function svn() { "$SVNDIR/subversion/svn/svn" "$@"; }
# function svnserve() { "$SVNDIR/subversion/svnserve/svnserve" "$@"; }
# function svnadmin() { "$SVNDIR/subversion/svnadmin/svnadmin" "$@"; }

set -e

svn --version
BASE="$(mktemp -d "/tmp/$(basename "$0").XXX")"
echo "BASE = $BASE"
REPOS="$BASE/repos"
WC="$BASE/wc"
URL="file://$REPOS"
svnadmin create "$REPOS"

# enable all revprop changes
cat > "$REPOS/hooks/pre-revprop-change" <<EOF
#!/usr/bin/env sh
exit 0
EOF
chmod a+x "$REPOS/hooks/pre-revprop-change"

svn co -q "$URL" "$WC"

set +e
set -x
cd "$WC"

## ACTUAL TEST

svn mkdir -m1 ^/a
svn cp -m2 ^/a ^/b
svn up

echo a > a/foo
svn add a/foo
svn ci -m3

echo b > b/foo
svn add b/foo
svn ci -m4

cd b
# Intending to merge from ^/a, knowing that ^/a/foo has been added,
# wanting to replace ./foo with ^/a/foo. Choosing to delete ./foo.
svn up
svn delete foo
svn ci -m5

# !!! forgetting to update !!!

# doing the intended merge to bring in ^/a/foo
svn merge ^/a
# commit complains about out-of-dateness, nothing an update can't fix:
svn up
# what, a tree conflict?
# local edit, incoming add? But it was deleted here!
# This is where the shirt starts hitting the farn. Just to illustrate...

svn resolved foo
cat foo
svn ci -m6

cat foo
svn cat ^/b/foo
set +x
echo "
NOTE:         cat foo shows 'a'
      svn cat ^/b/foo shows 'b'
  They differ though status and info indicate up-to-date-ness:
"
set -x
svn st -v
svn info ./foo
svn info ^/b/foo


## END
set +x
echo "BASE = $BASE"

