C# SVN Pre Commit Hook,SharpSvn 错误

发布于 2024-10-18 17:21:15 字数 2654 浏览 6 评论 0原文

我有一个 C# 控制台应用程序,用作 SVN Pre Commit Hook。控制台应用程序完美启动。但是,当我尝试使用 SharpSvn 进行写入时,我收到此错误:

Commit failed (details follow):
Commit blocked by pre-commit hook (exit code -1066598274) with output:

Unhandled Exception: System.Runtime.InteropServices.SEHException: External 
component has thrown an exception.
at svn_client_cat2(svn_stream_t* , SByte* , svn_opt_revision_t* , 
svn_opt_revision_t* , svn_client_ctx_t* , apr_pool_t* )
at SharpSvn.SvnClient.Write(SvnTarget target, Stream output, SvnWriteArgs args)
   at SharpSvn.SvnClient.Write(SvnTarget target, Stream output)
   at SvnPreCommitHook.Program.Main(String[] args)

我尝试从自己的计算机执行 svn.Write 命令,指向 svn://svn-server 而不是 localhost - 并且可以正常工作美好的。我猜这是服务器上的东西。 TortoiseSVN 已安装,尽管我没有看到任何上下文菜单...

我的代码如下所示:

private static EventLog _serviceEventLog;

static void Main(string[] args)
{
    _serviceEventLog = new EventLog();

    if (!System.Diagnostics.EventLog.SourceExists("Svn Hooks"))
    {
        System.Diagnostics.EventLog.CreateEventSource("Svn Hooks", "Svn Hooks");
    }

    _serviceEventLog.Source = "Svn Hooks";
    _serviceEventLog.Log = "Svn Hooks";

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

    using (SvnLookClient cl = new SvnLookClient())
    {
        SvnChangeInfoEventArgs ci;
        cl.GetChangeInfo(ha.LookOrigin, out ci);

        if (!ci.LogMessage.Equals("Svn Hook Test"))
        {
            AllowCommit();

            return;
        }

        var checkoutDir = @"C:\SvnTemp\" + DateTime.Now.Ticks.ToString();

        foreach (SvnChangeItem i in ci.ChangedPaths)
        {
            var checkoutFilepath = checkoutDir + "\\" + Path.GetFileName(i.Path);

            if (!Directory.Exists(checkoutDir))
            {
                Directory.CreateDirectory(checkoutDir);
            }

            using (SvnClient svn = new SvnClient())
            {
                using (StreamWriter sw = new StreamWriter(checkoutFilepath))
                {
                    svn.Write(SvnTarget.FromString("svn://localhost/" + i.RepositoryPath), sw.BaseStream);
                }
            }

            var fileContents = File.ReadAllText(checkoutFilepath);

            if (fileContents.Contains("Martin Normark"))
            {
                RemoveTempDirectory(checkoutDir);

                PreventCommit("Name is not allowed!");
            }
        }

        RemoveTempDirectory(checkoutDir);
    }

    AllowCommit();
}

I have a C# console application that I use as an SVN Pre Commit Hook. The console app is started perfectly. However, as soon as I try to do a Write using SharpSvn, I get this error:

Commit failed (details follow):
Commit blocked by pre-commit hook (exit code -1066598274) with output:

Unhandled Exception: System.Runtime.InteropServices.SEHException: External 
component has thrown an exception.
at svn_client_cat2(svn_stream_t* , SByte* , svn_opt_revision_t* , 
svn_opt_revision_t* , svn_client_ctx_t* , apr_pool_t* )
at SharpSvn.SvnClient.Write(SvnTarget target, Stream output, SvnWriteArgs args)
   at SharpSvn.SvnClient.Write(SvnTarget target, Stream output)
   at SvnPreCommitHook.Program.Main(String[] args)

I have tried to do the svn.Write command from my own machine, pointing to svn://svn-server instead of localhost - and that works fine. I guess it is something on the server. TortoiseSVN is installed, although I don't see any context menus...

My code looks like this:

private static EventLog _serviceEventLog;

static void Main(string[] args)
{
    _serviceEventLog = new EventLog();

    if (!System.Diagnostics.EventLog.SourceExists("Svn Hooks"))
    {
        System.Diagnostics.EventLog.CreateEventSource("Svn Hooks", "Svn Hooks");
    }

    _serviceEventLog.Source = "Svn Hooks";
    _serviceEventLog.Log = "Svn Hooks";

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

    using (SvnLookClient cl = new SvnLookClient())
    {
        SvnChangeInfoEventArgs ci;
        cl.GetChangeInfo(ha.LookOrigin, out ci);

        if (!ci.LogMessage.Equals("Svn Hook Test"))
        {
            AllowCommit();

            return;
        }

        var checkoutDir = @"C:\SvnTemp\" + DateTime.Now.Ticks.ToString();

        foreach (SvnChangeItem i in ci.ChangedPaths)
        {
            var checkoutFilepath = checkoutDir + "\\" + Path.GetFileName(i.Path);

            if (!Directory.Exists(checkoutDir))
            {
                Directory.CreateDirectory(checkoutDir);
            }

            using (SvnClient svn = new SvnClient())
            {
                using (StreamWriter sw = new StreamWriter(checkoutFilepath))
                {
                    svn.Write(SvnTarget.FromString("svn://localhost/" + i.RepositoryPath), sw.BaseStream);
                }
            }

            var fileContents = File.ReadAllText(checkoutFilepath);

            if (fileContents.Contains("Martin Normark"))
            {
                RemoveTempDirectory(checkoutDir);

                PreventCommit("Name is not allowed!");
            }
        }

        RemoveTempDirectory(checkoutDir);
    }

    AllowCommit();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眉黛浅 2024-10-25 17:21:15

可能是以下情况之一:

  • 64 位与 32 位vcredist
  • 服务器上缺少

Maybe one of the following:

  • 64bit vs 32 bit
  • vcredist missing on the server
意中人 2024-10-25 17:21:15

也许您应该首先使用 HandleProcessCorruptedStateExceptionsAttribute

[HandleProcessCorruptedStateExceptions] 
static void Main() // main entry point
{
    try 
    {

    }
    catch (Exception ex)
    {
        // Handle Exception here ...
    }
}

Maybe you should first catch the thrown exception by using the HandleProcessCorruptedStateExceptionsAttribute:

[HandleProcessCorruptedStateExceptions] 
static void Main() // main entry point
{
    try 
    {

    }
    catch (Exception ex)
    {
        // Handle Exception here ...
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文