Search code examples
svnpost-commit-hook

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


Okay so I have an SVN repo setup on my server. I have a post-commit hook setup that updates to a "DEV" folder so that when I commit changes, it automatically pushes to my "DEV" subdomain on my server.

What I need now is an easy way to push it to my "Live" subdomain when I am ready. The "Live" subdomain is on the same server, and in reality, it would be the same svn update /... command as with the DEV, but to a different path.

I was thinking I could have a specific file in my repo, and maybe I could just change this file, and then make some sort of condition in my post-commit file to also update to my "live" dir if that specific file has changed.

But I don't know how to write that code. Currently my post-commit file looks like this:

#!/bin/sh

REPOS="$1"
REV="$2"

svn update /var/www/dev/public

I need it to basically do this (but with correct syntax, obviously)

#!/bin/sh

REPOS="$1"
REV="$2"

svn update /var/www/dev/public
if (pushLive.txt has changed) {
  svn update /var/www/live/public
}

Anybody have any suggestions?


Solution

  • 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