Rebasing with svn

So I’ve been accepted as a GSoC student for WordPress. My project involves working on the core WordPress code, but on a separate svn repository. I needed an easy way to keep my fork synchronized with trunk.

Unfortunately, svn doesn’t have the concept of rebasing, so I wrote a little bash script to simulate it:

#!/bin/bash

# usage:
# svnrebase [WORKING_COPY_PATH]

# set working copy path
WCPATH=${1-'.'}

cd $WCPATH

# read base URL
BASE_URL=`cat BASE_URL`
if [ "" == "$BASE_URL" ]; then
	echo "can't find base URL"
	exit
fi

# read current base revision
OLD_BASE_REV=`cat BASE_REV`
if [ "" == "$OLD_BASE_REV" ]; then
	echo "can't find current base revision"
	exit
fi

# fetch latest base revision
NEW_BASE_REV=`svn info $BASE_URL | grep 'Revision:' | cut -d ' ' -f 2`
if [ "" == "$NEW_BASE_REV" ]; then
	echo "can't find base"
	exit
fi

if [ "$OLD_BASE_REV" == "$NEW_BASE_REV" ]; then
	echo 'base already at latest revision'
	exit
fi

# apply changes to fork
svn merge $BASE_URL@$OLD_BASE_REV $BASE_URL@$NEW_BASE_REV

# update current base revision
echo $NEW_BASE_REV > BASE_REV

echo "updated base to revision $NEW_BASE_REV"

The above script requires two text files placed in your working copy directory:

BASE_URL – the url of the base repository. In my case, it contains:

http://core.svn.wordpress.org/trunk

BASE_REV – the currently used revision number in your working copy. For example:

14995

The BASE_REV file will be updated automatically when you run the script, but you need to create it manually the first time.

comments powered by Disqus