问题描述
我在Windows服务器上通过VisualSVN服务器运行Subvbersion,并且我的存储库设置了一个中继和三个分支。分支是dev,test和prod。我有一个post提交钩子,我想运行它更新一个工作副本后,提交运行,但我只想要更新那个工作副本,如果提交是在dev分支。
I'm running Subvbersion through VisualSVN Server on a Windows server and have my repository set up with a trunk and three branches. The branches are dev, test and prod. I have a post commit hook that I want to run which updates a working copy after a commit is run, but I only want it to update that working copy if the commit was made in the dev branch.
这是我现在的代码...
This is the code I have right now...
@setlocal enableextensions enabledelayedexpansion
@echo off
SET str1=%1
IF NOT x%str1:dev=%==x%str1% (
pushd <path to working copy>
svn update --username <svn_username> --password <svn_password>
echo update complete
)
endlocal
如果我取出条件,更新在每次提交时运行,所以我知道条件工作中的代码。我还测试了条件作为一个常规的批处理文件,发送它的字符串,如branches / dev和branches / test,它在这些测试中正常运行。但是,当我将其保存为我的提交后钩子脚本时,它永远不会运行,无论提交是在开发分支还是其他。
If I take out the conditional, the update runs on every commit, so I know the code inside the conditional works. I have also tested the conditional as a regular batch file, sending it strings like "branches/dev" and "branches/test" and it behaved properly in those tests. However, when I save this as my post-commit hook script, it never runs, whether the commit is in the dev branch or otherwise.
编辑:基于反馈这个问题已经回答了,我尝试了另一个问题中推荐的方法,但是这种方法也不工作。这是我的版本的代码建议有:
Based on feedback that this question was already answered, I tried the approach recommended in the other question, but that approach is not working either. Here is my version of the code suggested there:
REM The command checks whether the committed revision changes any data under '/dev'
"%VISUALSVN_SERVER%bin\svnlook.exe" dirs-changed %1 --revision %2 | findstr /b "[Dd]ev"
REM If 'findstr' returns error code 0, it means that the commit involves the '/dev' directory.
REM So if the the returned code is 0 the command runs external batch 'post-commit-actions.bat'
If %ERRORLEVEL% EQU 0 call %~dp0post-commit-actions.bat %*
为了这个工作,我已经在hooks目录中创建了一个名为post-commit-actions .bat来执行svn更新。但是,这不是运行post-commit。如果我遗漏任何相关信息,请让我知道。
In order for this to work, I have created a file in the hooks directory called post-commit-actions.bat to execute the svn update. However, this is not running post-commit. If I'm leaving out any pertinent information, please let me know.
编辑:感谢大家的帮助。有了这里的输入,我能够拼凑一个工作的解决方案。对于那些寻找类似问题的答案,它的工作方式如下:
Thanks for everyone's help. With the input here, I was able to piece together a working solution. For those looking for an answer to a similar problem, it worked like this:
svnlook dirs-changed %1 -r %2 | findstr /b /i "branches/dev"
IF %ERRORLEVEL% EQU 0 (
pushd <path-to-working-copy>
svn update --username <repo-username> --password <repo-password>
)
推荐答案
刚刚发布,这里是问题的解决方案。这个代码集的目的是:
Just so it's posted, here was the solution to the problem. This code-set worked for the purpose intended:
svnlook dirs-changed %1 -r %2 | findstr /b /i "branches/dev"
IF %ERRORLEVEL% EQU 0 (
pushd <path-to-working-copy>
svn update --username <repo-username> --password <repo-password>
)
在导出此解决方案的所有帮助
Thanks for all of the help in deriving this solution
这篇关于为什么我的post-commit钩子条件语句不工作,当我检查,看看是否一个特定的分支提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!