Inspired by a couple of articles and even a screencast, I wrote a short batch file that creates a Rails application and automatically loads it into a subversion repository. It works by first creating a temp folder, generating the rails app there, renaming the app folder to trunk, creating the accompanying branches and tags folder, and then deleting/renaming a bunch of non-essential files. Once that’s done it imports the three folders into a specified subversion repository. Once the import is complete, the temp folder is deleted and then the trunk is checked out. Finally it cleans-up by copying the database.yml file and ignoring the tmp and log folders. That’s it.

@echo off

if "%1"=="" goto :NOAPPNAME
if "%2"=="" goto :NOUSERNAME
if "%3"=="" goto :NOSVNREPO

mkdir svntemp
cd svntemp
mkdir branches
mkdir tags
call rails %1
mv %1 trunk
cd trunk
mv config/database.yml config/database_example.yml
rm -r log/*
rm -r tmp/*
cd ..
call svn import --username %2 . %3 -m "initial import"
cd ..
rm -r svntemp
call svn co %3/trunk %1
cd %1
cp config/database_example.yml config/database.yml
call svn propset svn:ignore database.yml config/
call svn propset svn:ignore "*" log/
call svn propset svn:ignore "*" tmp/
svn commit -m "ignoring files"

goto :END

:NOAPPNAME
echo "ERROR: No application name provided."
goto :END

:NOSVNREPO
echo "ERROR: No subversion repository provided. svn://path/to/repo"
goto :END

:NOUSERNAME
echo "ERROR: No username provided."
goto :END

:END

It’s not bad for a first pass. It’d be good to have a shell script that does the same thing and it shouldn’t be too hard to port. If I were to rewrite it using Windows scripting, I’d be able to provide better error checking.

Leave a Reply