我正在尝试定义一个可以自动更新或签出多个SVN URL到特定文件路径的批处理文件,它将用于设置新用户并使其保持最新。此时,它是一个通用批处理文件问题,而不是SVN或TortoiseSVN问题。问题是如何将我复制和粘贴的内容多次复制到循环中,我可以将这两个参数输入。
该过程是重复的,并且包含两个变量(一个URL和一个本地文件路径),因此它非常适合循环,但URL和文件路径对于每个变量都是唯一的,所以我不得不将它们复制并粘贴到哪个使维护变得困难。
我在堆栈溢出搜索中得到的FOR %%A IN ( x x x x ) DO START xxx
示例中有多个文件路径可用,我最后注释掉了这个,当我决定要将它作为自动更新和自动时,这就是变形了结帐批次。我似乎不能让它为多个变量工作,因为那个例子只有一个。
目标是拥有一个自包含的批处理文件,我不必提供参数或拥有多个批处理文件。环境是Windows 10。
与原始问题无关:另外,我发布此帖是为了感谢我为了达到这个目的而看到的其他帖子。我喜欢"开始"多线程命令。我无法弄清楚如何让Tortoiseproc为我做结帐,现在它只是打开一个窗口,因此如果没有安装svn.exe,则回显让用户点击确定。我对.exe检查的路径进行了硬编码,因为我没有时间尝试"其中"命令和错误级别检查看起来很笨重。我让这个批处理文件按原样运行,然后使它成为通用的,对不起,如果它破坏了任何东西。关于如何正确显示语法突出显示的任何评论(我读到它应该在标签中找到它但我尝试了其他语言说明符并且它似乎没有拿起它所以我会看看我发帖后会发生什么事情)让我知道。
@echo off
setlocal
REM This batch file can be used to perform the initial checkout if needed and update svn working copys automatically.
REM It automatically detects a lack of TortoiseSVN. It has a workaround for if SVN commandline is not installed.
REM If at least TortoiseSVN is installed it automatically detects if the working copy does not exist and performs a checkout.
REM If at least TortoiseSVN is installed it automatically updates already existing working copies.
REM You can automate it via task scheduler. Ex: Upon lock if network is connected and user is logged in; and/or daily in the morning.
REM TODO: The templates folder has trouble upon initial checkout cleaning out the old normal.dotm file because it already exists. Probably add hard cleanup.
if not exist "C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" (
echo Install TortoiseSVN with command line option
pause
exit
) else (
if not exist "C:\Program Files\TortoiseSVN\bin\svn.exe" (
echo Proceeding without SVN commandline option.
echo Hit ok when TortoiseSVN checkout windows open.
pause
)
)
REM if everything is good then proceed on!
REM Everyone
SET REPO1_URLDIR=https://REPO1
SET REPO1_PATHDIR=C:\Users\Public\Documents\REPO1
SET REPO2_URLDIR=https://REPO2
SET REPO2_PATHDIR=%appdata%\Microsoft\Templates\
REM designers:
SET REPO3_URLDIR=https://REPO3
SET REPO3_PATHDIR=C:\Users\Public\Documents\REPO3
SET REPO4_URLDIR=https://REPO4
SET REPO4_PATHDIR=C:\Users\Public\Documents\REPO4
REM Optional:
SET REPO5_URLDIR=https://REPO5
SET REPO5_PATHDIR=C:\Users\Public\Documents\REPO5
SET REPO6_URLDIR=https://REPO6
SET REPO6_PATHDIR=C:\Users\Public\Documents\REPO6
REM check if folder exists
if NOT exist "%REPO1_PATHDIR%" (
rem file doesn't exist. Create and checkout
ECHO missing "%REPO1_PATHDIR%" beginning download
if exist "C:\Program Files\TortoiseSVN\bin\svn.exe" (
START svn checkout %REPO1_URLDIR% %REPO1_PATHDIR%
) else (
START TortoiseProc.exe /command:checkout /path:%REPO1_PATHDIR% /url:"%REPO1_URLDIR%"
)
) else ( START TortoiseProc.exe /command:update /path:%REPO1_PATHDIR% /closeonend:3 )
if NOT exist "%REPO2_PATHDIR%\blank.potx" (
rem file doesn't exist. Create and checkout
ECHO missing "%REPO2_PATHDIR%" beginning download
if exist "C:\Program Files\TortoiseSVN\bin\svn.exe" (
START svn checkout %REPO2_URLDIR% %REPO2_PATHDIR%
) else (
START TortoiseProc.exe /command:checkout /path:%REPO2_PATHDIR% /url:"%REPO2_URLDIR%"
)
) else ( START TortoiseProc.exe /command:update /path:%REPO2_PATHDIR% /closeonend:3 )
if NOT exist "%REPO3_PATHDIR%" (
rem file doesn't exist. Create and checkout
ECHO missing "%REPO3_PATHDIR%" beginning download
if exist "C:\Program Files\TortoiseSVN\bin\svn.exe" (
START svn checkout %REPO3_URLDIR% %REPO3_PATHDIR%
) else (
START TortoiseProc.exe /command:checkout /path:%REPO3_PATHDIR% /url:"%REPO3_URLDIR%"
)
) else ( START TortoiseProc.exe /command:update /path:%REPO3_PATHDIR% /closeonend:3 )
if NOT exist "%REPO4_PATHDIR%" (
rem file doesn't exist. Create and checkout
ECHO missing "%REPO4_PATHDIR%" beginning download
if exist "C:\Program Files\TortoiseSVN\bin\svn.exe" (
START svn checkout %REPO4_URLDIR% %REPO4_PATHDIR%
) else (
START TortoiseProc.exe /command:checkout /path:%REPO4_PATHDIR% /url:"%REPO4_URLDIR%"
)
) else ( START TortoiseProc.exe /command:update /path:%REPO4_PATHDIR% /closeonend:3 )
if NOT exist "%REPO5_PATHDIR%" (
rem file doesn't exist. Create and checkout
ECHO missing "%REPO5_PATHDIR%" beginning download
if exist "C:\Program Files\TortoiseSVN\bin\svn.exe" (
START svn checkout %REPO5_URLDIR% %REPO5_PATHDIR%
) else (
START TortoiseProc.exe /command:checkout /path:%REPO5_PATHDIR% /url:"%REPO5_URLDIR%"
)
) else ( START TortoiseProc.exe /command:update /path:%REPO5_PATHDIR% /closeonend:3 )
if NOT exist "%REPO6_PATHDIR%" (
rem file doesn't exist. Create and checkout
ECHO missing "%REPO6_PATHDIR%" beginning download
if exist "C:\Program Files\TortoiseSVN\bin\svn.exe" (
START svn checkout %REPO6_URLDIR% %REPO6_PATHDIR%
) else (
START TortoiseProc.exe /command:checkout /path:%REPO6_PATHDIR% /url:"%REPO6_URLDIR%"
)
) else ( START TortoiseProc.exe /command:update /path:%REPO6_PATHDIR% /closeonend:3 )
REM update only:
REM FOR %%A IN (
REM "%REPO1_PATHDIR%"
REM "%REPO2_PATHDIR%"
REM "%REPO3_PATHDIR%"
REM "%REPO4_PATHDIR%"
REM "%REPO5_PATHDIR%"
REM "%REPO6_PATHDIR%"
REM ) DO START TortoiseProc.exe /command:update /path:%%A /closeonend:3
REM • The "FOR %%A" loop will contain, obviously, paths to the projects you want to update.
REM • The "START" bit means "START asynchronously, ie don't wait for end of previous task to launch next one" so that all the Update windows will pop up simultaneously.
REM • Use the "/closeonend:0" to test it first. Means, "don't close the Update window once it's done", so you can actually see what has been updated.
REM There you go. You can even put this .bat file in your STARTup folder to get things updated when you turn your computer on.
REM
REM To close the progress dialog at the end of a command automatically without using the permanent setting you can pass the /closeonend parameter.
REM • /closeonend:0 don't close the dialog automatically
REM • /closeonend:1 auto close if no errors
REM • /closeonend:2 auto close if no errors and conflicts
REM • /closeonend:3 auto close if no errors, conflicts and merges
REM To close the progress dialog for local operations if there were no errors or conflicts, pass the /closeforlocal parameter.
答案 0 :(得分:1)
您重复的代码块的格式为:
if NOT exist _REPO_N_PATH_ (
rem file doesn't exist. Create and checkout
ECHO missing _REPO_N_PATH_ beginning download
if exist _SVN_PATH_ (
START svn checkout _REPO_N_URL_ _REPO_N_PATH_
) else (
START TortoiseProc.exe /command:checkout /path:_REPO_N_PATH_ /url:_REPO_N_URL_
)
) else ( START TortoiseProc.exe /command:update /path:_REPO_N_PATH_ /closeonend:3 )
我计算三个参数:1)Repo路径,2)SVN可执行路径(虽然这可以保持不变)和3)repo URL,并且有一个特殊情况,其中使用特定文件名来测试因为它的存在,所以为它添加第四个可选参数。
编写一个子程序并调用它:
@setlocal ENABLEEXTENSIONS
@rem @set prompt=$G
@rem You can add a search for svn later.
@set _SVN_Path="C:\Program Files\TortoiseSVN\bin\svn.exe"
@call :Action C:\Users\Public\Documents\REPO1 %_SVN_Path% https://REPO1
@call :Action "%appdata%\Microsoft\Templates" %_SVN_Path% https://REPO2 blank.potx
@call :Action "C:\Users\Public\Documents\REPO3" %_SVN_Path% https://REPO3
@rem Etc...
@exit /b 0
@REM Action takes three parameters:
@REM %%1 is the repo path.
@REM %%2 is the path to the SVN executable.
@REM %%3 is the papth to the URI.
@REM %%4 is optional file name to look for rather than just the directory.
:Action
@if NOT exist %1\%4 (
@rem file doesn't exist. Create and checkout
@ECHO missing %1 beginning download
@if exist %2 (
@START svn checkout %3 %1
) else (
@START TortoiseProc.exe /command:checkout /path:%1 /url:%3
)
) else ( @START TortoiseProc.exe /command:update /path:%1 /closeonend:3 )
以上是未经测试的,但如果我有任何错误,不应该太难调试。只需在测试时删除要在输出中看到的任何行前面的@
符号。