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 (2)

  • Nathan Nobbe says:

    Hi!

    While this is a novel concept and a technique used in svn land I would say the semantics of this script more closely resemble that of git pull than git rebase.

    I assume you modeled it after git since that’s where the rebasing link above refers to.

    I think a better approach would be to simply use git-svn where true rebasing is available on local branches.

    To enhance this script I would suggest first checking to see if the wc needs an svn up prior to the merge. Also, commit the merge before doing any work against the diff resulting in the wc from the merge.

    • scribu says:

      Hi Nathan, thanks for dropping by.

      While I wished it behaved more like git rebase, you’re right; at the end of the day, it’s just a merge.

      Actually, when I wrote this script, I hadn’t even used git yet. Today, I would indeed go with git-svn.

Respond / add a comment


Subscribe without commenting