I'm running Subvbersion through VisualSVN Server on a Windows server and have my repository set up with a trunk and three branches. The branches are dev, test and prod. I have a post commit hook that I want to run which updates a working copy after a commit is run, but I only want it to update that working copy if the commit was made in the dev branch.
This is the code I have right now...
@setlocal enableextensions enabledelayedexpansion
@echo off
SET str1=%1
IF NOT x%str1:dev=%==x%str1% (
pushd <path to working copy>
svn update --username <svn_username> --password <svn_password>
echo update complete
)
endlocal
If I take out the conditional, the update runs on every commit, so I know the code inside the conditional works. I have also tested the conditional as a regular batch file, sending it strings like "branches/dev" and "branches/test" and it behaved properly in those tests. However, when I save this as my post-commit hook script, it never runs, whether the commit is in the dev branch or otherwise.
EDIT: Based on feedback that this question was already answered, I tried the approach recommended in the other question, but that approach is not working either. Here is my version of the code suggested there:
REM The command checks whether the committed revision changes any data under '/dev'
"%VISUALSVN_SERVER%bin\svnlook.exe" dirs-changed %1 --revision %2 | findstr /b "[Dd]ev"
REM If 'findstr' returns error code 0, it means that the commit involves the '/dev' directory.
REM So if the the returned code is 0 the command runs external batch 'post-commit-actions.bat'
If %ERRORLEVEL% EQU 0 call %~dp0post-commit-actions.bat %*
In order for this to work, I have created a file in the hooks directory called post-commit-actions.bat to execute the svn update. However, this is not running post-commit. If I'm leaving out any pertinent information, please let me know.
EDIT: Thanks for everyone's help. With the input here, I was able to piece together a working solution. For those looking for an answer to a similar problem, it worked like this:
svnlook dirs-changed %1 -r %2 | findstr /b /i "branches/dev"
IF %ERRORLEVEL% EQU 0 (
pushd <path-to-working-copy>
svn update --username <repo-username> --password <repo-password>
)
Just so it's posted, here was the solution to the problem. This code-set worked for the purpose intended:
svnlook dirs-changed %1 -r %2 | findstr /b /i "branches/dev"
IF %ERRORLEVEL% EQU 0 (
pushd <path-to-working-copy>
svn update --username <repo-username> --password <repo-password>
)
Thanks for all of the help in deriving this solution