using System;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
///
/// A remote repository whose branches are tracked.
///
public class Remote : IEquatable
{
private static readonly LambdaEqualityHelper equalityHelper =
new LambdaEqualityHelper(new Func[] { x => x.Name, x => x.Url });
internal static Remote CreateFromPtr(RemoteSafeHandle handle)
{
if (handle == null)
{
return null;
}
string name = NativeMethods.git_remote_name(handle);
string url = NativeMethods.git_remote_url(handle);
var remote = new Remote
{
Name = name,
Url = url,
};
return remote;
}
///
/// Gets the alias of this remote repository.
///
public string Name { get; private set; }
///
/// Gets the url to use to communicate with this remote repository.
///
public string Url { get; private set; }
///
/// 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 Remote);
}
///
/// 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(Remote 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 ==(Remote left, Remote 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 !=(Remote left, Remote right)
{
return !Equals(left, right);
}
}
}