Monday, May 24, 2010
How to: Setup new Subversion Repository using a batch file
For those who use Subversion source control know that setting up a new repository can be tedious specially when you have to do it couple times a week or month.
I found myself doing it quite often and realized that I should automate this somehow, so here’s how I did it using simple a batch file.
To be able to have a custom name of the repository I wanted the batch file to prompt me in the first step,here’s how you do it
@echo off
set /p name=Type the name of repository
With the echo off here’s how the command prompt looks like.
When you type the name of the repo and hit Enter, subversion sets up some folders and files that it needs to operate.
In the conf folder it stores users credentials and permissions to check into this repository. You dont want to create them everyday specially for a small team, in my case I had to copy them from another repository that I have previously configured, so in the batch file I did this
copy d:\svn_repository\old.project\conf\authz d:\svn_repository\%name%\conf\authz
copy d:\svn_repository\old.project\conf\passwd d:\svn_repository\%name%\conf\passwd
%name% is the variable that holds the name of my repository.
Similarly in the hooks folder subversion stores different automated actions like pre-commit, post-commit, pre-lock and so on, in my case I wanted a demo server to update itself after every check-in to its repository, so in this case I could use post-commit hook that had this command.
"C:\Program Files\CollabNet Subversion Server\svn.exe" update "D:\demo_server\demo_project"
Following line creates the hook with the svn update command.
echo "C:\Program Files\CollabNet Subversion Server\svn.exe" update "D:\demo_server\%name%" >;> d:\svn_repository\%name%\hooks\post-commit.bat
Then I wanted to setup my demo_server, I had to create the folder with the name of my repository along with branches, tags and trunk folders. Here’s the complete snippet or you can view it here create_svn_repository.bat
@echo off
set /p name=Type the name of repository
d:
cd d:\svn_repository\
svnadmin create %name%
copy d:\svn_repository\old.project\conf\authz d:\svn_repository\%name%\conf\authz
copy d:\svn_repository\old.project\conf\passwd d:\svn_repository\%name%\conf\passwd
echo "C:\Program Files\CollabNet Subversion Server\svn.exe" update "D:\demo_server\%name%" >;> d:\svn_repository\%name%\hooks\post-commit.bat
cd d:\demo_server
md %name%
md %name%\branches
md %name%\tags
md %name%\trunk
set /p done=Type 'exit' to quit
Hope it helps someone out there, let me know in the comments.
Labels: automation, batches, subversion, svn