Setting commit author in SharpSvn .NET library throws SvnRepisitoryIOException exception

家住魔仙堡 提交于 2019-12-11 07:58:20

问题


If you have experience with using the SharpSvn .NET library, I could use your expertise in setting the commit author during an SVN commit. I've tried a few things, but they all throw an SvnRepisitoryIOException unless the user is saved in TortoiseSVN. However, I want to use different user credentials depending on the situation. If I've saved a user's default credentials, TortoiseSVN remembers them in Settings > Saved Data > Authenticated Data, and is able to commit a file using that authenticated user as the commit author. If you click "Clear" here, SharpSVN won't know who to authenticate during a commit.

Assume you have these directives in your class: using SharpSvn; using SharpSvn.Security; I'm using the free version of VisualSVN server for Windows. And I have two users, one being named "user1" and password of "pass1" to keep things simple in the examples below that failed.

How can I prevent this exception from being thrown and commit using different users for the author (in my log of the commit)?

Attempt #1:

    using (SvnClient client = new SvnClient())
    { 
        client.Authentication.Clear();  // Clear a previous authentication 
        client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("user1", "pass1");

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }

Attempt #2:

    using (SvnClient client = new SvnClient())
    {
        client.SetProperty(("", "svn:author", "user1");

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }

Attempt #3:

    using (SvnClient client = new SvnClient())
    {
        client.Authentication.Clear(); // Clear predefined handlers
        client.Authentication.UserNamePasswordHandlers
            += delegate(object obj, SharpSvn.Security.SvnUserNamePasswordEventArgs args)
        {
            args.UserName = "user1";
            args.Password = "pass1";
        }; 

        SvnCommitArgs ca = new SvnCommitArgs();
        ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
        bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);
    }

回答1:


After getting the stack trace when running the application as an administrator, I was able to catch the exception using the framework and accept the non trusted certificate issuer.

*Unhandled Exception: SharpSvn.SvnRepositoryIOException: Commit Failed (details follow): ===> SharpSvn.SvnRepositoryIOException: Unable to connect to a repository at URL 'https://mycomputer/svn/demo_repo/demo_project/trunk/file.txt' --> SharpSvn.SvnRepositoryIOException: OPTIONS of '': Server certificate verification failed: issuer is not trusted (https://mycomputer) --- End of inner exception stack trace --- --- End of inner exception stack trace --- at SharpSvn.SvnClientArgs.HandleResult(SvnClientContext client, SvnException error, Object targets) at SharpSvn.SvnClientArgs.HandleResult(SvnClientContext client, svn_error_t* error, Object targets) .....*

New Code:

            client.Authentication.Clear(); // Clear predefined handlers
            client.Authentication.UserNamePasswordHandlers
                += delegate(object obj, SharpSvn.Security.SvnUserNamePasswordEventArgs args)
            {
                args.UserName = "user1";
                args.Password = "pass1";
            }; 

            client.Authentication.SslServerTrustHandlers​ +=
            delegate(object sender, SvnSslServerTrustEventArgs e)
            {
              e.AcceptedFailures = e.Failures;
              e.Save = true; // Save acceptance to authentication store
            };

            SvnCommitArgs ca = new SvnCommitArgs();
            ca.LogMessage = "svn log message created at " + DateTime.Now.ToString();
            bool action = client.Commit(@"C:\demo_repo\demo_project\trunk\file.txt", ca);


来源:https://stackoverflow.com/questions/12668389/setting-commit-author-in-sharpsvn-net-library-throws-svnrepisitoryioexception-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!