Search code examples
c#svnsharpsvnpre-commit-hook

How can i get access to the SVN pre-commit message using SharpSVN?


i see that all I can set to is %repos% and %txn%

how can I use those to get to the commit message (in my case, so i can parse out the ticket number so i can see if it exists in the bug database before committing to it)


Solution

  • Using a recent SharpSvn release you can use

    SvnHookArguments ha; 
    if (!SvnHookArguments.ParseHookArguments(args, SvnHookType.PreCommit, false, out ha))
    {
        Console.Error.WriteLine("Invalid arguments");
        Environment.Exit(1);  
    }
    

    to parse the arguments of a pre-commit hook and then use

    using (SvnLookClient cl = new SvnLookClient())
    {
        SvnChangeInfoEventArgs ci;
    
        cl.GetChangeInfo(ha.LookOrigin, out ci);
    
    
        // ci contains information on the commit e.g.
        Console.WriteLine(ci.LogMessage); // Has log message
    
        foreach (SvnChangeItem i in ci.ChangedPaths)
        {
    
        }
    }
    

    to get to the log message, changed files, etc.