How can i write a pre-commit hook on SVN server?

85 Views Asked by At

There is a pre-commit hook in c# that i use, but this requires each client that checks out a project to add this to the repo on the local machine. Here is the code for that , its just a console app .

class Program
{
   static int Main(string[] args)
   { 
      return KeysFileCheck.CheckFiles(args[0]);
   }
}
 
public static class KeysFileCheck
{
 public static int CheckFiles(string fileList)
{
   return CheckFiles(
      File.ReadAllLines(fileList)
         .Where(path => Path.GetFileName(path) == "keys.txt")
         .ToArray());
}

 private static int CheckFiles(string[] keyFiles)
 {
   var result = 0;
  foreach (var keyFile in keyFiles)
  {
     using (var fs = new FileStream(keyFile, FileMode.Open, FileAccess.Read))
     {
        result |= CheckKeyFile(keyFile, fs);
     }
  }
  return result;

}

private static int CheckKeyFile(string filename, Stream stream)
{
  using (var sr = new StreamReader(stream))
  {
     var data = sr.ReadToEnd();
     if (!String.IsNullOrEmpty(data))
     {
        Console.Error.WriteLine(
           "The keys file {0} cannot be saved with data in it as the build server will 
      fail to build the solution", filename);
        return 1;
     }
  }
    return 0;
  }
}
 

There is currenltly a pre-commit.tmpl file on the SVN Server and if i add the following

grep “[a-zA-Z0-9]” > /dev/null || echo “A commit message is required”>&2 && exit 1 and

rename it to just pre-commit and restart , users are required to enter a commit message, thats fine. But how can i add the above code to my pre-commit file on the SVN Server ? I tried to right click on the repo directory and go to settings and add a hook but doesnt have an option there Any ideas on this ?

0

There are 0 best solutions below