tags:

views:

631

answers:

6

I am trying to get the revision number of a project and save it into a variable. I know I can get the revision number by svnversion command but I'm not sure how I can store it. I am using regular windows command prompt. Basically I'm trying to do something like : set svnVersion= %svnversion% but I'm not sure how??

+1  A: 

The "svn info" subcommand will tell you the revision number in your working copy.

Ken Liu
A: 

See if this help: Change Revision Number

Jedi Master Spooky
+2  A: 

To set the output of variable to the output of svnversion in a batch file, you have to do this:

for /f "delims=" %%a in ('svnversion') do @set myvar=%%a

echo %myvar%


Different approach: If you have TortoiseSVN you can also use SubWCRev.exe. See get the project revision number into my project? or Automatic SVN Revision Numbering in ASP.Net MVC

f3lix
In a batch file you'd have to double the % signs for the 'for' variable.
Joey
you're right. thanks. edited the answer.
f3lix
actually I think single % is the right choice. At least that's how it works on my system
+1  A: 

in Bash (via Cigwin):

$ svn info | grep -i "Revision" | cut -d ' ' -f 2

You can then use that in a shell script to store the value in a variable.

BryanH
I'm not sure most people run bash as their "regular windows command prompt" ;-)
Steven Robbins
You're correct, so I added -> Cigwin :)
BryanH
A: 

Something like:

svn version > ver.txt
set /p ver= < ver.txt
del ver.txt
echo %ver%
Steven Robbins
A: 

If you need this from a remote repository (as in not checked out localy) you can do this

for /f "delims=: tokens=1,2" %%a in ('svn info %SVN_REPO_URL%') do (
  if "%%a"=="Revision" (
    set /a RELEASE_REVISION=%%b
  )
)

I use this in my release process to grab the revision number from a tag.

StocksR