8000 Correct the deprecation path for MergeConflictException · leoniDEV/libgit2sharp@6a4155c · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a4155c

Browse files
committed
Correct the deprecation path for MergeConflictException
We want users to be able to have the old name in their code and catch the new type which we throw. To enable this we must switch the inheritance for the old vs new type.
1 parent f8c944b commit 6a4155c

File tree

4 files changed

+69
-41
lines changed

4 files changed

+69
-41
lines changed

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,23 @@ public void CanCheckoutPathFromCurrentBranch(string fileName)
10291029
}
10301030
}
10311031

1032+
[Fact]
1033+
public void CanCatchDeprecatedException()
1034+
{
1035+
bool caught = false;
1036+
1037+
try
1038+
{
1039+
throw new CheckoutConflictException();
1040+
}
1041+
catch (MergeConflictException)
1042+
{
1043+
caught = true;
1044+
}
1045+
1046+
Assert.True(caught);
1047+
}
1048+
10321049
/// <summary>
10331050
/// Helper method to populate a simple repository with
10341051
/// a single file and two branches.

LibGit2Sharp/CheckoutConflictException.cs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Runtime.Serialization;
32
using LibGit2Sharp.Core;
43

54
namespace LibGit2Sharp
@@ -10,49 +9,14 @@ namespace LibGit2Sharp
109
/// in the working directory.
1110
/// </summary>
1211
[Serializable]
13-
public class CheckoutConflictException : LibGit2SharpException
12+
public class CheckoutConflictException : MergeConflictException
1413
{
1514
/// <summary>
1615
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class.
1716
/// </summary>
1817
public CheckoutConflictException()
1918
{ }
2019

21-
/// <summary>
22-
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message.
23-
/// </summary>
24-
/// <param name="message">A message that describes the error.</param>
25-
public CheckoutConflictException(string message)
26-
: base(message)
27-
{ }
28-
29-
/// <summary>
30-
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message.
31-
/// </summary>
32-
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
33-
/// <param name="args">An object array that contains zero or more objects to format.</param>
34-
public CheckoutConflictException(string format, params object[] args)
35-
: base(format, args)
36-
{ }
37-
38-
/// <summary>
39-
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
40-
/// </summary>
41-
/// <param name="message">The error message that explains the reason for the exception.</param>
42-
/// <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>
43-
public CheckoutConflictException(string message, Exception innerException)
44-
: base(message, innerException)
45-
{ }
46-
47-
/// <summary>
48-
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a serialized data.
49-
/// </summary>
50-
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
51-
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
52-
protected CheckoutConflictException(SerializationInfo info, StreamingContext context)
53-
: base(info, context)
54-
{ }
55-
5620
internal CheckoutConflictException(string message, GitErrorCode code, GitErrorCategory category)
5721
: base(message, code, category)
5822
{ }

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
<Compile Include="IndexReucEntryCollection.cs" />
123123
<Compile Include="IndexNameEntry.cs" />
124124
<Compile Include="MergeAndCheckoutOptionsBase.cs" />
125-
<Compile Include="MergeConflictException.cs" />
125+
<Compile Include="CheckoutConflictException.cs" />
126126
<Compile Include="MergeOptions.cs" />
127127
<Compile Include="MergeOptionsBase.cs" />
128128
<Compile Include="MergeResult.cs" />
@@ -249,7 +249,7 @@
249249
<Compile Include="FetchHead.cs" />
250250
<Compile Include="Handlers.cs" />
251251
<Compile Include="Ignore.cs" />
252-
<Compile Include="CheckoutConflictException.cs" />
252+
<Compile Include="MergeConflictException.cs" />
253253
<Compile Include="MergeHead.cs" />
254254
<Compile Include="NameConflictException.cs" />
255255
<Compile Include="NonFastForwardException.cs" />

LibGit2Sharp/MergeConflictException.cs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Runtime.Serialization;
3+
using LibGit2Sharp.Core;
24

35
namespace LibGit2Sharp
46
{
@@ -9,6 +11,51 @@ namespace LibGit2Sharp
911
/// </summary>
1012
[Serializable]
1113
[Obsolete("This type will be removed in the next release. Please use CheckoutConflictException instead.")]
12-
public class MergeConflictException : CheckoutConflictException
13-
{ }
14+
public class MergeConflictException : LibGit2SharpException
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> class.
18+
/// </summary>
19+
public MergeConflictException()
20+
{ }
21+
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> class with a specified error message.
24+
/// </summary>
25+
/// <param name="message">A message that describes the error.</param>
26+
public MergeConflictException(string message)
27+
: base(message)
28+
{ }
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> class with a specified error message.
32+
/// </summary>
33+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
34+
/// <param name="args">An object array that contains zero or more objects to format.</param>
35+
public MergeConflictException(string format, params object[] args)
36+
: base(format, args)
37+
{ }
38+
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
41+
/// </summary>
42+
/// <param name="message">The error message that explains the reason for the exception.</param>
43+
/// <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>
44+
public MergeConflictException(string message, Exception innerException)
45+
: base(message, innerException)
46+
{ }
47+
48+
/// <summary>
49+
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> class with a serialized data.
50+
/// </summary>
51+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
52+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
53+
protected MergeConflictException(SerializationInfo info, StreamingContext context)
54+
: base(info, context)
55+
{ }
56+
57+
internal MergeConflictException(string message, GitErrorCode code, GitErrorCategory category)
58+
: base(message, code, category)
59+
{ }
60+
}
1461
}

0 commit comments

Comments
 (0)
0