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 wrt 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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.