Skip to content

Commit ba6b4b4

Browse files
committed
Merge pull request #1059 from libgit2/ethomson/mergeconflict
Introduce CheckoutConflictException
2 parents adafc41 + ac524f3 commit ba6b4b4

File tree

7 files changed

+76
-55
lines changed

7 files changed

+76
-55
lines changed

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public void CanForcefullyCheckoutWithConflictingStagedChanges()
266266

267267
// Assert that normal checkout throws exception
268268
// for the conflict.
269-
Assert.Throws<MergeConflictException>(() => repo.Checkout(master.CanonicalName));
269+
Assert.Throws<CheckoutConflictException>(() => repo.Checkout(master.CanonicalName));
270270

271271
// Checkout with force option should succeed.
272272
repo.Checkout(master.CanonicalName, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force});
@@ -304,11 +304,11 @@ public void CheckingOutWithMergeConflictsThrows()
304304

305305
// Assert that checking out master throws
306306
// when there are unstaged commits
307-
Assert.Throws<MergeConflictException>(() => repo.Checkout("master"));
307+
Assert.Throws<CheckoutConflictException>(() => repo.Checkout("master"));
308308

309309
// And when there are staged commits
310310
repo.Stage(originalFilePath);
311-
Assert.Throws<MergeConflictException>(() => repo.Checkout("master"));
311+
Assert.Throws<CheckoutConflictException>(() => repo.Checkout("master"));
312312
}
313313
}
314314

@@ -505,7 +505,7 @@ public void CheckingOutCallsCheckoutNotify(CheckoutNotifyFlags notifyFlags, stri
505505
CheckoutNotifyFlags = notifyFlags,
506506
};
507507

508-
Assert.Throws<MergeConflictException>(() => repo.Checkout("master", options));
508+
Assert.Throws<CheckoutConflictException>(() => repo.Checkout("master", options));
509509

510510
Assert.True(wasCalled);
511511
Assert.Equal(expectedNotificationPath, actualNotificationPath);

LibGit2Sharp.Tests/MergeFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public void MergeWithWorkDirConflictsThrows(bool shouldStage, FastForwardStrateg
584584
// Merging the fast_forward branch results in a change to file
585585
// b.txt. In this test we modify the file in the working directory
586586
// and then attempt to perform a merge. We expect the merge to fail
587-
// due to merge conflicts.
587+
// due to checkout conflicts.
588588
string committishToMerge = "fast_forward";
589589

590590
using (var repo = new Repository(SandboxMergeTestRepo()))
@@ -596,7 +596,7 @@ public void MergeWithWorkDirConflictsThrows(bool shouldStage, FastForwardStrateg
596596
repo.Stage("b.txt");
597597
}
598598

599-
Assert.Throws<MergeConflictException>(() => repo.Merge(committishToMerge, Constants.Signature, new MergeOptions() { FastForwardStrategy = strategy }));
599+
Assert.Throws<CheckoutConflictException>(() => repo.Merge(committishToMerge, Constants.Signature, new MergeOptions() { FastForwardStrategy = strategy }));
600600
}
601601
}
602602

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using LibGit2Sharp.Core;
4+
5+
namespace LibGit2Sharp
6+
{
7+
/// <summary>
8+
/// The exception that is thrown when a checkout cannot be performed
9+
/// because of a conflicting change staged in the index, or unstaged
10+
/// in the working directory.
11+
/// </summary>
12+
[Serializable]
13+
public class CheckoutConflictException : LibGit2SharpException
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class.
17+
/// </summary>
18+
public CheckoutConflictException()
19+
{
20+
}
21+
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message.
24+
/// </summary>
25+
/// <param name="message">A message that describes the error.</param>
26+
public CheckoutConflictException(string message)
27+
: base(message)
28+
{
29+
}
30+
31+
/// <summary>
32+
/// 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.
33+
/// </summary>
34+
/// <param name="message">The error message that explains the reason for the exception.</param>
35+
/// <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>
36+
public CheckoutConflictException(string message, Exception innerException)
37+
: base(message, innerException)
38+
{
39+
}
40+
41+
/// <summary>
42+
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a serialized data.
43+
/// </summary>
44+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
45+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
46+
protected CheckoutConflictException(SerializationInfo info, StreamingContext context)
47+
: base(info, context)
48+
{
49+
}
50+
51+
internal CheckoutConflictException(string message, GitErrorCode code, GitErrorCategory category)
52+
: base(message, code, category)
53+
{
54+
}
55+
}
56+
}

LibGit2Sharp/Core/Ensure.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private static readonly Dictionary<GitErrorCode, Func<string, GitErrorCode, GitE
9797
{ GitErrorCode.InvalidSpecification, (m, r, c) => new InvalidSpecificationException(m, r, c) },
9898
{ GitErrorCode.UnmergedEntries, (m, r, c) => new UnmergedIndexEntriesException(m, r, c) },
9999
{ GitErrorCode.NonFastForward, (m, r, c) => new NonFastForwardException(m, r, c) },
100-
{ GitErrorCode.MergeConflict, (m, r, c) => new MergeConflictException(m, r, c) },
100+
{ GitErrorCode.Conflict, (m, r, c) => new CheckoutConflictException(m, r, c) },
101101
{ GitErrorCode.LockedFile, (m, r, c) => new LockedFileException(m, r, c) },
102102
{ GitErrorCode.NotFound, (m, r, c) => new NotFoundException(m, r, c) },
103103
{ GitErrorCode.Peel, (m, r, c) => new PeelException(m, r, c) },

LibGit2Sharp/Core/GitErrorCode.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ internal enum GitErrorCode
5656
InvalidSpecification = -12,
5757

5858
/// <summary>
59-
/// A conflicting change has been detected.
59+
/// A conflicting change has been detected in the index
60+
/// or working directory.
6061
/// </summary>
61-
MergeConflict = -13,
62+
Conflict = -13,
6263

6364
/// <summary>
6465
/// A file operation failed because the file was locked.

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<Compile Include="IndexReucEntryCollection.cs" />
110110
<Compile Include="IndexNameEntry.cs" />
111111
<Compile Include="MergeAndCheckoutOptionsBase.cs" />
112+
<Compile Include="MergeConflictException.cs" />
112113
<Compile Include="MergeOptions.cs" />
113114
<Compile Include="MergeOptionsBase.cs" />
114115
<Compile Include="MergeResult.cs" />
@@ -232,7 +233,7 @@
232233
<Compile Include="FetchHead.cs" />
233234
<Compile Include="Handlers.cs" />
234235
<Compile Include="Ignore.cs" />
235-
<Compile Include="MergeConflictException.cs" />
236+
<Compile Include="CheckoutConflictException.cs" />
236237
<Compile Include="MergeHead.cs" />
237238
<Compile Include="NameConflictException.cs" />
238239
<Compile Include="NetworkExtensions.cs" />
Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,18 @@
11
using System;
2-
using System.Runtime.Serialization;
3-
using LibGit2Sharp.Core;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
45

56
namespace LibGit2Sharp
67
{
78
/// <summary>
8-
/// The exception that is thrown when a merge cannot be performed because
9-
/// of a conflicting change.
9+
/// The exception that is thrown when a checkout cannot be performed
10+
/// because of a conflicting change staged in the index, or unstaged
11+
/// in the working directory.
1012
/// </summary>
1113
[Serializable]
12-
public class MergeConflictException : LibGit2SharpException
14+
[Obsolete("This type will be removed in the next release. Please use CheckoutConflictException instead.")]
15+
public class MergeConflictException : CheckoutConflictException
1316
{
14-
/// <summary>
15-
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> class.
16-
/// </summary>
17-
public MergeConflictException()
18-
{
19-
}
20-
21-
/// <summary>
22-
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> class with a specified error message.
23-
/// </summary>
24-
/// <param name="message">A message that describes the error.</param>
25-
public MergeConflictException(string message)
26-
: base(message)
27-
{
28-
}
29-
30-
/// <summary>
31-
/// 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.
32-
/// </summary>
33-
/// <param name="message">The error message that explains the reason for the exception.</param>
34-
/// <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>
35-
public MergeConflictException(string message, Exception innerException)
36-
: base(message, innerException)
37-
{
38-
}
39-
40-
/// <summary>
41-
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> class with a serialized data.
42-
/// </summary>
43-
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
44-
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
45-
protected MergeConflictException(SerializationInfo info, StreamingContext context)
46-
: base(info, context)
47-
{
48-
}
49-
50-
internal MergeConflictException(string message, GitErrorCode code, GitErrorCategory category)
51-
: base(message, code, category)
52-
{
53-
}
5417
}
5518
}

0 commit comments

Comments
 (0)