zhongshu
zhongshu

Reputation: 7878

How to get entire svn commit message in window bat?

I need get the SVN commit message in post-commit hook bat in Windows, so I do this:

FOR /F "tokens=*" %%a in ('"svnlook log %1 -r %2"') do @SET MSG=%%a

I test it, it's ok for most case.

but, when I input multiple lines in SVN commit message, the command can only get the last line of commit message, I think it's caused by the windows batch file limit.

How to get the entire commit message to bat variable?

Upvotes: 2

Views: 1580

Answers (2)

mousio
mousio

Reputation: 10337

Depending on the type or format of the commit messages, it might be preferable to keep the newlines as well; this can be accomplished using this:

set newline=^


setlocal ENABLEDELAYEDEXPANSION

Note that the empty lines are required for the newline, and so is ENABLEDELAYEDEXPANSION (once, anywhere before using !newline!).

Now you can use this to concatenate the messages (skipping empty lines, btw) with a newline, and then trimming the first newline:

FOR /F "tokens=*" %%a in ('"svnlook log %1 -r %2"') do @SET MSG=!MSG!!newline!%%a
@SET MSG=!MSG:~1!

Upvotes: 2

Patrick Cuff
Patrick Cuff

Reputation: 29786

FOR /F operates over the lines in the input. Try Changing @SET MSG=%%a to @SET MSG=!MSG! %%a.

Upvotes: 1

Related Questions