using System;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
///
/// Represents a group of index entries that describe a merge conflict
/// in the index. This is typically a set of ancestor, ours and theirs
/// entries for a given path.
///
/// Any side may be missing to reflect additions or deletions in the
/// branches being merged.
///
public class Conflict : IEquatable
{
private readonly IndexEntry ancestor;
private readonly IndexEntry ours;
private readonly IndexEntry theirs;
private static readonly LambdaEqualityHelper equalityHelper =
new LambdaEqualityHelper(x => x.Ancestor, x => x.Ours, x => x.Theirs);
///
/// Needed for mocking purposes.
///
protected Conflict()
{ }
internal Conflict(IndexEntry ancestor, IndexEntry ours, IndexEntry theirs)
{
this.ancestor = ancestor;
this.ours = ours;
this.theirs = theirs;
}
///
/// The index entry of the ancestor side of the conflict (the stage
/// 1 index entry.)
///
public virtual IndexEntry Ancestor
{
get { return ancestor; }
}
///
/// The index entry of the "ours" (ORIG_HEAD or merge target) side
/// of the conflict (the stage 2 index entry.)
///
public virtual IndexEntry Ours
{
get { return ours; }
}
///
/// The index entry of the "theirs" (merge source) side of the
/// conflict (the stage 3 index entry.)
///
public virtual IndexEntry Theirs
{
get { return theirs; }
}
///
/// Determines whether the specified is
/// equal to the current .
///
/// The to compare with
/// the current .
/// true if the specified is equal
/// to the current ; otherwise,
/// false.
public override bool Equals(object obj)
{
return Equals(obj as Conflict);
}
///
/// Determines whether the specified
/// is equal to the current .
///
/// The to compare
/// with the current .
/// true if the specified is equal
/// to the current ; otherwise,
/// false.
public bool Equals(Conflict other)
{
return equalityHelper.Equals(this, other);
}
///
/// Returns the hash code for this instance.
///
/// A 32-bit signed integer hash code.
public override int GetHashCode()
{
return equalityHelper.GetHashCode(this);
}
///
/// Tests if two are equal.
///
/// First to compare.
/// Second to compare.
/// True if the two objects are equal; false otherwise.
public static bool operator ==(Conflict left, Conflict right)
{
return Equals(left, right);
}
///
/// Tests if two are different.
///
/// First to compare.
/// Second to compare.
/// True if the two objects are different; false otherwise.
public static bool operator !=(Conflict left, Conflict right)
{
return !Equals(left, right);
}
}
}