Hook script to block commit of files having a particular string

ε祈祈猫儿з 提交于 2019-12-02 04:00:07

问题


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
)

My file does contains the string cod_bank

OUTPUT: in commit window it shows

commit blocked by pre-commit-hook

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.


回答1:


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


来源:https://stackoverflow.com/questions/8181997/hook-script-to-block-commit-of-files-having-a-particular-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!