Load WordPress Sites in as fast as 37ms!

Handy Shell Scripts – part IV – svnswitchto.sh

So, you’re developing with SVN and you want to use branches? Creating a branch is easy, but switching between them by manually typing those URLs can be annoying. Use this script :)

SVN Branch Switcher (download file)#!/bin/sh

[ ! -d ".svn" ] && echo Use only inside the main project directory under SVN control && exit
S=` svn info | grep URL: | cut -d " " -f 2 `
echo Currently on $S
#echo $S
#exit;
BSE=` echo $S | sed 's/\/trunk/ /' | sed 's/\/branches/ /' | sed 's/\/tags/ /' | cut -d " " -f 1 `
BASEBRANCHES=$BSE/branches
TARGET=$BASEBRANCHES/$1

[ "$1" == "" ] && TARGET=$BSE/trunk
[ "$TARGET" != "$BSE/trunk" ] && [ "` svn ls $BASEBRANCHES | egrep \"^$1/$\" | wc -l | egrep -o \"[0-9]+\"`" == "0" ] && echo Branch $1 does not exist && exit;

echo Switching to $TARGET

[ "$TARGET" == "$S" ] && echo Nothing to do, already there && exit;

svn switch $TARGET

use it with a branchname as parameter and it will switch to the branch, without a parameter switches back to the trunk.

Enjoy!

Author: Remon Pel

WebDeveloper though not WebDesigner

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.