How to access file information in a pre-commit hook using SharpSVN

前端 未结 1 974
挽巷
挽巷 2021-01-07 01:21

I am new to SharpSVN and SVN in general. I am trying to implement a pre-commit hook that when the user commits a certain type of XML file; I am going to need to intercept th

相关标签:
1条回答
  • 2021-01-07 01:42

    You can do this by using the builtin SvnLookClient.

    To use this, first of all you need a SvnLookOrigin. SharpSvn contains standard argument parsing that 'knows' what arguments are passed to each type of hook. This gives you access to this SvnLookOrigin:

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

    Getting the changed files and contents of those files based on the parsed arguments

    using (SvnLookClient cl = new SvnLookClient())
    {
        Collection<SvnChangedEventArgs> changedItems;
        cl.GetChanged(ha.LookOrigin, out changedItems);
    
        foreach(var item in changedItems)
        {
            if(!IsXmlFile(item)) continue;
    
            using(MemoryStream ms = new MemoryStream())
            {
                cl.Write(ha.LookOrigin, item.Path, stream);
    
                VerifyXMLStream(stream);
            }
        }
    }
    

    Edit: Write to Console.Error and Environment.Exit(1) to report errors (exit non-null).

    0 讨论(0)
提交回复
热议问题