Tuesday, October 16, 2007

Version control unmaddened

PostgreSQL is the only project I'm involved in that uses CVS. Most other places now use Subversion, Bazaar, or something else. That's fine, but it's really annoying to continously type in the wrong tool when you switch back and forth.

So today I fixed this problem. I wrote this little shell script I call vcs:


#!/bin/sh

if [ -d CVS ]; then
cvs "$@"
exit $?
fi

if [ -d .svn ]; then
svn "$@"
exit $?
fi

dir=$(pwd)

while [ -n "$dir" ] && [ "$dir" != / ]; do
if [ -d "$dir/.bzr" ]; then
bzr "$@"
exit $?
fi

dir=$(dirname "$dir")
done

exit 77

This can be extended in obvious ways.

Put this in your path, and then you can use vcs for everything.

But somehow, cvs is really easy to type, or maybe your fingers are wired to svn or something else. So add to this a couple of shell functions like this:



bzr() { vcs "$@" || { [ $? -eq 77 ] && command bzr "$@"; }; }
cvs() { vcs "$@" || { [ $? -eq 77 ] && command cvs "$@"; }; }
svn() { vcs "$@" || { [ $? -eq 77 ] && command svn "$@"; }; }

Now you can type cvs update or whatever your brain or fingers prefer and it will do the right thing.