当我检查特定分支是否已提交时,为什么我的提交后挂钩条件语句不起作用?

2023-12-08

我通过 Windows 服务器上的 VisualSVN Server 运行 Subvbersion,并设置了一个主干和三个分支的存储库。分支是开发、测试和生产。我有一个提交后钩子,我想运行它在提交运行后更新工作副本,但我只希望它在提交是在开发分支中进行时更新该工作副本。

这是我现在拥有的代码......

@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”等字符串,并且它在这些测试中表现正常。但是,当我将其保存为提交后挂钩脚本时,无论提交是否在 dev 分支中,它都永远不会运行。

编辑:根据这个问题已经得到解答的反馈,我尝试了另一个问题中推荐的方法,但该方法也不起作用。这是我建议的代码版本:

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 更新。但是,这不是在提交后运行。如果我遗漏了任何相关信息,请告诉我。

编辑:感谢大家的帮助。通过这里的输入,我能够拼凑出一个可行的解决方案。对于那些寻找类似问题答案的人来说,它的工作原理如下:

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>
)

就这样发布了,这就是问题的解决方案。该代码集达到了预期目的:

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>
)

感谢您为得出此解决方案提供的所有帮助

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当我检查特定分支是否已提交时,为什么我的提交后挂钩条件语句不起作用? 的相关文章

随机推荐