diff --git a/LibGit2Sharp.Tests/CheckoutFixture.cs b/LibGit2Sharp.Tests/CheckoutFixture.cs index 80cb9727d..132cb68ec 100644 --- a/LibGit2Sharp.Tests/CheckoutFixture.cs +++ b/LibGit2Sharp.Tests/CheckoutFixture.cs @@ -1029,6 +1029,23 @@ public void CanCheckoutPathFromCurrentBranch(string fileName) } } + [Fact] + public void CanCatchDeprecatedException() + { + bool caught = false; + + try + { + throw new CheckoutConflictException(); + } + catch (MergeConflictException) + { + caught = true; + } + + Assert.True(caught); + } + /// /// Helper method to populate a simple repository with /// a single file and two branches. diff --git a/LibGit2Sharp/CheckoutConflictException.cs b/LibGit2Sharp/CheckoutConflictException.cs index a06360afb..811e2183a 100644 --- a/LibGit2Sharp/CheckoutConflictException.cs +++ b/LibGit2Sharp/CheckoutConflictException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; using LibGit2Sharp.Core; namespace LibGit2Sharp @@ -10,7 +9,7 @@ namespace LibGit2Sharp /// in the working directory. /// [Serializable] - public class CheckoutConflictException : LibGit2SharpException + public class CheckoutConflictException : MergeConflictException { /// /// Initializes a new instance of the class. @@ -18,41 +17,6 @@ public class CheckoutConflictException : LibGit2SharpException public CheckoutConflictException() { } - /// - /// Initializes a new instance of the class with a specified error message. - /// - /// A message that describes the error. - public CheckoutConflictException(string message) - : base(message) - { } - - /// - /// Initializes a new instance of the class with a specified error message. - /// - /// A composite format string for use in . - /// An object array that contains zero or more objects to format. - public CheckoutConflictException(string format, params object[] args) - : base(format, args) - { } - - /// - /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - /// - /// The error message that explains the reason for the exception. - /// The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception. - public CheckoutConflictException(string message, Exception innerException) - : base(message, innerException) - { } - - /// - /// Initializes a new instance of the class with a serialized data. - /// - /// The that holds the serialized object data about the exception being thrown. - /// The that contains contextual information about the source or destination. - protected CheckoutConflictException(SerializationInfo info, StreamingContext context) - : base(info, context) - { } - internal CheckoutConflictException(string message, GitErrorCode code, GitErrorCategory category) : base(message, code, category) { } diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index c2fc74e2e..d73b2b8ae 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -122,7 +122,7 @@ - + @@ -249,7 +249,7 @@ - + diff --git a/LibGit2Sharp/MergeConflictException.cs b/LibGit2Sharp/MergeConflictException.cs index c1eab05be..d95124dc0 100644 --- a/LibGit2Sharp/MergeConflictException.cs +++ b/LibGit2Sharp/MergeConflictException.cs @@ -1,4 +1,6 @@ using System; +using System.Runtime.Serialization; +using LibGit2Sharp.Core; namespace LibGit2Sharp { @@ -9,6 +11,51 @@ namespace LibGit2Sharp /// [Serializable] [Obsolete("This type will be removed in the next release. Please use CheckoutConflictException instead.")] - public class MergeConflictException : CheckoutConflictException - { } + public class MergeConflictException : LibGit2SharpException + { + /// + /// Initializes a new instance of the class. + /// + public MergeConflictException() + { } + + /// + /// Initializes a new instance of the class with a specified error message. + /// + /// A message that describes the error. + public MergeConflictException(string message) + : base(message) + { } + + /// + /// Initializes a new instance of the class with a specified error message. + /// + /// A composite format string for use in . + /// An object array that contains zero or more objects to format. + public MergeConflictException(string format, params object[] args) + : base(format, args) + { } + + /// + /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception. + public MergeConflictException(string message, Exception innerException) + : base(message, innerException) + { } + + /// + /// Initializes a new instance of the class with a serialized data. + /// + /// The that holds the serialized object data about the exception being thrown. + /// The that contains contextual information about the source or destination. + protected MergeConflictException(SerializationInfo info, StreamingContext context) + : base(info, context) + { } + + internal MergeConflictException(string message, GitErrorCode code, GitErrorCategory category) + : base(message, code, category) + { } + } }