Selectively running SVN hook commands in Windows

Posted by Dan on May 15, 2008 @ 3:23 PM

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 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%" >
if errorlevel 1 goto notfound
    svn update %WORKING_COPY%
goto end
ECHO No updates to the "%FOLDER_PATH%" folder detected
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.

Categories: Source Code


  • Wouldn't this trigger improperly if %FOLDER_PATH% was mentioned in the log message? "svn log -v" will print more than just the changed files. Since this is a commit script, you have local access, so you could run "svnlook changed %WORKING_COPY% -r %REV%" or "svnlook changed %SVN_REPOS% -t %TXN%" if you wanted to run this as a pre-commit or post-commit script.
  • @Jake:

    Yes, if your path occurred in the log message, but in my case if I'm referencing the path in my log message, I'd want the working copy updated anyway--because if I've mentioned the path, it's probably because something has changed.

    You can customize the script however you want. I'm not overly concerned if a corner case would happen to try to update the working copy even if nothing actually changed.
  • Gotcha. I am considering using something like this for actions that only trigger on the folder path (sending emails, changing a website, etc), so I mentally transferred my task over yours.

Comments for this entry have been disabled.