Getting log message from svnlook via windows batch

江枫思渺然 提交于 2019-11-29 15:25:57

As you want also the linebreaks, you can add them when concatenating the lines.

@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!

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 the SET assignment to something like SET 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. Read HELP SET for more information.

Something similar to this,

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

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

@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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!