views:

99

answers:

7

Hello, I'm trying to write a batch file in which I need the HEAD revision of the project I am working on.

Is there a command to get this from the command line?

I am on a Windows XP Machine.

EDIT I ended up using a mix between Shambulator, mizipzor, and Stefan's answers. I ended up with this:

for /f "tokens=5" %%i in ('SubWCRev WorkingCopyPath^|find "Last committed at revision"') do set version=%%i 
echo %version%

Thanks for all your help guys

Added this answer to the list below as well.

A: 

TortoiseSVN doesn't give you any command-line interface as it is just a shell extension.

However, if you install the svn command-line tools, the following command will give you details of the SVN URL:

svn info [SVN-URL]

to extract the revision you could use this:

svn info [SVN-URL] | grep Revision | awk '{print $2}'

(that is assuming you've got some UNIX tools installed, e.g. cygwin)

John Pickup
Ah ok, I had been looking at the tortoise command line documentation and hoping that I was just missing something. Trying to write a batch file to go from source files to a built and compiled installer "automagically" has been no easy task.
Nedloh
A: 

I don't think there's any way of doing this directly from the command line using tortoisesvn. You can install the command line version from Collabnet and then use a command such as this:

c:\>svn ls -v svn://server/Source
67336 user1                Jul 05 13:00 ./
67336 user1                Jul 05 13:00 Source/
the_mandrill
In this is the 67336 the revision number? I am in need of something that makes it easy to extract as I will be using it through my batch file. If it is the case that it is the first item provided this may prove useful.
Nedloh
yes, this is the revision of the latest revision in the repository (ie the head). If you were using multiple branches then substitute this with `svn://.../Source/trunk` or `.../Source/branches/mybranch` as appropriate
the_mandrill
+5  A: 

It's awkward without the text-processing capabilities of *nix, but this batch file does it:

@echo off
for /f "tokens=2" %%i in ('svn info -rHEAD svn://localhost^|find "Revision"') do @echo %%i

Substitute your svn repository for my svn://localhost.

svn info gets the repository info, then pipes it to find, which strips out everything except the line containing the revision number. The for command gives you the second "token" on that line (the first one is Revision:).

EDIT: As others have mentioned already, you'll need a command-line version of Subversion installed, and have svn.exe on your PATH.

shambulator
First real solution Ive seen that doesnt need *nix stuff.
mizipzor
ah, this looks good. I was hoping to be able to avoid installing anything else as the goal of this batch file is to go from source files to a built and compiled installer, and it has to work on all of my team's machines but it appears I have no choice
Nedloh
@Nedloh: you probably dont have to install anything. I assume that everyone in your team has a working svn client installed. If such is the case, you can simply add the location to where the svn client is to PATH. But I dont think you get around that, other than a fully qualified call in the script, but then everyone would need to have the client installed in the same place.
mizipzor
Also, if your ultimate goal is to set up a build infrastructure, I'd suggest taking a look at MSBuild or Ant, rather than batch files. You already have MSBuild if you're using Visual Studio.
shambulator
@mizipzor: ok, this this should be good solution as is the one you posted, I'll just have to ensure that I outline in my procedures for the script that the member has correctly added their svn client to PATH. Thanks
Nedloh
@shambulator: We currently do use Ant, the problem is that within the project, on each formal release there are certain modifications that need to be made to specific files (i.e. updating the revision number) which I am using a combination of this batch file and Perl. Currently I go from the source code to a setup.exe that is all in place in our formal release directory.
Nedloh
@mizipzor: Alright, one more question, I just joined this group a month ago. When I came in they set me up with TortoiseSVN. From what I gather, everyone uses that as their SVN client. Is there an svn.exe with the tortoise path (I can't find it) or will I need to install a different client with command line functionality?
Nedloh
@Nedloh: I think there should be a *svn.exe* file somewhere within the TortoiseSVN install folder (check for a *bin* folder or similar). Sadly I cant be bothered to install it right now and I couldnt find a flat install in a zip archive on the download page so I cant look myself.
mizipzor
@mizipzor: alright no problem, I look around, I can't seem to find one but I suppose if worse comes to worse I they'll just need to install a command line SVN client. Thanks for all your help
Nedloh
Used this solution in combination with the utility that Stefan brought up. Solution is now provided with question as well as in the answers
Nedloh
You may want to use `findstr /b` to anchor the `Revision` string to the start of the line. Also I'd probably use the colon as a separator – who knows which language has “Revision” split up into two words ...
Joey
A: 

Another possible approach. If you've got the repository checked out then the .svn\entries file has the revision number in the 4th line. i.e.

head -4 entries | tail -1

will give you the revision number.

probably not all that wise to use this as the format of the file could change - it really depends on if the script is just for personal use

John Pickup
+1  A: 

The current answers list how to print the current revision on the central svn repository. If you're interested in the current local checked out revision I found this blog post that does something quite similar to what is done in Shambulator's answer:

@echo off
FOR /F "tokens=2 skip=4" %%G IN ('svn info --revision HEAD') DO ^
IF NOT DEFINED REVISION SET REVISION=%%G
echo %REVISION%
mizipzor
In the procedures for this batch file, it is a requirement that the user has updated to the newest revision (forced this within the batch file) so really either way should work.
Nedloh
@Nedloh: Good to hear. But I would urge you to, as Shambulator pointed out, reading up on MSBuild if youre setting up your infrastructure.
mizipzor
+1  A: 

If you need that revision in a file, use SubWCRev which is installed with TortoiseSVN (or available separately).

Stefan
I do kind of need it in a file, but I need it in the script that would be running so that wouldn't quite work. However, I think if I can us SubWCRev and extract the revision number from the output then I can accomplish my goal without having to install another svn client that supports command line functionality.
Nedloh
A: 

I ended up using a mix between Shambulator, mizipzor, and Stefan's answers. I ended up with this:

for /f "tokens=5" %%i in ('SubWCRev WorkingCopyPath^|find "Last committed at revision"') do set version=%%i  
echo %version% 

Thanks for all your help guys

Nedloh