我的服务器上设置了许多不同的存储库。我需要在每个repos中都有一个相同的post-commit钩子文件。对于现有的简单,但有没有办法调用 svnadmin create 自动将提交后的存根文件复制到新的hooks目录?基本上我正在寻找一个 post-svnadmin-create 钩子。谢谢!
答案 0 :(得分:1)
我认为你最好的选择是在一个脚本中包含对svnadmin create的调用,该脚本会在repo之后创建钩子。
答案 1 :(得分:0)
同意,只要没有一些内置的方式,似乎没有。我希望subversion可以为新的Linux用户提供类似可定制的骨架目录。太糟糕了。
如果有人发现它有用,那么这是我的评论包装器 - 应该是相当可扩展的。如果有人注意到其中有任何明显的陷阱,请不要犹豫 - 我既不是bash也不是Linux专家,但我认为我的大部分都被覆盖了,而且它有效:)
# -----------------------------------------------------------------------
# A wrapper for svnadmin to allow post operations following repo creation - copying custom
# hook files into repo in this case. This should be run as root.
# capture input args; note that args[0] == $@[1] (this script name is not captured here)
args=("$@");
# redirect args to svnadmin in all cases - this script should not modify the behavior of svnadmin.
# note: the original binary "/binary_path/svnadmin" has been renamed "/binary_path/svnadmin-wrapped" and
# this script was then named "/binary_path/svnadmin" and given identical user:group & permissions as
# the original.
sudo -u svnuser svnadmin-wrapped ${args[@]};
# capture return code so we can return on exit; svnadmin returns 0 for success
eCode=$?;
# find out if sub-command to svnadmin was "create" and, if so, note the index of the directory arg,
# which is not necessarily going to be in the same position each time (options may be specified
# before the sub-command).
path_idx=0;
found=0;
for i in ${args[@]}
do
# track index; pre-incerement
((path_idx++));
if [ $i == "create" ]
then
# found repo path
((found++));
break;
fi
done
# we now know if the subcommand was create and where the repo path is - finish up as needed.
# note that this block assumes that our hook file stubs are /stub_path/ (owned by root)
# and that there exists a custom log file at /stub_path/cust-log (also owned by root).
d=`date`;
if [ $found != 0 ]
then
# check that the command succeeded
if [ $eCode == 0 ]
then
# check that the directory exists
if [ -d "${args[$path_idx]}/hooks" ]
then
# copy our custom hooks into place
sudo -u svnuser cp "/stub_path/post-commit" "${args[$path_idx]}/hooks/post-commit";
sudo -u svnuser cp "/stub_path/post-revprop-change" "${args[$path_idx]}/hooks/post-revprop-change";
else
# unlikey failure; set custom error code here; log issue
echo "$d svnadmin wrapper error: svnadmin 'create' succeeded but the 'hooks' directory was not found! Params: ${args[@]}" >> "/stub_path/cust-log";
let "eCode=1325";
fi
else
# tried to create but svnadmin failed; log issue
echo "$d svnadmin wrapper error: svnadmin 'create' was called but failed! Params: ${args[@]}" >> "/stub_path/cust-log";
fi
fi
exit $eCode;
- 感谢所有主持和发帖的人!