Receiving a log message from svnlook through a Windows package

I am trying to prepare a post-commit hook for my svn repository. So I need a log message from the last commit that I get with the command svnlook log -r %REV% %REPOS%. Filling a fragment with appropriate parameters I get the following multline log message:

This
is
my
transaction.

It works well. Now I put this in a .bat file:

@ECHO OFF

REM just for testing purpose...
SET REPOS=C:\repo
SET REV=40

FOR /F %%i in ('svnlook log -r %REV% %REPOS%') do SET VAR=%%i

ECHO %VAR%

When I execute the script, only the last line is output transaction.. For-loop is a snippet from which I thought it would read svnlook's output %var%.

My approach is to get the log message in a variable that I pass to another exe file as a parameter. But that will not work. I do not know how to use the loop correctly.

exe .

script (@ PA.)

@ECHO OFF
setlocal enabledelayedexpansion

SET REPOS=C:\repo
SET REV=40

SET MSG=
FOR /F %%i in ('svnlook log -r %REV% %REPOS%') do SET VAR=!VAR! %%i
ECHO !VAR!

This is my transaction. , .

+3
3

, , .

@ECHO OFF
setlocal enabledelayedexpansion
set LF=^


rem ** The two empty lines are NECESSARY

SET REPOS=C:\Users\CH.ROSESOFT\Downloads\t3\repo
SET REV=40

SET MSG=
FOR /F %%i in ('svnlook log -r %REV% %REPOS%') do (
    SET "VAR=!VAR!!LF!%%i"
    SET "PAR=!PAR!^^!LF!!LF!%%i"
)
ECHO !VAR!
myProgram.exe !par!
+1

, svnlook (- VAR = VAR %% i)

BAT , , %. , . SET X=%A%. SET Y=%A%%B%. SET - SET VAR=%VAR% %%i.

. FOR, . Delayed Expansion. HELP SET.

- ,

@ECHO OFF
setlocal enabledelayedexpansion
...
SET VAR=
FOR /F %%i in ('solook log -r %REV% %REPOS%') do SET VAR=!VAR! %%i
ECHO !VAR!
+1

without delimiters, some words will be missing

here is my pre-commit script that i just finished writing

if you set debug to 1, it will fail all the time and you will see messages with some var output

@echo off

set DEBUG=0

:::::::::::::::::::::::::: Dont touch this part :::::::::::::
setlocal enabledelayedexpansion
set space= 
set LF=^


rem ** The two empty lines are NECESSARY
:::::::::::::::::::::::::: Dont touch above     :::::::::::::

set REPOS=%1
set TXN=%2   

::: Get the author ::::::::::::::::::::::::::::::::::
set author=
For /F %%I in ('svnlook author %REPOS% -t %TXN%') Do Set author=!author!%%I

::: Get the message ::::::::::::::::::::::::::::::::::
set message=
For /F "delims=" %%I in ('svnlook log %1 -t %2') Do Set message=!message!%%I%space%


 :: Make sure that author is not blank or guest - if readonly accounts are enabled and something goes wrong
  echo %author% | FindStr [a-zA-Z0-9] >nul
  IF %ERRORLEVEL% NEQ 0 GOTO AUTHOR_NOT_OK

  echo %author% | FindStr \C:guest >nul
  IF %ERRORLEVEL% EQU 0 GOTO AUTHOR_NOT_OK
  :: %ERRORLEVEL% = 1 at this point means its no error!

  :: Make sure that the log message contains some text.
  echo "%message%" | FindStr [a-zA-Z0-9] >nul
  IF %ERRORLEVEL% NEQ 0 GOTO COMMENT_NOT_OK

  :: Make sure that the log message contains ACR
  echo "%message%" | FindStr /I /C:acr >nul
  IF %ERRORLEVEL% NEQ 0 GOTO COMMENT_NOT_OK

  GOTO OK

:COMMENT_NOT_OK
  echo COMMENT_NOT_OK 1>&2
  echo "D:\SYSAPPS\HATS\ci\repositories\repo\java\hooks\pre-commit.bat 1>&2
  echo Your commit has been blocked because you didn't provide adequate log message 1>&2
  echo Please write a log message describing the purpose of your changes and 1>&2
  echo then try committing again. -- Thank you 1>&2
  echo e.g. 1>&2
  echo ACR: 12345 1>&2
  echo fixed blah blah blah 1>&2
  if %DEBUG% EQU 1 GOTO EXITDEBUG

  exit 1

:AUTHOR_NOT_OK
  echo AUTHOR_NOT_OK 1>&2

:OK
  if %DEBUG% EQU 1 GOTO EXITDEBUG
  exit 0

:EXITDEBUG

  echo == EXITDEBUG == 1>&2
  echo ---- %AUTHOR% %message% ----  1>&2
  echo txn %TXN% repos %REPOS% 1>&2
  echo  changedpath  1>&2
  svnlook changed %REPOS% -t %TXN% 1>&2
  echo ERRORLEVEL %ERRORLEVEL% 1>&2
  echo "D:\SYSAPPS\HATS\ci\repositories\repo\java\hooks\pre-commit.bat" 1>&2
  exit 1
0
source

All Articles