我在钩子脚本文件abc-pre-commit.bat
中实现了以下代码,如果文件包含字符串cod_bank
SETLOCAL
SET PATH=C:\Windows;C:\Windows\system32;D:\SCC\SVN146\ bin;C:\Program Files\VisualSVN Server\bin;
set SVNLOOK = "C:\ProgramFiles\VisualSVNServer\bin\svnlook.exe"
set REPOS=%1
set TXN=%2
%SVNLOOK% diff %REPOS% -t %TXN% | findstr /I /M /L cod_bank > nul
if %errorlevel% gtr 0 (
exit 0
) else (
echo Your commit has been blocked because it contains the keyword cod_bank. 1>&2
exit 1
)
我的文件包含字符串cod_bank
OUTPUT:在提交窗口中显示
commit blocked by pre-commit-hook
它不显示echo msg如何存储svnlook diff命令的o / p。我试过但没有成功。
答案 0 :(得分:2)
在Linux中 它的工作原理如下:
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
$SVNLOOK diff "$REPOS" -t "$TXN" | \
[[ grep "^+cod_bank">/dev/null exit 0 ]] ||
echo "Your commit has been blocked because it contains the keyword cod_bank" >&2
exit 1