Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Introduce CheckoutConflictException #1059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions LibGit2Sharp.Tests/CheckoutFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void CanForcefullyCheckoutWithConflictingStagedChanges()

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

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

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

// And when there are staged commits
repo.Stage(originalFilePath);
Assert.Throws<MergeConflictException>(() => repo.Checkout("master"));
Assert.Throws<CheckoutConflictException>(() => repo.Checkout("master"));
}
}

Expand Down Expand Up @@ -505,7 +505,7 @@ public void CheckingOutCallsCheckoutNotify(CheckoutNotifyFlags notifyFlags, stri
CheckoutNotifyFlags = notifyFlags,
};

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

Assert.True(wasCalled);
Assert.Equal(expectedNotificationPath, actualNotificationPath);
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/MergeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public void MergeWithWorkDirConflictsThrows(bool shouldStage, FastForwardStrateg
// 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()))
Expand All @@ -596,7 +596,7 @@ public void MergeWithWorkDirConflictsThrows(bool shouldStage, FastForwardStrateg
repo.Stage("b.txt");
}

Assert.Throws<MergeConflictException>(() => repo.Merge(committishToMerge, Constants.Signature, new MergeOptions() { FastForwardStrategy = strategy }));
Assert.Throws<CheckoutConflictException>(() => repo.Merge(committishToMerge, Constants.Signature, new MergeOptions() { FastForwardStrategy = strategy }));
}
}

Expand Down
56 changes: 56 additions & 0 deletions LibGit2Sharp/CheckoutConflictException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Runtime.Serialization;
using LibGit2Sharp.Core;

namespace LibGit2Sharp
{
/// <summary>
/// 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.
/// </summary>
[Serializable]
public class CheckoutConflictException : LibGit2SharpException
{
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class.
/// </summary>
public CheckoutConflictException()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message.
/// </summary>
/// <param name="message">A message that describes the error.</param>
public CheckoutConflictException(string message)
: base(message)
{
}

/// <summary>
/// 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.
/// </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 CheckoutConflictException(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> 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 CheckoutConflictException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

internal CheckoutConflictException(string message, GitErrorCode code, GitErrorCategory category)
: base(message, code, category)
{
}
}
}
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/Ensure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private static readonly Dictionary<GitErrorCode, Func<string, GitErrorCode, GitE
{ 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) },
Expand Down
5 changes: 3 additions & 2 deletions LibGit2Sharp/Core/GitErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ internal enum GitErrorCode
InvalidSpecification = -12,

/// <summary>
/// A conflicting change has been detected.
/// A conflicting change has been detected in the index
/// or working directory.
/// </summary>
MergeConflict = -13,
Conflict = -13,

/// <summary>
/// A file operation failed because the file was locked.
Expand Down
3 changes: 2 additions & 1 deletion LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<Compile Include="IndexReucEntryCollection.cs" />
<Compile Include="IndexNameEntry.cs" />
<Compile Include="MergeAndCheckoutOptionsBase.cs" />
<Compile Include="MergeConflictException.cs" />
<Compile Include="MergeOptions.cs" />
<Compile Include="MergeOptionsBase.cs" />
<Compile Include="MergeResult.cs" />
Expand Down Expand Up @@ -228,7 +229,7 @@
<Compile Include="FetchHead.cs" />
<Compile Include="Handlers.cs" />
<Compile Include="Ignore.cs" />
<Compile Include="MergeConflictException.cs" />
<Compile Include="CheckoutConflictException.cs" />
<Compile Include="MergeHead.cs" />
<Compile Include="NameConflictException.cs" />
<Compile Include="NetworkExtensions.cs" />
Expand Down
53 changes: 8 additions & 45 deletions LibGit2Sharp/MergeConflictException.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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.
/// </summary>
[Serializable]
public class MergeConflictException : LibGit2SharpException
[Obsolete("This type will be removed in the next release. Please use CheckoutConflictException instead.")]
public class MergeConflictException : CheckoutConflictException
{
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> class.
/// </summary>
public MergeConflictException()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> class with a specified error message.
/// </summary>
/// <param name="message">A message that describes the error.</param>
public MergeConflictException(string message)
: base(message)
{
}

/// <summary>
/// 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.
/// </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 MergeConflictException(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.MergeConflictException"/> 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 MergeConflictException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

internal MergeConflictException(string message, GitErrorCode code, GitErrorCategory category)
: base(message, code, category)
{
}
}
}