Question

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>) 
)
Was it helpful?

Solution

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 :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top