1

In some cases it's required to perform a post-commit operation only if some condition is met.

E.g. to send an e-mail only when the committed revision affects '/tags' directory. I've searched the web for such script sample to run in Windows environment and wasn't able to find any so I had to write it myself.

bahrep
  • 29,961
  • 12
  • 103
  • 150

2 Answers2

2

The post-commit.bat code:

REM The command checks whether the committed revision changes any data under '/tags'
"%VISUALSVN_SERVER%bin\svnlook.exe" dirs-changed %1 --revision %2 | findstr /b "[Tt]ags"

REM If 'findstr' returns error code 0, it means that the commit involves the '/tags' directory.
REM So if the the returned code is 0 the command runs external batch 'post-commit-run.bat'
If %ERRORLEVEL% EQU 0 call %~dp0post-commit-run.bat %*
bahrep
  • 29,961
  • 12
  • 103
  • 150
  • I have attempted to implement this solution in my own repository, but for some reason it doesn't seem to work. I had to alter it because I am looking to run my script if the commit happens in the "dev" branch, so I changed the "Findstr /b "[Tt]ags"" to "findstr /b "[Dd]ev"" and my script is called post-commit-actions.bat so I also changed the filename in the script accordingly. The script file is saved in the same directory as the hook scripts. – Carl Oct 17 '13 at 13:49
1

I have a post commit Watcher script that will do exactly what you're asking. It's a Perl script, but you can download Perl for Windows from ActiveState or from the Strawberry Perl project.

My post-commit hook is in GitHub. It uses a configuration file to specify the directories to watch. (Actually, each user can set up their own configuration file).

David W.
  • 105,218
  • 39
  • 216
  • 337
  • Any possible caveats with Perl in Windows environment? I strive to use only Windows Batch and PowerShell scripts in Windows environment. Or use compiled executables of custom hook scripts. – bahrep Dec 10 '12 at 12:56
  • 1
    No problem using Perl in a Windows environment. Perl is made to be platform independent. The same goes for Python. Perl (and Python) are much more powerful than Batch scripting. At the same time, Perl and Python are much more popular than PowerShell. It's much easier to find people who know Perl and Python than PowerShell. The big advantage PowerShell has is that it's included in the Windows environment while you have to download and install Perl and Python. – David W. Dec 10 '12 at 13:08