private static void HandleError(int result) { string errorMessage; GitError error = NativeMethods.giterr_last().MarshalAsGitError(); if (error == null) { error = new GitError { Category = GitErrorCategory.Unknown, Message = IntPtr.Zero }; errorMessage = "No error message has been provided by the native library"; } else { errorMessage = Utf8Marshaler.FromNative(error.Message); } Func <string, GitErrorCode, GitErrorCategory, LibGit2SharpException> exceptionBuilder; if (!GitErrorsToLibGit2SharpExceptions.TryGetValue((GitErrorCode)result, out exceptionBuilder)) { exceptionBuilder = (m, r, c) => new LibGit2SharpException(m, r, c); } throw exceptionBuilder(errorMessage, (GitErrorCode)result, error.Category); }
public static FilePath FromNative(IntPtr pNativeData, int length) { if (0 == length) { return(FilePath.Empty); } return(Utf8Marshaler.FromNative(pNativeData, length)); }
public static FilePath FromNative(IntPtr pNativeData) { if (IntPtr.Zero == pNativeData) { return(null); } if (0 == Marshal.ReadByte(pNativeData)) { return(FilePath.Empty); } return(Utf8Marshaler.FromNative(pNativeData)); }
private static void HandleError(int result) { string errorMessage; GitError error = NativeMethods.giterr_last().MarshalAsGitError(); if (error == null) { error = new GitError { Category = GitErrorCategory.Unknown, Message = IntPtr.Zero }; errorMessage = "No error message has been provided by the native library"; } else { errorMessage = Utf8Marshaler.FromNative(error.Message); } switch (result) { case (int)GitErrorCode.User: throw new UserCancelledException(errorMessage, (GitErrorCode)result, error.Category); case (int)GitErrorCode.BareRepo: throw new BareRepositoryException(errorMessage, (GitErrorCode)result, error.Category); case (int)GitErrorCode.Exists: throw new NameConflictException(errorMessage, (GitErrorCode)result, error.Category); case (int)GitErrorCode.InvalidSpecification: throw new InvalidSpecificationException(errorMessage, (GitErrorCode)result, error.Category); case (int)GitErrorCode.UnmergedEntries: throw new UnmergedIndexEntriesException(errorMessage, (GitErrorCode)result, error.Category); case (int)GitErrorCode.NonFastForward: throw new NonFastForwardException(errorMessage, (GitErrorCode)result, error.Category); case (int)GitErrorCode.MergeConflict: throw new MergeConflictException(errorMessage, (GitErrorCode)result, error.Category); default: throw new LibGit2SharpException(errorMessage, (GitErrorCode)result, error.Category); } }