简体   繁体   中英

How to listen to svn commit event on working directory on developer/client machine?

I need to write a node.js program that will somehow get triggered anytime a developer checks in code into svn. This will update a file in the working directory. The developers work on Mac OS X and Windows. The program needs to run on both machines.

Is there a way I can somehow listen to svn client's commit? Are there any sdk for svn that allows plugin/extension? Will watching .svn hidden directory (that svn creates for its own use) for changes do it? if so, how can I know by looking at this directory that a file was committed?

At first I thought hooks might be the way to go but hooks are run on the machine that host's svn and they are mostly for admin tasks such as sending email alerts or kicking off builds

First you need to understand that there is no way to know whether an update has occurred on the server without connecting to the server. Hence you cannot do it simply by looking at the local folders because that is not how svn works.

A workaround to achieve what you want would be the following. On the server, write a "post-commit" hook that takes a counter from a text file, increments it, and writes it back. Deposit this text file somewhere where your clients can download it. I'm going to assume this will be on "http://www.example.com/commit-id.txt". Then, on the clients, use a shell script that monitors this text file for changes and executes the desired action. Using windows powershell, for instance, this could work as follows. For Mac you need to use a different shell but I'm sure this script could be easily ported.

function get-current-commit-id {
        trap [Exception] {
                # Make sure the script doesn't freak out when server is down or connection
                $commitid
                return
        }
        # The rand.next() ensures by brute force that the text file is not cached
        [int] $clnt.DownloadString("http://www.example.com/commit-id.txt?q="+$rand.next())
}

$clnt = new-object System.Net.WebClient
$commitid = get-current-commit-id

while( 1 ){
        $commitidnew = get-current-commit-id
        if( $commitidnew -ne $rsid ){
                Write-Output "Commit occured on server"

                ### execute desired action here
                ### perhaps you'll also want to run "svn up"

                $commitid = $rsidnew
        }
        ### check for new update every 10 seconds
        sleep 10
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM