#!/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/svntest.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



# create basic structure in repos
svn mkdir trunk branches
svn commit -mm

# create a file in trunk
cat > trunk/file <<END
line1
line2
line3
END

svn add trunk/file
svn commit -mm trunk

# create a file in trunk
cat > trunk/file <<END
line1
line2
line3 modified!
END

svn ci -mm

#...

# while in a working copy, we can use '^/' (here making a branch)
svn copy -m "branch one" ^/trunk ^/branches/br1

# if you want a separate checkout of it:
WC_BR1="$BASE/br1"
svn checkout "$URL/branches/br1" "$WC_BR1"
cd "$WC_BR1"
ls

# but technically the branch now also exists in the "big" working copy
cd "$WC"
svn update

#...

# if you need another separate working copy...
WC_TRUNK="$BASE/trunk"
svn checkout "$URL/trunk" "$WC_TRUNK"
cd "$WC_TRUNK"

#...



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

