Best strategy to write hooks for subversion in Windows *

Question

What is the best approach to write hooks for Subversion in Windows? As far as I know, only executable files can be used. So what is the best choice?

  • Plain batch files (very limited but perhaps OK for very simple solutions)
  • Dedicated compiled executable applications (sledgehammer to crack a nutshell?)
  • Some other hybrid choice (like a batch file running a Powershell script)

Answer

I’ve just spent several days procrastinating about exactly this question. There are third party products available and plenty of PERL and Python scripts but I wanted something simple and a language I was familiar with so ended up just writing hooks in a C# console app. It’s very straight forward:

public void Main(string[] args)
{
  string repositories = args[0];
  string transaction = args[1];

  var processStartInfo = new ProcessStartInfo
                           {
                             FileName = "svnlook.exe",
                             UseShellExecute = false,
                             CreateNoWindow = true,
                             RedirectStandardOutput = true,
                             RedirectStandardError = true,
                             Arguments = String.Format("log -t \"{0}\" \"{1}\"", transaction, repositories)
                           };

  var p = Process.Start(processStartInfo);
  var s = p.StandardOutput.ReadToEnd();
  p.WaitForExit();

  if (s == string.Empty)
  {
    Console.Error.WriteLine("Message must be provided");
    Environment.Exit(1);
  }

  Environment.Exit(0);
}

You can then invoke this on pre commit by adding a pre-commit.cmd file to the hooks folder of the repo with the following line:

[path]\PreCommit.exe %1 %2

You may consider this overkill but ultimately it’s only a few minutes of coding. What’s more, you get the advantage of the .NET language suite which IMHO is far preferable to the alternatives. I’ll expand my hooks out significantly and write appropriate tests against them as well – bit hard to do this with a DOS batch file!

BTW, the code has been adapted from this post.

< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/5134/" >Best strategy to write hooks for subversion in Windows< /a>
Share on Google Plus

About Cinema Guy

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment