diff options
author | Metalrom <romain.magny@gmail.com> | 2013-01-15 13:24:58 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-01-16 21:50:15 +0400 |
commit | 5d7887e71b3ad9567e66c6269928688202050a3c (patch) | |
tree | c0eaf3d9c82396ac4f8fb3871c5eb2b2dabdd222 | |
parent | 849c21e9cc986d8716859a97f7b50fb7754065c3 (diff) |
Add IndexContainsUnmergedEntriesException to bind EUNMERGED exception
-rw-r--r-- | LibGit2Sharp.Tests/MergeFixture.cs | 30 | ||||
-rw-r--r-- | LibGit2Sharp/Core/Ensure.cs | 3 | ||||
-rw-r--r-- | LibGit2Sharp/LibGit2Sharp.csproj | 1 | ||||
-rw-r--r-- | LibGit2Sharp/UnmergedIndexEntriesException.cs | 55 |
4 files changed, 88 insertions, 1 deletions
diff --git a/LibGit2Sharp.Tests/MergeFixture.cs b/LibGit2Sharp.Tests/MergeFixture.cs index 9c8ca38c..f7ecd1cb 100644 --- a/LibGit2Sharp.Tests/MergeFixture.cs +++ b/LibGit2Sharp.Tests/MergeFixture.cs @@ -1,4 +1,5 @@ -using LibGit2Sharp.Tests.TestHelpers; +using System.Linq; +using LibGit2Sharp.Tests.TestHelpers; using Xunit; namespace LibGit2Sharp.Tests @@ -28,5 +29,32 @@ namespace LibGit2Sharp.Tests } } } + + [Fact] + public void SoftResetARepoWithUnmergedEntriesThrows() + { + using (var repo = new Repository(MergedTestRepoWorkingDirPath)) + { + Assert.Equal(false, repo.Index.IsFullyMerged); + + var headCommit = repo.Head.Tip; + var firstCommitParent = headCommit.Parents.First(); + Assert.Throws<UnmergedIndexEntriesException>( + () => repo.Reset(ResetOptions.Soft, firstCommitParent)); + } + } + + [Fact] + public void CommitAgainARepoWithUnmergedEntriesThrows() + { + using (var repo = new Repository(MergedTestRepoWorkingDirPath)) + { + Assert.Equal(false, repo.Index.IsFullyMerged); + + var author = DummySignature; + Assert.Throws<UnmergedIndexEntriesException>( + () => repo.Commit("Try commit unmerged entries", author, author)); + } + } } } diff --git a/LibGit2Sharp/Core/Ensure.cs b/LibGit2Sharp/Core/Ensure.cs index 3a839fff..48031117 100644 --- a/LibGit2Sharp/Core/Ensure.cs +++ b/LibGit2Sharp/Core/Ensure.cs @@ -87,6 +87,9 @@ namespace LibGit2Sharp.Core case (int)GitErrorCode.InvalidSpecification: throw new InvalidSpecificationException(errorMessage, (GitErrorCode)result, error.Category); + case (int)GitErrorCode.UnmergedEntries: + throw new UnmergedIndexEntriesException(errorMessage, (GitErrorCode)result, error.Category); + default: throw new LibGit2SharpException(errorMessage, (GitErrorCode)result, error.Category); } diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 0fef0a45..fe693252 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -65,6 +65,7 @@ <Compile Include="Changes.cs" /> <Compile Include="CheckoutCallbacks.cs" /> <Compile Include="CheckoutOptions.cs" /> + <Compile Include="UnmergedIndexEntriesException.cs" /> <Compile Include="Commit.cs" /> <Compile Include="CommitLog.cs" /> <Compile Include="Configuration.cs" /> diff --git a/LibGit2Sharp/UnmergedIndexEntriesException.cs b/LibGit2Sharp/UnmergedIndexEntriesException.cs new file mode 100644 index 00000000..5cd7ff21 --- /dev/null +++ b/LibGit2Sharp/UnmergedIndexEntriesException.cs @@ -0,0 +1,55 @@ +using System; +using System.Runtime.Serialization; +using LibGit2Sharp.Core; + +namespace LibGit2Sharp +{ + /// <summary> + /// The exception that is thrown when an operation that requires a fully merged index + /// is performed against an index with unmerged entries + /// </summary> + [Serializable] + public class UnmergedIndexEntriesException : LibGit2SharpException + { + /// <summary> + /// Initializes a new instance of the <see cref = "UnmergedIndexEntriesException" /> class. + /// </summary> + public UnmergedIndexEntriesException() + { + } + + /// <summary> + /// Initializes a new instance of the <see cref = "UnmergedIndexEntriesException" /> class with a specified error message. + /// </summary> + /// <param name = "message">A message that describes the error. </param> + public UnmergedIndexEntriesException(string message) + : base(message) + { + } + + /// <summary> + /// Initializes a new instance of the <see cref = "UnmergedIndexEntriesException" /> class with a specified error message and a reference to the inner exception that is the cause of this exception. + /// </summary> + /// <param name = "message">The error message that explains the reason for the exception. </param> + /// <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> + public UnmergedIndexEntriesException(string message, Exception innerException) + : base(message, innerException) + { + } + + /// <summary> + /// Initializes a new instance of the <see cref = "UnmergedIndexEntriesException" /> class with a serialized data. + /// </summary> + /// <param name = "info">The <see cref="SerializationInfo "/> that holds the serialized object data about the exception being thrown.</param> + /// <param name = "context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param> + protected UnmergedIndexEntriesException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + + internal UnmergedIndexEntriesException(string message, GitErrorCode code, GitErrorCategory category) + : base(message, code, category) + { + } + } +} |