Django: Switching between development branches

Cyril and I have been using new forms admin for some stuff we are working on for fun whilst we are here at SXSWi. One of the issues is that if you're developing several different Django sites you won't necessary want to migrate away from trunk to migrate everything to one of the other branches that you're trying out. Obviously at some point in the future work like the new forms admin branch and the queryset refactor branch will be merged back to trunk and you'll want to switch back.

To make life a little easier I knocked up a simple shell script to switch between branches by changing the symlink to site-packages. This assumes you are already using the method which symlinks the svn source into site-packages.

As long as the branches are in the same directory this script will work as it simply creates a selection based on the branches contained withing the directory specifed in the constant "DJANGOBRANCHES". Simply change the constant to meet your needs:

#!/usr/bin/env bash

DJANGOBRANCHES=/Users/muffin/django/
SITEPACKAGES=/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/

cd $DJANGOBRANCHES
echo 'Choose Django branch:'

select dir in *;
do          
    if [ -n "$dir" ] && [ -d ${DJANGOBRANCHES}${dir}/ ]
    then                       
      rm -f ${SITEPACKAGES}django
      ln -s ${DJANGOBRANCHES}${dir}/django ${SITEPACKAGES}django 
      break
    else  
      echo "Error: You choice '$REPLY' does not correspond to a branch"
    fi
done

exit 0

Using the script is simple:

muffin@shiva muffin/django $ switch_django 
Choose Django branch
1) django_src
2) newforms-admin
#? 2

Check the site-packages directory and you should see the correct branch is now sym-linked.