Selectively running SVN hook commands in Windows
I was working on another SVN hook today and only wanted to run some code if a particular folder was modified, just to save some processing time from unnecessarily running an SVN update process. Here's the little snippet I came up with to run in my post-commit.bat file:
SET REV=%2
SET WORKING_COPY=C:\local\working\copy\path
SET FOLDER_PATH=/path/as/seen/in/SVN/log/output
REM Check to see if a file in our specified folder was edited
svn log %WORKING_COPY% -v -r "%REV%" | find /i "%FOLDER_PATH%" > nul
if errorlevel 1 goto notfound
svn update %WORKING_COPY%
goto end
:notfound
ECHO No updates to the "%FOLDER_PATH%" folder detected
:end
ECHO Finished
The idea behind this is simple. We check the log for the revision that was just checked in to see if it contains a specific string—which in this case is a folder path. If the log does contain the string, we update our local copy. If it doesn't exist, we skip that step and just output a message that says no updates found.
Make sure to check out my other posts on using SVN hooks in Windows for more tips and tricks.
