SVN(服务器-预提交钩子):知道正在提交的文件列表 [英] SVN (server - pre-commit hook): Know the list of files that are being committed
问题描述
我想知道如何获取在预提交挂钩上提交的文件列表.
I would like to know how to get the list of files that are being committed on the pre-commit hook.
如果该列表不包含特定路径中的特定文件,那么我想拒绝提交.
If that list doesn't contain a specific file in a specific path, then I want to reject the commit.
推荐答案
在预提交中使用 svnlook
.svnlook changed
给出了提交的更改路径.将此与您的列表进行比较.如果找到/未找到路径,则拒绝它.预提交的一个简单示例可能是.
Use svnlook
in a pre-commit.
svnlook changed
gives the changed paths of the commit. Compare this against your list. And reject it if path is found/not found. One simple example for pre-commit could be.
#!/bin/sh
REPOS="$1"
TXN="$2"
SPATH="specific/path"
FOUND=$(svnlook changed -t "$TXN" "$REPOS" | tr -d '\n' | grep -E ".*$SPATH.*")
if [ "$FOUND" != "" ]
then
echo "Reject commit!" 1>&2 && exit 1
else
exit 0
fi
在这里,我删除了感兴趣的路径的换行符和 grep.如果找不到路径,则拒绝提交 exit 1
.用户将在那里看到您的回声.
Here I removed newlines and grep for the interested path. If path is not found, recject the commit exit 1
. User will see what you echo there.
这篇关于SVN(服务器-预提交钩子):知道正在提交的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!