From ac524f36fcb1840ec1fa54b394a7510a74c63306 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 28 May 2015 15:18:07 -0400 Subject: Introduce CheckoutConflictException Rename MergeConflictException to CheckoutConflictException, as merge conflicts are not a failure, only checkout conflicts are a failure. --- LibGit2Sharp.Tests/CheckoutFixture.cs | 8 ++--- LibGit2Sharp.Tests/MergeFixture.cs | 4 +-- LibGit2Sharp/CheckoutConflictException.cs | 56 +++++++++++++++++++++++++++++++ LibGit2Sharp/Core/Ensure.cs | 2 +- LibGit2Sharp/Core/GitErrorCode.cs | 5 +-- LibGit2Sharp/LibGit2Sharp.csproj | 3 +- LibGit2Sharp/MergeConflictException.cs | 53 +++++------------------------ 7 files changed, 76 insertions(+), 55 deletions(-) create mode 100644 LibGit2Sharp/CheckoutConflictException.cs diff --git a/LibGit2Sharp.Tests/CheckoutFixture.cs b/LibGit2Sharp.Tests/CheckoutFixture.cs index 9e95b922..c91f1d69 100644 --- a/LibGit2Sharp.Tests/CheckoutFixture.cs +++ b/LibGit2Sharp.Tests/CheckoutFixture.cs @@ -266,7 +266,7 @@ namespace LibGit2Sharp.Tests // Assert that normal checkout throws exception // for the conflict. - Assert.Throws(() => repo.Checkout(master.CanonicalName)); + Assert.Throws(() => repo.Checkout(master.CanonicalName)); // Checkout with force option should succeed. repo.Checkout(master.CanonicalName, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force}); @@ -304,11 +304,11 @@ namespace LibGit2Sharp.Tests // Assert that checking out master throws // when there are unstaged commits - Assert.Throws(() => repo.Checkout("master")); + Assert.Throws(() => repo.Checkout("master")); // And when there are staged commits repo.Stage(originalFilePath); - Assert.Throws(() => repo.Checkout("master")); + Assert.Throws(() => repo.Checkout("master")); } } @@ -505,7 +505,7 @@ namespace LibGit2Sharp.Tests CheckoutNotifyFlags = notifyFlags, }; - Assert.Throws(() => repo.Checkout("master", options)); + Assert.Throws(() => repo.Checkout("master", options)); Assert.True(wasCalled); Assert.Equal(expectedNotificationPath, actualNotificationPath); diff --git a/LibGit2Sharp.Tests/MergeFixture.cs b/LibGit2Sharp.Tests/MergeFixture.cs index b3bb432b..2153e85e 100644 --- a/LibGit2Sharp.Tests/MergeFixture.cs +++ b/LibGit2Sharp.Tests/MergeFixture.cs @@ -584,7 +584,7 @@ namespace LibGit2Sharp.Tests // Merging the fast_forward branch results in a change to file // b.txt. In this test we modify the file in the working directory // and then attempt to perform a merge. We expect the merge to fail - // due to merge conflicts. + // due to checkout conflicts. string committishToMerge = "fast_forward"; using (var repo = new Repository(SandboxMergeTestRepo())) @@ -596,7 +596,7 @@ namespace LibGit2Sharp.Tests repo.Stage("b.txt"); } - Assert.Throws(() => repo.Merge(committishToMerge, Constants.Signature, new MergeOptions() { FastForwardStrategy = strategy })); + Assert.Throws(() => repo.Merge(committishToMerge, Constants.Signature, new MergeOptions() { FastForwardStrategy = strategy })); } } diff --git a/LibGit2Sharp/CheckoutConflictException.cs b/LibGit2Sharp/CheckoutConflictException.cs new file mode 100644 index 00000000..9bd525ca --- /dev/null +++ b/LibGit2Sharp/CheckoutConflictException.cs @@ -0,0 +1,56 @@ +using System; +using System.Runtime.Serialization; +using LibGit2Sharp.Core; + +namespace LibGit2Sharp +{ + /// + /// The exception that is thrown when a checkout cannot be performed + /// because of a conflicting change staged in the index, or unstaged + /// in the working directory. + /// + [Serializable] + public class CheckoutConflictException : LibGit2SharpException + { + /// + /// Initializes a new instance of the class. + /// + 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 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/Core/Ensure.cs b/LibGit2Sharp/Core/Ensure.cs index 343fc188..bc9e4550 100644 --- a/LibGit2Sharp/Core/Ensure.cs +++ b/LibGit2Sharp/Core/Ensure.cs @@ -97,7 +97,7 @@ namespace LibGit2Sharp.Core { GitErrorCode.InvalidSpecification, (m, r, c) => new InvalidSpecificationException(m, r, c) }, { GitErrorCode.UnmergedEntries, (m, r, c) => new UnmergedIndexEntriesException(m, r, c) }, { GitErrorCode.NonFastForward, (m, r, c) => new NonFastForwardException(m, r, c) }, - { GitErrorCode.MergeConflict, (m, r, c) => new MergeConflictException(m, r, c) }, + { GitErrorCode.Conflict, (m, r, c) => new CheckoutConflictException(m, r, c) }, { GitErrorCode.LockedFile, (m, r, c) => new LockedFileException(m, r, c) }, { GitErrorCode.NotFound, (m, r, c) => new NotFoundException(m, r, c) }, { GitErrorCode.Peel, (m, r, c) => new PeelException(m, r, c) }, diff --git a/LibGit2Sharp/Core/GitErrorCode.cs b/LibGit2Sharp/Core/GitErrorCode.cs index 59ba1b15..a6c44e68 100644 --- a/LibGit2Sharp/Core/GitErrorCode.cs +++ b/LibGit2Sharp/Core/GitErrorCode.cs @@ -56,9 +56,10 @@ InvalidSpecification = -12, /// - /// A conflicting change has been detected. + /// A conflicting change has been detected in the index + /// or working directory. /// - MergeConflict = -13, + Conflict = -13, /// /// A file operation failed because the file was locked. diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 1b630e57..4b7bfd93 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -105,6 +105,7 @@ + @@ -228,7 +229,7 @@ - + diff --git a/LibGit2Sharp/MergeConflictException.cs b/LibGit2Sharp/MergeConflictException.cs index 69ce3d6b..edcd5ebb 100644 --- a/LibGit2Sharp/MergeConflictException.cs +++ b/LibGit2Sharp/MergeConflictException.cs @@ -1,55 +1,18 @@ using System; -using System.Runtime.Serialization; -using LibGit2Sharp.Core; +using System.Collections.Generic; +using System.Linq; +using System.Text; namespace LibGit2Sharp { /// - /// The exception that is thrown when a merge cannot be performed because - /// of a conflicting change. + /// The exception that is thrown when a checkout cannot be performed + /// because of a conflicting change staged in the index, or unstaged + /// in the working directory. /// [Serializable] - public class MergeConflictException : LibGit2SharpException + [Obsolete("This type will be removed in the next release. Please use CheckoutConflictException instead.")] + public class MergeConflictException : CheckoutConflictException { - /// - /// 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 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) - { - } } } -- cgit v1.2.3