挂钩脚本可阻止提交具有特定字符串的文件 [英] Hook script to block commit of files having a particular string
本文介绍了挂钩脚本可阻止提交具有特定字符串的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在我的钩子脚本文件abc-pre-commit.bat
中实现了以下代码,如果文件包含字符串cod_bank
I have implemented the below code in my hook script file abc-pre-commit.bat
to disallow commit if files contain the string 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
My file does contains the string cod_bank
输出:在提交窗口中显示
OUTPUT: in commit window it shows
commit blocked by pre-commit-hook
它不显示echo msg,也如何存储svnlook diff命令的o/p.我尝试过但没有成功.
It does not displays the echo msg also how can I store the o/p of the svnlook diff command. I tried but was not successful.
推荐答案
在Linux中 它是这样的:
In Linux It works like this:
#!/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
这篇关于挂钩脚本可阻止提交具有特定字符串的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文