Inspired by a cou­ple of arti­cles and even a screen­cast, I wrote a short batch file that cre­ates a Rails appli­ca­tion and auto­mat­i­cally loads it into a sub­ver­sion repos­i­tory. It works by first cre­at­ing a temp folder, gen­er­at­ing the rails app there, renam­ing the app folder to trunk, cre­at­ing the accom­pa­ny­ing branches and tags folder, and then deleting/renaming a bunch of non-essential files. Once that’s done it imports the three fold­ers into a spec­i­fied sub­ver­sion repos­i­tory. Once the import is com­plete, the temp folder is deleted and then the trunk is checked out. Finally it cleans-up by copy­ing the database.yml file and ignor­ing the tmp and log fold­ers. 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 Win­dows script­ing, I’d be able to pro­vide bet­ter error checking.

Comments are closed.