83390

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

Question:

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?

Answer1:

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

Answer2:

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 <a href="http://jenkins-ci.org" rel="nofollow">Jenkins</a>.

Jenkins is a continuous build server, but you can use it even if you don't have a <em>build</em>. 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 <em>build</em> 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.

Recommend

  • On which thread JavaFX change listeners are executed ?
  • Ruby and class variables in inherit class
  • Insertion large number of Entities into SQL Server 2012 [duplicate]
  • Not able to display correct data in table -AngularJS
  • Angular - routerLinkActive and queryParams handling
  • Changing Jupyter Notebook start up folder by modifying “start in” not working any more
  • how to populate a SQLite database and use that database in phonegap?
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • Most efficient way to move table rows from one table to another
  • Why are YouTube videos using 'youtube.com/v' not loading
  • In-place sed command not working
  • How to set elevation color?
  • perl, mysql - fasting way to upload a csv file into mysql?
  • Question about instantiating object
  • Why cepheus don't send int without quotes to orion?
  • How to make jdk.nashorn.api.scripting.JSObject visible in plugin [duplicate]
  • Installing iPhone App to iPhone
  • Jackson Parser: ignore deserializing for type mismatch
  • Email verification using google app script and google forms
  • NHibernate Validation Localization with S#arp Architecture
  • How to delay loading a property with linq to sql external mapping?
  • Installing Hadoop, Java Exception about illegal characters at index 7?
  • Spring Data JPA custom method causing PropertyReferenceException
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • Optimizing database types to compact database (SQLite)
  • How to add date and time under each post in guestbook in google app engine
  • Excel - Autoshape get it's name from cell (value)
  • Cross-Platform Protobuf Serialization
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Do I've to free mysql result after storing it?
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • 0x202A in filename: Why?
  • Arrays break string types in Julia
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • File not found error Google Drive API
  • Turn off referential integrity in Derby? is it possible?
  • How can I remove ASP.NET Designer.cs files?
  • java string with new operator and a literal