svn post-commit hook : update only if certain file has changed

China☆狼群 提交于 2019-12-08 20:04:25

not sure if this is the most efficient way, and also this the first case will technically work on a file called "pushLive.txt" regardless of dir, so you might wanna play with that or make sure file is unique...

#!/bin/sh

LOOK=/usr/bin/svnlook
REPOS="$1"
REV="$2"

for changes in `$LOOK changed $REPOS | awk '{print $1 "=" $2;}'`;
do

  idx=`expr index "$changes" =`;
  directory=${changes:$idx};
  action=${changes:0:$idx-1};

  case "$directory" in
    *pushLive.txt )
      case "$action" in
        "U" )
           svn update /var/www/dev/test/public
           ;;
      esac
      ;;
  esac
done

exit 0

I wouldn't do this through a post-commit hook since an update can take a long time. That means users have to wait around for your update to complete before they get control of their workstations again.

Take a look at Jenkins.

Jenkins is a continuous build server, but you can use it even if you don't have a build. In your case, you can use it to watch the Subversion repository for the live domain. When Jenkins detects a commit upon that Subversion URL, it can spawn a build process. In your case, it would be updating the files on the live server.

If your server is the same machine running Jenkins, you could easily specify the Jenkins Working directory to be the /var/www/live/public directory. (By default, Jenkins will create the build directory under $JENKINS_HOME/jobs/<jobname>/workspace, but there's an option in Jenkins where you can specify it). Then, there's no programming involved at all. This is faster and easier than playing around with a post-commit hook.

By the way, if you take this route, I suggest you create a new update to a clean directory, then rename the directory. Otherwise, as Subversion updates your server, you'll have files from the previous and present Subversion revision at the same time. This could cause problems if someone was on the server while the update is occurring.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!