使用 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