SVN 钩子预提交钩子以防止添加相同的文件名

SVN hook pre commit hook to prevent addition of same filename

我的存储库中有 class 个列表,我不想将相同的 class 名称添加两次。

我的目标是防止提交相同的文件名,即如果 abc.class.php 已经存在于任何目录中,则用户无法将 abc.class.php 添加到存储库。
我试过了

CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS" | grep "^[A]" | $AWK '{print }' | grep \.class.php$`
for FILENAME in $CHANGED
do  
    AlreadyFoundFile=$(locate $FILENAME ./var/www/html/REPO/)

    if [ $AlreadyFoundFile ]
    then
        echo "WARNING-  "$FILENAME" - class name already exist" 1>&2
        exit 1
    fi
done 

它正在检查 /var/www/html/REPO/(checkedOut 分支)中已提交的文件,但我想检查存储库中的文件。

有没有可能的方法?

您可以使用 svnlook tree:

CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS" | grep "^[A]" | $AWK '{print }' | grep \.class.php$`
tree=$( svnlook tree "$REPOS" )

for FILENAME in $CHANGED
do  
    if grep -q "$FILENAME" <<< "$tree"
    then
        echo "WARNING-  "$FILENAME" - class name already exist" 1>&2
        exit 1
    fi
done

请注意,这将不限于某个分支。如果需要,树命令允许将路径指定为第二个参数,请参阅 documentation.