如何使用SharpSVN访问预提交挂钩中的文件信息 [英] How to access file information in a pre-commit hook using SharpSVN
问题描述
总体来说,我对SharpSVN和SVN还是陌生的.我正在尝试实现一个预提交钩子,该钩子在用户提交某种类型的XML文件时提供;在允许提交文件之前,我将需要截取文件并对其进行分析,以确保它们包含某些元素.
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 the file and analyze it to ensure they included certain elements before I allow the file to be committed.
由于SVN似乎提交了两个参数;仓库路径和交易;我将需要使用这两项来拦截文件.有人知道我需要在SharpSVN中使用这两个参数来获取文件信息吗?
Since it seems that SVN submits two arguments; the repository path and the transaction; I will need to use these two items to intercept the file. Does anyone know what I need to use in SharpSVN to get file information based on these two parameters?
谢谢, 跳蚤#
推荐答案
您可以使用内置的SvnLookClient
来实现.
You can do this by using the builtin SvnLookClient
.
要使用此功能,首先需要一个SvnLookOrigin
. SharpSvn包含标准参数解析,可以知道"将哪些参数传递给每种类型的挂钩.这使您可以访问此SvnLookOrigin
:
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);
}
}
}
编辑:写入Console.Error
和Environment.Exit(1)
以报告错误(退出为非null).
Edit: Write to Console.Error
and Environment.Exit(1)
to report errors (exit non-null).
这篇关于如何使用SharpSVN访问预提交挂钩中的文件信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!