svn branchlist: Print branch names for multiple repos

Display mode

Back to Quick Hacks

I sometimes run into the situation where I'm working on multiple related Subversion repositories, and all their working copies are in a "repository root" on my drive. With these repos being switched to different branches, it became tedious to flip through each one to find which branch they were attached to.

Like any lazy programmer, I automated the process into a Bash script.

svnbr: A script to print the current branch name of multiple Subversion working copies

#!/bin/bash
REPOROOT="/home/inazar/code"
PREFIX="foo-"
POSTFIX="-bar"

t=`mktemp /tmp/svnbr_XXXXX`
pushd . > /dev/null
cd $REPOROOT
for a in `find . -maxdepth 1 -name "$PREFIX*$POSTFIX"`; do
        cd $a
        b=`svn info 2> /dev/null | grep URL | awk -F'/' '{print $NF}'`
        c=${a%$POSTFIX}
        c=${c#$PREFIX}
        c=${c:2}
        d=""

        # Caveat: Display will fall over with repo names past 16 chars
        [[ ${#c} -lt 8 ]] && d="\t"
        echo -e "$c\t$d $b" >> $t
        cd ..
done
popd > /dev/null
sort $t
rm $t