Nov 11, 2009

SVN Automated Local Update

Summary

This short tutorial will get SVN to automatically grab any changes to a SVN repository for you at designated times. I use this so that each morning, I have a "what was changed" report, without the monotonous select all folders and ask for an update. You will need TortoiseSVN installed, and running Windows for this script to run correctly.

The Tutorial

Start by copying this base script into TextPad (or your text editor of choice):
@echo off

cls
echo == Initiating system instance variables...
echo. -- Setting the variables...

:: Here you need to make some changes to suit your system.
set SOURCE=CHANGEME!
set SVN=C:\Program Files\TortoiseSVN\bin

:: Unless you want to modify the script, this is enough.

echo. %SOURCE%
echo. %SVN%
echo. ++ Done setting variables.
echo.
echo == Updating source from SVN
echo. -- Running update...
"%SVN%\TortoiseProc.exe" /command:update /path:"%SOURCE%"
echo. ++ Done.

echo. -- Cleaning up...
set SOURCE=
set SVN=
echo. ++ Done.
Edit the SOURCE's CHANGEME to a directory that you could normally right-click and select "SVN Update". This address can be grabbed with a quick copy paste of the address bar when you have navigated to that folder in Windows Explorer. Such an entry should appear as so:
set SOURCE=E:\My Files\My Work\SuperSecretProject
Save that script as "SVNUpdateMyFilesPlease.bat". Next step is to get that file to run at proper intervals of time. Navigate to: Start -> Settings -> Control Panel -> Scheduled Task -> Add Scheduled Task.

In the wizard, hit next, then browse for your bat file you just made (you did test it to be sure it works, right?). From there, I trust that you can figure out the rest of the wizard.

If you have multiple projects, you need to make multiple bat files and multiple schedules, right? Wrong. All on one line, keep adding each project behind the last with a "*" between each.
set SOURCE=E:\My Files\My Work\SuperSecretProject*E:\My Files\My Work\KindaSecretProject*E:\My Files\My Work\ProjectIKeepForJobSecuirty*E:\My Files\My Work\ProjectThatWillHelpMeRuleTheWorld*E:\My Files\My Work\MuhahahahahahahaProject
The ["%SVN%\TortoiseProc.exe" /command:update /path:"%SOURCE%"] line can edited to do many things, such as close the update window when there were no errors, conflicts or merges.
%SVN%\TortoiseProc.exe" /command:update /path:"%SOURCE%" /closeonend:3
A list of what each closeonend:# does can be found here.

Credit Where Credit is Due

The script that makes this possible was written by varl from stackoverflow.com. The multiple files in one line for windows command line was learned from this random "U B" fellow.

No comments: