#!/bin/sh

# Cherrypicking mergeinfo failure test
# This script demonstrates an error in the recorded mergeinfo several steps after cherrypicking a change from branch->trunk

# January 20, 2010
# rick@sb.org

# The next line is the only line you should need to adjust.
SVNDIR=/usr/bin

SVN=${SVNDIR}/svn
SVNSERVE=${SVNDIR}/svnserve
SVNADMIN=${SVNDIR}/svnadmin

URL=file://`pwd`/repos

rm -rf repos trunk-wc branch1-wc branch2-wc branch3-wc

${SVNADMIN} create repos
${SVN} mkdir ${URL}/trunk ${URL}/branches -m "structure"
${SVN} co ${URL}/trunk trunk-wc

${SVN} mkdir trunk-wc/subtree
echo "This is the file 'file.txt'."        > trunk-wc/subtree/file.txt
${SVN} add trunk-wc/subtree/file.txt
${SVN} ci trunk-wc -m "file added"

${SVN} cp ${URL}/trunk ${URL}/branches/branch1 -m "branch1 created"
${SVN} co ${URL}/branches/branch1 branch1-wc

echo "Modified file in branch1."        >> branch1-wc/subtree/file.txt
${SVN} ci branch1-wc -m "file modified in branch1"

${SVN} up trunk-wc

# Update this revision number if you change the above
${SVN} merge -c4 ${URL}/branches/branch1/subtree trunk-wc/subtree
${SVN} ci trunk-wc -m "Merge subtree change to trunk."
${SVN} up trunk-wc

${SVN} cp ${URL}/trunk ${URL}/branches/branch2 -m "branch2 created"
${SVN} cp ${URL}/trunk ${URL}/branches/branch3 -m "branch3 created"
${SVN} co ${URL}/branches/branch2 branch2-wc
${SVN} co ${URL}/branches/branch3 branch3-wc

echo "Modified in branch2."        >> branch2-wc/subtree/file.txt
${SVN} ci branch2-wc -m "file modified in branch2"

${SVN} up trunk-wc
${SVN} merge --reintegrate ${URL}/branches/branch2 trunk-wc
${SVN} ci trunk-wc -m "Land branch2."

echo "###"
echo "### Mergeinfo on branch3 pre-merge:"
echo "###"
${SVN} pl -vR branch3-wc
echo "###"

${SVN} merge ${URL}/trunk branch3-wc
${SVN} ci branch3-wc  -m "Merge from trunk."

echo "###"
echo "### Mergeinfo on branch3 subtree was not set correctly by merge: Should include trunk revisions just merged."
echo "###"
${SVN} pl -vR branch3-wc
echo "###"
echo "### This will cause the next command (a reintegrate) to fail."
echo "###"

${SVN} up trunk-wc
${SVN} merge --reintegrate ${URL}/branches/branch3 trunk-wc

