Skip to content

Commit 858fa09

Browse files
committed
Introduce BareRepositoryException
1 parent abdcc6c commit 858fa09

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using LibGit2Sharp.Core;
4+
5+
namespace LibGit2Sharp
6+
{
7+
/// <summary>
8+
/// The exception that is thrown when an operation which requires a
9+
/// working directory is performed against a bare repository.
10+
/// </summary>
11+
[Serializable]
12+
public class BareRepositoryException : LibGit2SharpException
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref = "LibGit2Sharp.BareRepositoryException" /> class.
16+
/// </summary>
17+
public BareRepositoryException()
18+
{
19+
}
20+
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref = "LibGit2Sharp.BareRepositoryException" /> class with a specified error message.
23+
/// </summary>
24+
/// <param name = "message">A message that describes the error. </param>
25+
public BareRepositoryException(string message)
26+
: base(message)
27+
{
28+
}
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref = "LibGit2Sharp.BareRepositoryException" /> class with a specified error message and a reference to the inner exception that is the cause of this exception.
32+
/// </summary>
33+
/// <param name = "message">The error message that explains the reason for the exception. </param>
34+
/// <param name = "innerException">The exception that is the cause of the current exception. If the <paramref name = "innerException" /> parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.</param>
35+
public BareRepositoryException(string message, Exception innerException)
36+
: base(message, innerException)
37+
{
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref = "LibGit2Sharp.AmbiguousException" /> class with a serialized data.
42+
/// </summary>
43+
/// <param name = "info">The <see cref="SerializationInfo "/> that holds the serialized object data about the exception being thrown.</param>
44+
/// <param name = "context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
45+
protected BareRepositoryException(SerializationInfo info, StreamingContext context)
46+
: base(info, context)
47+
{
48+
}
49+
50+
internal BareRepositoryException(string message, GitErrorCode code, GitErrorCategory category)
51+
: base(message, code, category)
52+
{
53+
}
54+
}
55+
}

LibGit2Sharp/Core/Ensure.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@ public static void Success(int result, bool allowPositiveResult = false)
7676
errorMessage = Utf8Marshaler.FromNative(error.Message);
7777
}
7878

79-
throw new LibGit2SharpException(errorMessage, (GitErrorCode)result, error.Category);
79+
switch (result)
80+
{
81+
case (int)GitErrorCode.BareRepo:
82+
throw new BareRepositoryException(errorMessage, (GitErrorCode)result, error.Category);
83+
84+
default:
85+
throw new LibGit2SharpException(errorMessage, (GitErrorCode)result, error.Category);
86+
}
8087
}
8188

8289
/// <summary>

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
</ItemGroup>
5757
<ItemGroup>
5858
<Compile Include="AmbiguousException.cs" />
59+
<Compile Include="BareRepositoryException.cs" />
5960
<Compile Include="Blob.cs" />
6061
<Compile Include="BlobExtensions.cs" />
6162
<Compile Include="Branch.cs" />

0 commit comments

Comments
 (0)