在svn hooks

时间:2017-08-05 19:36:09

标签: svn pre-commit-hook svn-hooks

如果有人试图提交受限文件,我有一个提交失败的挂钩。但是,我希望通过绕过预提交挂钩来提供对可以提交的某些人的访问权限。让我知道我该怎么做。我在编写脚本方面不是很专业。

预提交挂钩:

REPOS="$1"
TXN="$2"

# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook

LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS")

# check if any comment has supplied by the commiter
if [ -z "$LOGMSG" ]; then
echo "Your commit was blocked because it have no comments."
exit 1
fi 1>&2

#check minimum size of text
if [ ${#LOGMSG} -lt 15 ]; then
echo "Your Commit was blocked because the comments does not meet minimum length requirements (15 letters)."
exit 1
fi 1>&2

# get TaskID by regex
TaskID=$(expr "$LOGMSG" : '\([#][0-9]\{1,9\}[:][" "]\)[A-Za-z0-9]*')

# Check if task id was found. 
if [ -z "$TaskID" ]; then

echo   
echo "No Task id found in log message \"$LOGMSG\"" 
echo   
echo "The TaskID must be the first item on the first line of the log message."  
echo   
echo "Proper TaskID format--> #123- 'Your commit message'  " 
exit 1
fi 1>&2

#Check that QA should not be present in log message.

if grep -q ' QA\>' <<< "$LOGMSG"; then
    echo
    echo "Your log message \"$LOGMSG\" must not contain QA in upper case."
    echo
    exit 1
fi 1>&2

#Check that restricted files should not get commited.

if [ -x ${REPOS}/hooks/restrict_files.sh ]; then
echo
${REPOS}/hooks/restrict_files.sh "${REPOS}" "${TXN}" 
fi 1>&2

restrict_files.sh

#!/bin/bash

REPOS="$1"
TXN="$2"

SVNLOOK=/usr/bin/svnlook

#Check that restricted files should not get commited.

RESFILES=$($SVNLOOK changed -t "$TXN" "$REPOS")

if grep -E '/*/httpdocs/libs/class.logs.php'\|'/*/httpdocs/app/models/login.php'\|'/*/httpdocs/app/controller/login.php'\|'/*/httpdocs/check_session.php'\|'/*/httpdocs/index.php'\|'/*/httpdocs/config/db.php'\|'/*/httpdocs/config/path.php'\|'/*/httpdocs/Salesp/config/constant.php'\|'/*/generic/common/CarrierConstants.php'\|'/*/generic/Carrier/GetVendorCommonFunction.php' <<< "$RESFILES" >/tmp/rest.txt; then

echo
echo "You are trying to commit restricted files:"
rest=$(</tmp/rest.txt)
echo "$rest"
echo
exit 1
fi 1>&2

0 个答案:

没有答案