batch
Archived Posts from this Category
Archived Posts from this Category
The svn command has an info parameter with which you can obtain some info about the current directory, like this:
C:\Projects\myproject\branches\DEV_V0001.00>svn info --revision HEAD Path: DEV_V0001.00 URL: http://svn.mycompany:10080/svn/myproject/branches/DEV_V0001.00 Repository Root: http://svn.mycompany:10080/svn/myproject Repository UUID: 495b61df-840d-0410-9b36-f3cf8ec0f97e Revision: 8251 Node Kind: directory Last Changed Author: mahieuguy Last Changed Rev: 8211 Last Changed Date: 2008-06-05 13:05:22 +0200 (do, 05 jun 2008)
I could not find a command that would just return the revision number, which we needed in our build script. On linux systems it would be trivial to extract just the rev number from the output of the ‘info’ command, so I hoped it would also be possible in dos/windows without installing extra tools. It turned out to be possible, but much less elegant than I suspected:
@echo off
FOR /F "tokens=2 skip=4" %%G IN ('svn info --revision HEAD') DO ^
IF NOT DEFINED REVISION SET REVISION=%%G
echo %REVISION%
Note that the ^ character is just there to split the command into two lines, this works for XP batch scripts, but I’m not sure about other versions of cmd.exe
The HEAD revision number is put in the %REVISION% parameter. Make sure you don’t already have a REVISION parameter defined before executing the command in the batch file though, because it will only be set if it is not already defined. This was needed to be able to get the FOR command to ignore all lines after the ‘Revision: 8251′ line from the ’svn info’ result.
2 comments Monday 09 Jun 2008 | Guy Mahieu | batch(t) , svn(t) , windows(t)