Tuesday winter photo

This is a collection of my Subversion "cheats", right now just the scripts that I use to manage branches containing potentially intrusive changes.

Contents

Branch Management Scripts

I have two scripts for managing branches. The first, called svnbranch, creates a new branch and checks it out. You just run "svnbranch base-url branch-url wc-path" to create a copy (branch) of "base-url" at "branch-url" and check it out into "wc-path". For example, to create a branch of CUPS trunk called "foo" and check it out into a "bar" subdirectory, I'd use:

svnbranch https://svn.easysw.com/public/cups/trunk \
    https://svn.easysw.com/public/cups/branches/foo bar
cd bar
svn ci

As I continue to make changes in trunk, I can merge them into my branch using the second script, svnmerge:

cd bar
svnmerge
svn ci

Once I am done with my development on the branch and want to merge the changes onto trunk, I'll first run svnmerge to update the branch to the latest trunk changes (see above) and then run svnmerge from the trunk working copy, this time passing in the URL of the branch to merge:

cd trunk
svnmerge https://svn.easysw.com/public/cups/branches/foo
svn ci

And here are the scripts!

"svnbranch":

#!/bin/sh
#
# Creates a branch (copy) of the specified WC's branch and checks it out.
#
# Usage:
#
#   svnbranch base-url branch-url wc-path
#

if test $# != 3; then
	echo Usage: svnbranch base-url branch-url wc-path
	exit 1
fi

svn copy "$1" "$2"
svn co "$2" "$3"
cd "$3"
rev=`svnversion . | awk -F: '{print $NF}' | sed -e '1,$s/[a-zA-Z]*//g'`
svn ps merge-baserev $rev .
svn ps merge-revision $rev .
svn ps merge-url "$1" .
"svnmerge":

#!/bin/sh
#
# Merges changes from trunk to branch or visa-versa.
#
# This script uses the following properties to track merges:
#
#     merge-url         The "trunk" URL.
#     merge-revision    The last revision that was merged.
#     merge-baserev     The revision that created the branch.
#
# These properties are 
#
# Usage:
#
#   svnmerge [branch-url]
#

if test $# -gt 1; then
	echo Usage: svnmerge [branch-url]
	exit 1
fi

svn up

if test $# = 1; then
	echo Merging changes from branch...
	baserev=`svn pg merge-baserev $1`
	svn merge -r $baserev:HEAD $1
	# Remove merge-* properties from branch...
	svn revert .
else
	echo Merging changes from trunk...
	rev=`svnversion . | awk -F: '{print $NF}' | sed -e '1,$s/[a-zA-Z]*//g'`
	oldrev=`svn pg merge-revision .`
	trunk=`svn pg merge-url .`
	svn merge -r $oldrev:HEAD $trunk

	svn ps merge-revision $rev .
fi