SVN的“钩子”脚本在代码版本库的hooks子目录下,该目录下已有一批 *.tmpl 的“钩子”脚本模版文件,复制 post-commit.tmpl 到 post-commit 文件,在文件中写入需要在 SVN Server 处理完提交操作后执行的shell命令,一般多为通知提醒或者代码自动同步等动作。

 

下面是一份自动同步更新代码到指定工作版本目录的示例脚本:

REPOS="$1"    # 版本库目录 /data2/svnrepos/rain
REV="$2"      # revision number

# 若是edward提交的则不执行同步操作
AUTHOR=`/data2/subversion/bin/svnlook author -r $REV $REPOS`    # 执行提交的用户名
if [ "$AUTHOR" == "edward" ] ; then
  exit;
fi

TIME=`date '+%F %T'`
echo "[$TIME]--[$AUTHOR] svn commit file:" >> /data2/logs/svn_rain_update.log

# 将修改了的文件同步更新到目标版本库
for updatePath in `/data2/subversion/bin/svnlook changed -r $REV $REPOS | awk '{print $2}'`
do
  fullUpdatePath="/data2/rain/$updatePath"
  /data2/subversion/bin/svn update --username xxx --password xxx $fullUpdatePath >> /data2/logs/svn_rain_update.log
  chmod g+w $fullUpdatePath
done

 

常见问题

1. Warning: post-commit hook failed (exit code 255) with no output.

如果执行提交时SVN提示255错误,则是 post-commit 脚本文件的权限不对,post-commit 脚本必须有 +x 权限。

chown svn:svn post-commit
chmod +x post-commit

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2022-01-01
  • 2021-05-17
  • 2021-10-14
  • 2022-01-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-02
  • 2022-12-23
  • 2021-11-30
  • 2022-01-08
相关资源
相似解决方案