diff options
author | Metalrom <romain.magny@gmail.com> | 2013-01-07 18:52:18 +0400 |
---|---|---|
committer | Metalrom <romain.magny@gmail.com> | 2013-01-10 17:18:41 +0400 |
commit | d71f7561dd8ac5e7e6636f380a25d3fd1b4e5087 (patch) | |
tree | 1bf00462a13916aeb9829564d88f1e41e7a701a6 | |
parent | 0114a7c04ebe01c8c3b4cdcf9388d7212c6aba1e (diff) |
Add NameConflictException as wrapper for EEXIST native exception
-rw-r--r-- | LibGit2Sharp.Tests/BranchFixture.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/ReferenceFixture.cs | 6 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/TagFixture.cs | 8 | ||||
-rw-r--r-- | LibGit2Sharp/Core/Ensure.cs | 3 | ||||
-rw-r--r-- | LibGit2Sharp/LibGit2Sharp.csproj | 1 | ||||
-rw-r--r-- | LibGit2Sharp/NameConflictException.cs | 54 |
6 files changed, 66 insertions, 8 deletions
diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs index fc321c3c..95010aad 100644 --- a/LibGit2Sharp.Tests/BranchFixture.cs +++ b/LibGit2Sharp.Tests/BranchFixture.cs @@ -552,7 +552,7 @@ namespace LibGit2Sharp.Tests { using (var repo = new Repository(BareTestRepoPath)) { - Assert.Throws<LibGit2SharpException>(() => repo.Branches.Move("br2", "test")); + Assert.Throws<NameConflictException>(() => repo.Branches.Move("br2", "test")); } } diff --git a/LibGit2Sharp.Tests/ReferenceFixture.cs b/LibGit2Sharp.Tests/ReferenceFixture.cs index 6dfeff29..4f680dff 100644 --- a/LibGit2Sharp.Tests/ReferenceFixture.cs +++ b/LibGit2Sharp.Tests/ReferenceFixture.cs @@ -112,7 +112,7 @@ namespace LibGit2Sharp.Tests TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); using (var repo = new Repository(path.RepositoryPath)) { - Assert.Throws<LibGit2SharpException>(() => repo.Refs.Add("refs/heads/master", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); + Assert.Throws<NameConflictException>(() => repo.Refs.Add("refs/heads/master", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); } } @@ -122,7 +122,7 @@ namespace LibGit2Sharp.Tests TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(); using (var repo = new Repository(path.RepositoryPath)) { - Assert.Throws<LibGit2SharpException>(() => repo.Refs.Add("HEAD", "refs/heads/br2")); + Assert.Throws<NameConflictException>(() => repo.Refs.Add("HEAD", "refs/heads/br2")); } } @@ -613,7 +613,7 @@ namespace LibGit2Sharp.Tests { using (var repo = new Repository(BareTestRepoPath)) { - Assert.Throws<LibGit2SharpException>(() => repo.Refs.Move("refs/heads/packed", "refs/heads/br2")); + Assert.Throws<NameConflictException>(() => repo.Refs.Move("refs/heads/packed", "refs/heads/br2")); } } diff --git a/LibGit2Sharp.Tests/TagFixture.cs b/LibGit2Sharp.Tests/TagFixture.cs index a87f9bc9..8d1c146c 100644 --- a/LibGit2Sharp.Tests/TagFixture.cs +++ b/LibGit2Sharp.Tests/TagFixture.cs @@ -296,7 +296,7 @@ namespace LibGit2Sharp.Tests { repo.ApplyTag("mytag"); - Assert.Throws<LibGit2SharpException>(() => repo.ApplyTag("mytag")); + Assert.Throws<NameConflictException>(() => repo.ApplyTag("mytag")); } } @@ -413,7 +413,7 @@ namespace LibGit2Sharp.Tests { using (var repo = new Repository(BareTestRepoPath)) { - Assert.Throws<LibGit2SharpException>(() => repo.Tags.Add("e90810b", "refs/heads/br2")); + Assert.Throws<NameConflictException>(() => repo.Tags.Add("e90810b", "refs/heads/br2")); } } @@ -422,7 +422,7 @@ namespace LibGit2Sharp.Tests { using (var repo = new Repository(BareTestRepoPath)) { - Assert.Throws<LibGit2SharpException>(() => repo.Tags.Add("e90810b", "refs/heads/br2", signatureNtk, "a nice message")); + Assert.Throws<NameConflictException>(() => repo.Tags.Add("e90810b", "refs/heads/br2", signatureNtk, "a nice message")); } } @@ -431,7 +431,7 @@ namespace LibGit2Sharp.Tests { using (var repo = new Repository(BareTestRepoPath)) { - Assert.Throws<LibGit2SharpException>(() => repo.Tags.Add("test", tagTestSha, signatureTim, "message")); + Assert.Throws<NameConflictException>(() => repo.Tags.Add("test", tagTestSha, signatureTim, "message")); } } diff --git a/LibGit2Sharp/Core/Ensure.cs b/LibGit2Sharp/Core/Ensure.cs index c18e537b..7998bebd 100644 --- a/LibGit2Sharp/Core/Ensure.cs +++ b/LibGit2Sharp/Core/Ensure.cs @@ -81,6 +81,9 @@ namespace LibGit2Sharp.Core case (int)GitErrorCode.BareRepo: throw new BareRepositoryException(errorMessage, (GitErrorCode)result, error.Category); + case (int)GitErrorCode.Exists: + throw new NameConflictException(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 19e032e5..83edb8d3 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -87,6 +87,7 @@ <Compile Include="DiffTargets.cs" /> <Compile Include="Handlers.cs" /> <Compile Include="MergeConflictException.cs" /> + <Compile Include="NameConflictException.cs" /> <Compile Include="ReferenceCollectionExtensions.cs" /> <Compile Include="Core\GitRemoteCallbacks.cs" /> <Compile Include="RemoteCallbacks.cs" /> diff --git a/LibGit2Sharp/NameConflictException.cs b/LibGit2Sharp/NameConflictException.cs new file mode 100644 index 00000000..989256ca --- /dev/null +++ b/LibGit2Sharp/NameConflictException.cs @@ -0,0 +1,54 @@ +using System; +using System.Runtime.Serialization; +using LibGit2Sharp.Core; + +namespace LibGit2Sharp +{ + /// <summary> + /// The exception that is thrown when a reference, a remote, a submodule... with the same name already exists in the repository + /// </summary> + [Serializable] + public class NameConflictException : LibGit2SharpException + { + /// <summary> + /// Initializes a new instance of the <see cref = "NameConflictException" /> class. + /// </summary> + public NameConflictException() + { + } + + /// <summary> + /// Initializes a new instance of the <see cref = "NameConflictException" /> class with a specified error message. + /// </summary> + /// <param name = "message">A message that describes the error. </param> + public NameConflictException(string message) + : base(message) + { + } + + /// <summary> + /// Initializes a new instance of the <see cref = "NameConflictException" /> 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 NameConflictException(string message, Exception innerException) + : base(message, innerException) + { + } + + /// <summary> + /// Initializes a new instance of the <see cref = "NameConflictException" /> 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 NameConflictException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + + internal NameConflictException(string message, GitErrorCode code, GitErrorCategory category) + : base(message, code, category) + { + } + } +} |