1

I've been working on a post-commit hook for my Subversion repository which will update a particular working copy on my live server when other working copies are committed. I have it working when I run the update command on the entire working copy, but not when I want to do it for the particular files which have changed. I am running VisualSVN Server on a Windows 2008 server and the hook is running from a .cmd file.

Any help is greatly appreciated. Here is the code I am using:

@ECHO OFF
svnlook dirs-changed %1 -r %2 | findstr /b /i "trunk"

IF %ERRORLEVEL% EQU 0 (
    pushd <path_to_working_copy>
    SET CHANGES=svnlook changed %1 -r %2
    FOR /F "tokens=2" %%a IN ('%CHANGES%') DO (svn update %%a --username <username> --password <password>)
)

I believe there is a problem with the FOR loop, but I can't tell what it is. This is the code that was working to update the entire working copy. This solution isn't really workable, though, as it takes to long to run the update on every commit:

@ECHO OFF
svnlook dirs-changed %1 -r %2 | findstr /b /i "trunk"

IF %ERRORLEVEL% EQU 0 (
    pushd <path_to_working_copy>
    svn update --username <username> --password <password>
)

EDIT: I've made a few minor chnages to the code above, based on what I'm reading about FOR loops in CMD, but it still isn't working. I don't get any errors, but the update does not execute.

EDIT: I have found a solution to the problem which runs perfectly well as a .bat file or as a CMD file, but it still doesn't update from post-commit.cmd. It doesn't return any errors, it just doesn't run the update:

@ECHO OFF
svnlook dirs-changed %1 -r %2 | findstr /b /i "trunk"

IF %ERRORLEVEL% EQU 0 (
    FOR /F "tokens=2" %%a IN ('svnlook changed %1 -r %2') DO (SET NEWA=%%a & SET NEWB=%NEWA:trunk/=% & svn update <path_to_working_copy>\%NEWB% --username <username>--password <password>) 
)
npocmaka
  • 55,367
  • 18
  • 148
  • 187
Carl
  • 1,246
  • 3
  • 21
  • 39
  • what is the output of `svnlook changed %1 -r %2` ? – npocmaka Oct 21 '13 at 15:17
  • U trunk\scriptcontent\test.cfm – Carl Oct 21 '13 at 16:13
  • It would appear now that the branch/trunk name being included is the problem - I have to figure out how to parse that out of the string – Carl Oct 21 '13 at 16:14
  • As i'm not experienced with subversion (but experienced with batch :-) ) could you tell me what you want to convert `U trunk\scriptcontent\test.cfm` ...I saw already that you managed to get only the path.But what you want to do whit it? – npocmaka Oct 21 '13 at 18:07
  • Thanks, I just updated the issue. I found a way to get the string to what I need it to be (scriptcontent\test.cfm) but now it's just not running the update. I've tested in .bat and .cmd from the command line and I know the post-commit is firing, it just doesn't give me any feedback – Carl Oct 21 '13 at 18:13
  • you need `setlocal enabledDelayedExpansion` here.I'll post an answer to be more clear – npocmaka Oct 21 '13 at 18:21

1 Answers1

3

try with this:

@ECHO OFF

setlocal enableDelayedExpansion
svnlook dirs-changed %1 -r %2 | findstr /b /i "trunk"    
IF ERRORLEVEL 1 (
    FOR /F "tokens=2" %%a IN ('svnlook changed %1 -r %2') DO (
    SET NEWA=%%a 
    SET "NEWB=!NEWA:trunk/=!"
    svn update <path_to_working_copy>\!NEWB! --username <username>--password <password>) 
)
endlocal

this is one of the first and most confusing issues that batch scripters face at the beginning of their "career" . Here's more info :-)

npocmaka
  • 55,367
  • 18
  • 148
  • 187