Rob Chartier ~ Contemplation...

.NET, C#, Work, etc.

News






www.flickr.com
This is a Flickr badge showing public photos from Rob & Kat Chartier. Make your own badge here.


Even Quicker Links

Subversion Hooks with C#

One thing I noticed yesterday when setting up Subversion is that it has "Hook Scripts". 

"A hook is a program triggered by some repository event, such as the creation of a new revision or the modification of an unversioned property. Each hook is handed enough information to tell what that event is, what target(s) it's operating on, and the username of the person who triggered the event. Depending on the hook's output or return status, the hook program may continue the action, stop it, or suspend it in some way."

In the doc it mentions...

"Windows, however, uses file extensions to determine whether or not a program is executable, so you would need to supply a program whose basename is the name of the hook, and whose extension is one of the special extensions recognized by Windows for executable programs, such as .exe or .com for programs, and .bat for batch files."

This has to be too easy.  So I whipped up a quick C# Console Executable:

"post-commit.cs" Source Listing:
----------------------------------
using System;

namespace post_commit {
    class Class1 {
        [STAThread]
        static void Main(string[] args) {
        System.IO.StreamWriter sw = new System.IO.StreamWriter(@"f:\PostCommit.txt", true, System.Text.Encoding.Default);
            sw.Write(System.DateTime.Now.ToString() + ":" + string.Join("|", args));
            sw.Close();
        }
    }
}
----------------------------------
Now build it, "csc post-commit.cs"

Built it, and placed the .exe  into the Project\Hooks\ Folder.  Now commit any file into the repository; you should see a file f:\PostCommit.txt created.  Inspect the contents.

I wonder what cool things are being done with Hooks and subversion.  Obvious examples (in the Doc's) include triggering backups, and sending emails. 




Comments

Chad Myers said:

We've implemented a generic hook script that will load up assemblies and execute them as "plug-ins". Current we have a plug-in for sending out a nice HTML-formatted email with details about the recent commit (who did it, what they changed, the diffs, a URL to our Trac instance, etc) and another plug-in that integrates with our bug-tracking system.

We can put special XML in our SVN comments and it will do various things like mark a bug as "fixed" and associate the "fix" of the bug with the SVN revision so we can track the relationship between fixes and changes
# July 29, 2005 4:35 PM

Ricky Dhatt said:

FogBugz (bugtracker) uses Subversion hooks to link checkins to bugs.
# July 29, 2005 5:35 PM

.Net Adventures said:

Check out SubversionSharp (SVN#) - http://support.softec.st/trac/clr/wiki/SubversionSharp

SVN# is the starting point to easily integrate Subversion repositories in any .NET managed software.
# July 31, 2005 3:28 AM

Josh Blair said:

Rob, have you done any cool things with C# hook console apps?  Most of the hook scripts that are contributed seem to be in Python.  I speak C# not Python.  Thanks,

# June 11, 2007 7:55 PM

seek said:

your title is about HOOKs, but i didn't see what hooks in your content?

# August 23, 2007 2:52 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)