使用 SVN post-commit 钩子同步更新代码


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

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM