diff --git a/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs b/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs index 4e3b03ce3..0c21b28a0 100644 --- a/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs +++ b/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs @@ -77,6 +77,28 @@ public void CustomSmartSubtransportTest(string scheme, string url) } } + [Fact] + public void ExceptionPropogationTest() + { + var scd = BuildSelfCleaningDirectory(); + var url = "https://github.com/libgit2/TestGitRepository"; + + SmartSubtransportRegistration registration = null; + + try + { + registration = GlobalSettings.RegisterSmartSubtransport("https"); + Assert.NotNull(registration); + + var thrownException = Assert.Throws(() => Repository.Clone(url, scd.RootedDirectoryPath)); + Assert.True(thrownException.Message.Contains("This is a Read Exception"), "Exception message did not contain expected reference."); + } + finally + { + GlobalSettings.UnregisterSmartSubtransport(registration); + } + } + //[Theory] //[InlineData("https", "https://bitbucket.org/libgit2/testgitrepository.git", "libgit3", "libgit3")] //public void CanUseCredentials(string scheme, string url, string user, string pass) @@ -159,6 +181,32 @@ public void CannotUnregisterTwice() GlobalSettings.UnregisterSmartSubtransport(httpRegistration)); } + private class FailingSmartSubtransport : RpcSmartSubtransport + { + protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action) + { + return new FailingSmartSubtransportStream(this); + } + + private class FailingSmartSubtransportStream : SmartSubtransportStream + { + public FailingSmartSubtransportStream(FailingSmartSubtransport parent) + : base(parent) + { + + } + public override int Read(Stream dataStream, long length, out long bytesRead) + { + throw new Exception("This is a Read Exception"); + } + + public override int Write(Stream dataStream, long length) + { + throw new NotImplementedException(); + } + } + } + private class MockSmartSubtransport : RpcSmartSubtransport { protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action) diff --git a/LibGit2Sharp/SmartSubtransportStream.cs b/LibGit2Sharp/SmartSubtransportStream.cs index 008d1fcd0..247e90f34 100644 --- a/LibGit2Sharp/SmartSubtransportStream.cs +++ b/LibGit2Sharp/SmartSubtransportStream.cs @@ -119,6 +119,10 @@ private static int SetError(SmartSubtransportStream stream, Exception caught) { errorCode = ((NativeException)ret).ErrorCode; } + else + { + Proxy.git_error_set_str(GitErrorCategory.Unknown, caught); + } return (int)errorCode; }