【问题标题】:Can you output text when the commit passes in SVN?当提交通过SVN时,你能输出文本吗?
【发布时间】:2020-01-10 23:38:15
【问题描述】:

我们正在使用 SVN,我想检查一个字符串的提交消息并发出警告,没有这个字符串的提交将从下个月开始被退回,但目前允许提交通过。

stderr 仅在提交失败时输出,如何让提交成功但仍向用户提供输出(我在 C# 中编写钩子)?

【问题讨论】:

  • 我有一个解决方案,如果钩子被编写为 Windows 批处理脚本。如果您需要批处理脚本解决方案,请告诉我。
  • 总比没有好,谢谢!
  • @David,抱歉,由于某种原因,我的标签在之前的评论中不起作用,现在我无法编辑它:-/

标签: c# svn pre-commit-hook


【解决方案1】:

根据您上面的回复,这里是 windows 批处理解决方案。

在提交后挂钩中

:: repos = full path to physical repository
:: rev = the revision number related to the transaction committed
:: reposname = the name of the repository
set repos=%1
set rev=%2
set reposname=%~nx1
set Unwanted_String=string value

:: Capture commit message
svnlook log %repos% -r %rev%>%reposname%_%rev%_commit_statement.txt

:: Verify commit message meets requirements
powershell -command "If (Get-Content '%reposname%_%rev%_commit_statement.txt' | Where-Object { $_ -match '%Unwanted_String%'}) {'Found'} else {'Not found'}">%reposname%_%rev%_Is_String_Present.txt

:: Determine if feedback is needed
set /p Commit_Search=<%reposname%_%rev%_Is_String_Present.txt
if "%Commit_Search%"=="Found" (
echo ----------------------------------------------------->&2
echo The string %Unwanted_String% is not allowed >&2
echo In the future, please do not include this as part of your commit statement >&2
echo. >&2
echo Your change has been committed>&2
echo ----------------------------------------------------->&2
del *%reposname%_%rev%*.txt
exit /b 1
)

返回给用户的输出将显示对象已提交以及错误消息

提交后挂钩失败(退出代码 1)并输出:


字符串xxxxxx是不允许的

以后,请不要将此作为提交声明的一部分

您的更改已提交


一旦宽限期结束并且您想拒绝包含此字符串的提交语句,请将上述行移至您的预提交挂钩并进行一次更改

:: Capture commit message (-t is transaction in progress)
svnlook log -t %rev% %repos%>%reposname%_%rev%_commit_Statement.txt

将其移至预提交挂钩将阻止提交并告知用户它被拒绝的原因。

【讨论】:

    猜你喜欢
    • 2015-03-01
    • 1970-01-01
    • 2012-03-29
    • 2018-07-29
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多