14

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.

Nedloh
  • 381
  • 2
  • 3
  • 14
  • 3
    Have you tried "svnversion ./" ??? that's in the command line, you get only the current revision version you have checkedout – jmdiego Nov 13 '14 at 17:04

11 Answers11

28

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.

anton.burger
  • 5,637
  • 32
  • 48
  • 1
    First real solution Ive seen that doesnt need *nix stuff. – Mizipzor Jul 05 '10 at 13:28
  • 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 Jul 05 '10 at 13:32
  • @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 Jul 05 '10 at 13:36
  • 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. – anton.burger Jul 05 '10 at 13:39
  • @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 Jul 05 '10 at 13:43
  • @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 Jul 05 '10 at 13:48
  • @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 Jul 05 '10 at 14:15
  • 1
    @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 Jul 05 '10 at 14:22
  • @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 Jul 05 '10 at 14:24
  • 1
    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 Jul 05 '10 at 15:19
  • 1
    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 Jul 05 '10 at 21:20
  • @Nedloh TortoiseSVN by default does not install the commandline tools. So I always enable that feature manually when installing, as they are tremendously useful (and TortoiseSVN often releases them earlier than the official Windows builds from Apache or Collabnet). – Jeroen Wiert Pluimers Aug 02 '13 at 07:54
4

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

Stefan
  • 43,293
  • 10
  • 75
  • 117
  • 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 Jul 05 '10 at 14:57
3

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
  • 381
  • 2
  • 3
  • 14
1

I know this question is old, but it was just what I was looking for, only problem was that I couldn't get the answer to work. Here's the bat script I ended up with:

set SubWCRev=C:\Program Files\TortoiseSVN\bin\SubWCRev.exe
set WorkingCopyPath=%~dp0
for /f "tokens=5" %%i in ('""%SubWCRev%" "%WorkingCopyPath%.""') do set version=%%i
@echo Version=%version%

I used the directory that the bat file was located in as the SVN reporitory folder, use %~dp1 is you want to pass in the directory as a parameter

Grant
  • 1,608
  • 16
  • 14
1

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)

  • 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 Jul 05 '10 at 13:27
1

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%
Community
  • 1
  • 1
Mizipzor
  • 51,151
  • 22
  • 97
  • 138
  • 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 Jul 05 '10 at 13:38
  • @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 Jul 05 '10 at 13:49
0
svn info -rHEAD %cd%|find "Revision:"> %temp%\__svnrev.tmp
set /p revision=< %temp%\__svnrev.tmp
del %temp%\__svnrev.tmp
set revision=%revision:~10%
echo %revision%

change %cd% in first line to your desired path

damkrat
  • 355
  • 3
  • 6
0

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
  • 29,792
  • 6
  • 64
  • 93
  • 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 Jul 05 '10 at 13:28
  • 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 Jul 05 '10 at 15:20
0

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

0

Here is my variant of shambulator's answer, in case you don't have svn.exe in the PATH. Note the use of backquotes to handle the spaces in the path.

@echo off
set SVN_EXE=C:\Program Files (x86)\VisualSVN\bin\svn.exe

rem Find revision of entire repository
for /f "usebackq tokens=2" %%i in (`call "%SVN_EXE%" info -rHEAD https://svnroot/repo^|find "Revision"`) do @echo %%i

rem Find revision of a path in the repository
for /f "usebackq tokens=4" %%i in (`call "%SVN_EXE%" info -rHEAD https://svnroot/repo/project/trunk^|find "Last Changed Rev"`) do @echo %%i
Community
  • 1
  • 1
Daniel Rose
  • 17,233
  • 9
  • 65
  • 88
0

This seems easier than all the previous answers:

svnlook youngest <repo-path>

It returns a single revision number.