gpt4 book ai didi

svn 预提交 Hook - 如何阻止某些文件类型中的关键字?

转载 作者:行者123 更新时间:2023-12-01 16:33:11 25 4
gpt4 key购买 nike

我正在尝试编写一个 svn 预提交 Hook ,如果某些文件类型中存在某些关键字,它将给出错误。

对我来说,如果文件是 .java、.jsp 或 .jspf 文件,我想确保其中不存在“http://”和“https://”。到目前为止,如果关键字存在于任何文件中,但不仅仅是我要检查的文件类型,我都可以抛出错误。

这是我到目前为止所拥有的:

$SVNLOOK diff -t "$TXN" "$REPOS" | grep -i "https://" > /dev/null && { echo "Your commit has been blocked because it contains the keyword https://." 1>&2; exit 1; }

最佳答案

我使用svnlookchangedsvnlookcat的组合来解决这个问题:

#Put all the restricted formats in variable FILTER
HTTP_FILTER=".(j|jsp)$"


# Figure out what directories have changed using svnlook.
FILES=`${SVNLOOK} changed ${REPOS} -t ${TXN} | ${AWK} '{ print $2 }'` > /dev/null

for FILE in $FILES; do

#Get the base Filename to extract its extension
NAME=`basename "$FILE"`

#Get the extension of the current file
EXTENSION=`echo "$NAME" | cut -d'.' -f2-`

#Checks if it contains the restricted format
if [[ "$HTTP_FILTER" == *"$EXTENSION"* ]]; then

# needed to only use http:/ or https:/ - for some reason doing double slash (i.e. http://)
# would not return results.
$SVNLOOK cat -t "$TXN" "$REPOS" "$FILE" | egrep -wi "https:/|http:/" > /dev/null && { echo "Your commit has been blocked because it contains the keyword https:// or http://." 1>&2; exit 1; }

fi

done

关于svn 预提交 Hook - 如何阻止某些文件类型中的关键字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29707649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com