SVN结账自动化批处理
SVN checkout automation batch
我想到了这个
echo.
echo. [ SVN Updater ]
setlocal enableDelayedExpansion
set SOURCE=E:\Svncheckout\
set SVN=C:\Program Files\TortoiseSVN\bin
set SVN_REPO_URL=https://SVNSERVERIP/svn/
set projects=project1/branches/hello1 project2/branches/hello2
set checkoutdir=project1 project2
echo.
SET PROJCOUNT=0
(for %%i in (%projects%) do (
echo. Checking out %SVN_REPO_URL%%%i from SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%checkoutdir[0]%" /url:"%SVN_REPO_URL%%%i" /closeonend:2
PROJCOUNT+=1;
)
)
echo.
echo. Operation complete.
我想用每个目录名称迭代 checkoutdir
列表数组。我被困在这里了。我是批处理编程的新手。请帮助
方法二:
echo.
echo. [ SVN Updater ]
setlocal enableDelayedExpansion
set SOURCE=E:\SvncheckoutMAY2016\
set SVN=C:\Program Files\TortoiseSVN\bin
set SVN_REPO_URL=https://192.168.1.35:8443/svn/
set projects=JPO/JPOMobile/branches/2016-05-18 JPO/JPOWEB/branches/20160518
set checkoutdir=JPOMobile JPOWEB
set /A CHECKOUTCOUNT=1
set /A PROJCOUNT=0
(for %%i in (%projects%) do (
SET /A "PROJCOUNT+=1"
(for %%a in (%checkoutdir%) do (
IF ("%PROJCOUNT%"=="%CHECKOUTCOUNT%") (
echo. Checking out %SVN_REPO_URL%%%i from SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%%a" /url:"%SVN_REPO_URL%%%i" /closeonend:2
SET /A "CHECKOUTCOUNT+=1"
)
))
))
echo.
echo. Operation complete.
第二种方法出错,设置/A PROJCOUNT=0 in unexpected at this time.I 认为for
循环有问题
1st:错误IF syntax:删除下一个有害的括号
IF ("%PROJCOUNT%"=="%CHECKOUTCOUNT%") (
rem ^ ^
第 2:variables within parenthesized command blocks:
Delayed Expansion will cause variables to be expanded at execution
time rather than at parse time, this option is turned on with the
SETLOCAL command. When delayed expansion is in effect variables
can be referenced using !variable_name!
(in addition to the normal
%variable_name%
).
您需要应用 延迟扩展 必要时,因为仅仅声明是不够的。
3rd(外观错误):删除 不必要的括号 .
更新的代码:请注意 TortoiseProc.exe
命令只是为了调试目的而回显。
echo off
echo.
echo. [ SVN Updater ]
setlocal EnableExtensions EnableDelayedExpansion
set SOURCE=E:\SvncheckoutMAY2016\
set SVN=C:\Program Files\TortoiseSVN\bin
set SVN_REPO_URL=https://192.168.1.35:8443/svn/
set projects=JPO/JPOMobile/branches/2016-05-18 JPO/JPOWEB/branches/20160518
set checkoutdir=JPOMobile JPOWEB
set /A CHECKOUTCOUNT=1
set /A PROJCOUNT=0
for %%i in (%projects%) do (
SET /A "PROJCOUNT+=1"
for %%a in (%checkoutdir%) do (
rem wrong IF ("%PROJCOUNT%"=="%CHECKOUTCOUNT%") (
rem right IF "!PROJCOUNT!"=="!CHECKOUTCOUNT!" (
rem or IF !PROJCOUNT! EQU !CHECKOUTCOUNT! (
IF !PROJCOUNT! EQU !CHECKOUTCOUNT! (
echo. Checking out %SVN_REPO_URL%%%i from SVN...
ECHO "%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%%a" /url:"%SVN_REPO_URL%%%i" /closeonend:2
SET /A "CHECKOUTCOUNT+=1"
)
)
)
echo.
echo. Operation complete.
echo. debug PROJCOUNT=%PROJCOUNT%
echo. CHECKOUTCOUNT=%CHECKOUTCOUNT%
这是我针对此任务的解决方案:
@echo off
echo.
echo. [ SVN Updater ]
set "SOURCE=E:\SvncheckoutMAY2016\"
set "SVN=%ProgramFiles%\TortoiseSVN\bin"
set "SVN_REPO_URL=https://192.168.1.35:8443/svn/"
set "projects=JPO/JPOMobile/branches/2016-05-18 JPO/JPOWEB/branches/20160518"
set "checkoutdir=JPOMobile JPOWEB"
set "ProjectCount=0"
for %%P in (%projects%) do call :CheckOut "%%P"
echo.
echo. Operation complete.
rem Exit batch processing to avoid a fall through to subroutine.
exit /B
:CheckOut
set /A ProjectCount+=1
for /F "tokens=%ProjectCount%" %%D in ("%checkoutdir%") do (
echo. Checking out %SVN_REPO_URL%%~1 from SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%%D" /url:"%SVN_REPO_URL%%~1" /closeonend:2
)
rem Exit this subroutine. It is also possible to use GOTO :EOF
exit /B
第一个循环处理环境变量 projects
中定义的每个项目,由 space 分隔。对于每个项目,子例程 CheckOut
以当前项目路径作为参数被调用。
子例程 CheckOut
首先递增项目计数变量,该变量是结帐目录字符串索引,第一个字符串的索引号为 1。
此子例程中的第二个循环现在将环境变量 checkoutdir
中的目录列表解释为字符串而不是字符串列表,因为使用了 FOR 的参数 /F
并将环境变量的值括在双引号中。
要从字符串中获取第 N 个签出目录,其中签出目录由 spaces 分隔,使用 tokens=x
语法,其中 x
是项目计数变量的当前值.
检出是通过第 N 个检出目录完成的,并且 %~1
引用的当前项目作为第一个参数传递给子例程。
有关在命令提示符 window call /?
中使用子例程和引用参数 运行 的详细信息,并阅读所有输出帮助页面。
这里使用的子程序就像在当前批处理文件中嵌入了另一个批处理文件。
注意: 有 31 个令牌的限制。 ProjectCount
因此不应超过值 31。
我想到了这个
echo.
echo. [ SVN Updater ]
setlocal enableDelayedExpansion
set SOURCE=E:\Svncheckout\
set SVN=C:\Program Files\TortoiseSVN\bin
set SVN_REPO_URL=https://SVNSERVERIP/svn/
set projects=project1/branches/hello1 project2/branches/hello2
set checkoutdir=project1 project2
echo.
SET PROJCOUNT=0
(for %%i in (%projects%) do (
echo. Checking out %SVN_REPO_URL%%%i from SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%checkoutdir[0]%" /url:"%SVN_REPO_URL%%%i" /closeonend:2
PROJCOUNT+=1;
)
)
echo.
echo. Operation complete.
我想用每个目录名称迭代 checkoutdir
列表数组。我被困在这里了。我是批处理编程的新手。请帮助
方法二:
echo.
echo. [ SVN Updater ]
setlocal enableDelayedExpansion
set SOURCE=E:\SvncheckoutMAY2016\
set SVN=C:\Program Files\TortoiseSVN\bin
set SVN_REPO_URL=https://192.168.1.35:8443/svn/
set projects=JPO/JPOMobile/branches/2016-05-18 JPO/JPOWEB/branches/20160518
set checkoutdir=JPOMobile JPOWEB
set /A CHECKOUTCOUNT=1
set /A PROJCOUNT=0
(for %%i in (%projects%) do (
SET /A "PROJCOUNT+=1"
(for %%a in (%checkoutdir%) do (
IF ("%PROJCOUNT%"=="%CHECKOUTCOUNT%") (
echo. Checking out %SVN_REPO_URL%%%i from SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%%a" /url:"%SVN_REPO_URL%%%i" /closeonend:2
SET /A "CHECKOUTCOUNT+=1"
)
))
))
echo.
echo. Operation complete.
第二种方法出错,设置/A PROJCOUNT=0 in unexpected at this time.I 认为for
循环有问题
1st:错误IF syntax:删除下一个有害的括号
IF ("%PROJCOUNT%"=="%CHECKOUTCOUNT%") (
rem ^ ^
第 2:variables within parenthesized command blocks:
Delayed Expansion will cause variables to be expanded at execution time rather than at parse time, this option is turned on with the SETLOCAL command. When delayed expansion is in effect variables can be referenced using
!variable_name!
(in addition to the normal%variable_name%
).
您需要应用 延迟扩展 必要时,因为仅仅声明是不够的。
3rd(外观错误):删除 不必要的括号 .
更新的代码:请注意 TortoiseProc.exe
命令只是为了调试目的而回显。
echo off
echo.
echo. [ SVN Updater ]
setlocal EnableExtensions EnableDelayedExpansion
set SOURCE=E:\SvncheckoutMAY2016\
set SVN=C:\Program Files\TortoiseSVN\bin
set SVN_REPO_URL=https://192.168.1.35:8443/svn/
set projects=JPO/JPOMobile/branches/2016-05-18 JPO/JPOWEB/branches/20160518
set checkoutdir=JPOMobile JPOWEB
set /A CHECKOUTCOUNT=1
set /A PROJCOUNT=0
for %%i in (%projects%) do (
SET /A "PROJCOUNT+=1"
for %%a in (%checkoutdir%) do (
rem wrong IF ("%PROJCOUNT%"=="%CHECKOUTCOUNT%") (
rem right IF "!PROJCOUNT!"=="!CHECKOUTCOUNT!" (
rem or IF !PROJCOUNT! EQU !CHECKOUTCOUNT! (
IF !PROJCOUNT! EQU !CHECKOUTCOUNT! (
echo. Checking out %SVN_REPO_URL%%%i from SVN...
ECHO "%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%%a" /url:"%SVN_REPO_URL%%%i" /closeonend:2
SET /A "CHECKOUTCOUNT+=1"
)
)
)
echo.
echo. Operation complete.
echo. debug PROJCOUNT=%PROJCOUNT%
echo. CHECKOUTCOUNT=%CHECKOUTCOUNT%
这是我针对此任务的解决方案:
@echo off
echo.
echo. [ SVN Updater ]
set "SOURCE=E:\SvncheckoutMAY2016\"
set "SVN=%ProgramFiles%\TortoiseSVN\bin"
set "SVN_REPO_URL=https://192.168.1.35:8443/svn/"
set "projects=JPO/JPOMobile/branches/2016-05-18 JPO/JPOWEB/branches/20160518"
set "checkoutdir=JPOMobile JPOWEB"
set "ProjectCount=0"
for %%P in (%projects%) do call :CheckOut "%%P"
echo.
echo. Operation complete.
rem Exit batch processing to avoid a fall through to subroutine.
exit /B
:CheckOut
set /A ProjectCount+=1
for /F "tokens=%ProjectCount%" %%D in ("%checkoutdir%") do (
echo. Checking out %SVN_REPO_URL%%~1 from SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%%D" /url:"%SVN_REPO_URL%%~1" /closeonend:2
)
rem Exit this subroutine. It is also possible to use GOTO :EOF
exit /B
第一个循环处理环境变量 projects
中定义的每个项目,由 space 分隔。对于每个项目,子例程 CheckOut
以当前项目路径作为参数被调用。
子例程 CheckOut
首先递增项目计数变量,该变量是结帐目录字符串索引,第一个字符串的索引号为 1。
此子例程中的第二个循环现在将环境变量 checkoutdir
中的目录列表解释为字符串而不是字符串列表,因为使用了 FOR 的参数 /F
并将环境变量的值括在双引号中。
要从字符串中获取第 N 个签出目录,其中签出目录由 spaces 分隔,使用 tokens=x
语法,其中 x
是项目计数变量的当前值.
检出是通过第 N 个检出目录完成的,并且 %~1
引用的当前项目作为第一个参数传递给子例程。
有关在命令提示符 window call /?
中使用子例程和引用参数 运行 的详细信息,并阅读所有输出帮助页面。
这里使用的子程序就像在当前批处理文件中嵌入了另一个批处理文件。
注意: 有 31 个令牌的限制。 ProjectCount
因此不应超过值 31。