0

How do I get a SVN revision number of a remote repository in a windows batch file ? I want to check for a condition when the user enters blank i have to get HEAD revision.

I'm using the following snippet to get the revision number. Although the for loop returns all the necessary information w.r.t remote SVN server location including the revision number. Still the batch file throws The system cannot find the file specified and the variable %SVN_VERSION% still remains empty.

In the below mentioned code, the %SVN_PATH% points to the remote server URL

set /p "SVN_VERSION=Please specify the SVN Revision number. For HEAD revision press Enter"
    if "%SVN_VERSION%" =="" (
    for /f "delims=: tokens=1,2" %%a in ('svn info %SVN_PATH%') do (
              if "%%a"=="Revision:" (
                set /a SVN_VERSION=%%b
            )
        )
    )

Thanks

this-Me
  • 2,139
  • 6
  • 43
  • 70
  • what show this? `svn info %SVN_PATH% | findstr /ic:"Revision:"` – Paul Sep 24 '15 at 07:39
  • Also you can use directly [`svnversion` command: Summarize the local revision(s) of a working copy.](http://svnbook.red-bean.com/en/1.7/svn.ref.svnversion.re.html) – Paul Sep 24 '15 at 08:47
  • 1. you should reset your variable by `set SVN_VERSION=` before the `set /p` command, as this does not clear a previous number; 2. is the location of `svn.exe` contained in the system's `%path%` variable, or in which directory do you run your script? – aschipfl Sep 24 '15 at 08:56
  • @Paul: Actually the Revision is returned in the for loop step, but somehow the value is not being set to the %SVN_VERSION% variable – this-Me Sep 24 '15 at 13:27

1 Answers1

2

As I mentioned in the comments, you can directly obtain revision with svnversion command.

@echo off
set /p "SVN_VERSION=Please specify the SVN Revision number. For HEAD revision press Enter"
if "%SVN_VERSION%"=="" (
    for /f %%a in ('svnversion') do set "SVN_VERSION=%%a"
)
exit /b 0

Edit

Here it is well explained how to use the command svnversion

Edit

According to your comments and trying to guess in your mind, the following command should work if you know the remote_url

@echo off

rem Edit remote_url
set /p "remote_url=Please specify the SVN repo url http://....." || goto:EOF

set /p "SVN_VERSION=Please specify the SVN Revision number. For HEAD revision press Enter"

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

Edit

This should also work since I have seen what should be the input

@echo off

set /p "SVN_VERSION=Please specify the SVN Revision number. For HEAD revision press Enter"

if "%SVN_VERSION%"=="" (
    for /f "tokens=1,2" %%a in ('svn info %SVN_PATH% ^|findstr /ic:"Revision"') do set SVN_VERSION=%%b
)
exit /b 0

Explanation:
Your mistake was with delims=: since : is not part of the tokens the comparison came wrong. Also, the default delims is space, so don't need to specify a delims here since the line are splited in two parts.

Community
  • 1
  • 1
Paul
  • 2,620
  • 2
  • 17
  • 27
  • How does the svnversion command know to look for that specific remote repository ? – this-Me Sep 24 '15 at 11:23
  • No, this wouldn't work because I need the information from the remote repository. I do not have a local working copy yet. – this-Me Sep 24 '15 at 11:36
  • %SVN_PATH% - user defined variable which points to the remote SVN Server URL. Similar to the variable you have defined %remote_url% – this-Me Sep 24 '15 at 13:18
  • Removing colon worked. Really don't understand how did I missed it. Thanks for helping me out – this-Me Sep 24 '15 at 13:41