SVN revision number in DOS/Windows batch file
I don't know if my search terms were crap, but I couldn't find a good way to get a subversion revision number in a batch file. Teh Webs offers up all sorts of convoluted methods involving temp files, svn propfind, and alternate shells or grep-like tools, but really it's more straightforward than that.
DOS prompt:
for /f "tokens=1,2" %g in ('svn info') do @if %g == Revision: echo %h
Batch file:
for /f "tokens=1,2" %%g in ('svn info') do @if %%g == Revision: set REV=%%h
Add quotes around both sides of the string comparison if it makes you feel less yucky to have that Revision: just hanging out naked like that. The magic is in the %h referring to the token after the %g. Google, please archive this for my future reference.
DOS prompt:
for /f "tokens=1,2" %g in ('svn info') do @if %g == Revision: echo %h
Batch file:
for /f "tokens=1,2" %%g in ('svn info') do @if %%g == Revision: set REV=%%h
Add quotes around both sides of the string comparison if it makes you feel less yucky to have that Revision: just hanging out naked like that. The magic is in the %h referring to the token after the %g. Google, please archive this for my future reference.

2 Comments:
hey! it's your yearly post!
Sorry man, just ruined my streak for the year and made another post..
Post a Comment
<< Home