using System;
using System.Diagnostics;
using System.Globalization;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;
namespace LibGit2Sharp
{
///
/// A push or fetch reference specification
///
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RefSpec
{
private RefSpec(string refSpec, RefSpecDirection direction, string source, string destination, bool forceUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(refSpec, "refSpec");
Ensure.ArgumentNotNull(source, "source");
Ensure.ArgumentNotNull(destination, "destination");
Specification = refSpec;
Direction = direction;
Source = source;
Destination = destination;
ForceUpdate = forceUpdate;
}
///
/// Needed for mocking purposes.
///
protected RefSpec()
{ }
internal static RefSpec BuildFromPtr(GitRefSpecHandle handle)
{
Ensure.ArgumentNotNull(handle, "handle");
return new RefSpec(Proxy.git_refspec_string(handle), Proxy.git_refspec_direction(handle),
Proxy.git_refspec_src(handle), Proxy.git_refspec_dst(handle), Proxy.git_refspec_force(handle));
}
///
/// Gets the pattern describing the mapping between remote and local references
///
public virtual string Specification { get; private set; }
///
/// Indicates whether this is intended to be used during a Push or Fetch operation
///
public virtual RefSpecDirection Direction { get; private set; }
///
/// The source reference specifier
///
public virtual string Source { get; private set; }
///
/// The target reference specifier
///
public virtual string Destination { get; private set; }
///
/// Indicates whether the destination will be force-updated if fast-forwarding is not possible
///
public virtual bool ForceUpdate { get; private set; }
private string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture,
"{0}", Specification);
}
}
}
}