我想添加一个Subversion预提交钩子,并拒绝包含某些文本的提交,例如Eclipse的// IDE-generated stub
注释。
我使用svnlook
(来自Subversion 1.11.0):
~> svnlook --version
svnlook, version 1.11.0 (r1845130)
compiled Dec 9 2018, 17:34:43 on x86_64-apple-darwin17.7.0
我的预提交钩子是一个简单的bash脚本:
#!/bin/bash
REPOS="$1"
TXN="$2"
set -ue
bad="// IDE-generated stub"
while read file
do
# found=$(svnlook cat --transaction "$TXN" "$REPOS" "$file" | grep "$bad")
found=$(svnlook diff --transaction "$TXN" "$file" | grep "$bad")
if [ -n "$found" ]
then
echo "Found $bad in $file" >&2
exit 1
fi
done < <(svnlook changed --transaction "$TXN" "$REPOS" | cut -c 4-)
exit 0
当我尝试提交某些内容时,出现以下关于foo/format
不存在的错误。下面的MCVE:
~> svnadmin create repository
~> svn co file://$PWD/repository wc
Checked out revision 0.
~> echo foo > wc/foo
~> svn add wc/foo
A wc/foo
~> svn ci wc/foo -m "initial version"
Adding wc/foo
Transmitting file data .done
Committing transaction...
Committed revision 1.
~> cp ~/pre-commit repository/hooks/pre-commit
~> chmod 755 repository/hooks/pre-commit
~> echo whatever >> wc/foo
~> svn ci wc/foo -m "next one"
Sending wc/foo
Transmitting file data .done
Committing transaction...
svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 1) with output:
svnlook: E000002: Can't open file 'foo/format': No such file or directory
请注意,当我使用带注释的svnlook cat
版本时,上述代码或多或少地起作用,但是随后,它也会触发它在已提交的代码中找到的任何关键字,而不仅仅是在当前更改中。
我看到了this question,但似乎与svnlook log
有关,并且有不同的错误代码。
为什么会出现该错误,我该如何解决?