I try to prepare a post-commit hook for my svn repository. Therefore i need the log message from the last commit which I get with the command svnlook log -r %REV% %REPOS%
. Filling the snippet with the appropriate params I get the following multline log message:
This
is
my
transaction.
This works well so far. 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 transaction.
is echoed. The for-loop is a snippet from which I thought, it would read the svnlook output into %var%
.
My approach is to get the log message in a variable, which I pass to another exe-file as parameter. But it won't work. I don't know how to properly use the loop.
The log message should given to another exe-file as an parameter.
I modified the script to the following (@thx 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!
The output is now This is my transaction.
But the linebreak are gone but I need the for further processing.
As you want also the linebreaks, you can add them when concatenating the lines.
If I understand your question correctly, you need to concatenate the output of the svnlook command into a single variable (something like VAR = VAR & %%i)
In BAT you access the contents of a variable by writing the variable wrapped with
%
signs. And you concatenate by just sticking them together.SET X=%A%
.SET Y=%A%%B%
. So in your case you should change theSET
assignment to something likeSET VAR=%VAR% %%i
.However, this would not work. As the assignment is inside a
FOR
loop, it needs to be reevaluated every iteration. You need to Enable Delayed Expansion. ReadHELP SET
for more information.Something similar to this,
without delims, some words will be missing
here is my pre-commit script, that i just finished writing
if you set debug to 1, it will start failing all the time, and you ll get to see messages with some var output