Skip to content

Bind the methods for refspecs #1249

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

Closed
wants to merge 8 commits into from
Closed
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
17 changes: 0 additions & 17 deletions LibGit2Sharp.Tests/CheckoutFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,23 +1029,6 @@ public void CanCheckoutPathFromCurrentBranch(string fileName)
}
}

[Fact]
public void CanCatchDeprecatedException()
{
bool caught = false;

try
{
throw new CheckoutConflictException();
}
catch (MergeConflictException)
{
caught = true;
}

Assert.True(caught);
}

/// <summary>
/// Helper method to populate a simple repository with
/// a single file and two branches.
Expand Down
38 changes: 38 additions & 0 deletions LibGit2Sharp.Tests/RefSpecFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,43 @@ public void SettingInvalidRefSpecsThrows(string refSpec)
Assert.Equal(oldRefSpecs, newRemote.RefSpecs.Select(r => r.Specification).ToList());
}
}

[Theory]
[InlineData("refs/heads/master", true, false)]
[InlineData("refs/heads/some/master", true, false)]
[InlineData("refs/remotes/foo/master", false, true)]
[InlineData("refs/tags/foo", false, false)]
public void CanCheckForMatches(string reference, bool shouldMatchSource, bool shouldMatchDest)
{
var path = SandboxStandardTestRepo();
using (var repo = InitIsolatedRepository(path))
{
var remote = repo.Network.Remotes.Add("foo", "blahblah", "refs/heads/*:refs/remotes/foo/*");
var refspec = remote.RefSpecs.Single();

Assert.Equal(shouldMatchSource, refspec.SourceMatches(reference));
Assert.Equal(shouldMatchDest, refspec.DestinationMatches(reference));
}
}

[Theory]
[InlineData("refs/heads/master", "refs/remotes/foo/master")]
[InlineData("refs/heads/bar/master", "refs/remotes/foo/bar/master")]
[InlineData("refs/heads/master", "refs/remotes/foo/master")]
public void CanTransformRefspecs(string lhs, string rhs)
{
var path = SandboxStandardTestRepo();
using (var repo = InitIsolatedRepository(path))
{
var remote = repo.Network.Remotes.Add("foo", "blahblah", "refs/heads/*:refs/remotes/foo/*");
var refspec = remote.RefSpecs.Single();

var actualTransformed = refspec.Transform(lhs);
var actualReverseTransformed = refspec.ReverseTransform(rhs);

Assert.Equal(rhs, actualTransformed);
Assert.Equal(lhs, actualReverseTransformed);
}
}
}
}
38 changes: 37 additions & 1 deletion LibGit2Sharp/CheckoutConflictException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;
using LibGit2Sharp.Core;

namespace LibGit2Sharp
Expand All @@ -9,14 +10,49 @@ namespace LibGit2Sharp
/// in the working directory.
/// </summary>
[Serializable]
public class CheckoutConflictException : MergeConflictException
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.
/// </summary>
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
/// <param name="args">An object array that contains zero or more objects to format.</param>
public CheckoutConflictException(string format, params object[] args)
: base(format, args)
{ }

/// <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)
{ }
Expand Down
31 changes: 0 additions & 31 deletions LibGit2Sharp/CommitFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ public CommitFilter()
/// </summary>
public CommitSortStrategies SortBy { get; set; }

/// <summary>
/// A pointer to a commit object or a list of pointers to consider as starting points.
/// <para>
/// Can be either a <see cref="string"/> containing the sha or reference canonical name to use,
/// a <see cref="Branch"/>, a <see cref="Reference"/>, a <see cref="Commit"/>, a <see cref="Tag"/>,
/// a <see cref="TagAnnotation"/>, an <see cref="ObjectId"/> or even a mixed collection of all of the above.
/// By default, the <see cref="Repository.Head"/> will be used as boundary.
/// </para>
/// </summary>
[Obsolete("This property will be removed in the next release. Please use IncludeReachableFrom instead.")]
public object Since
{
get { return IncludeReachableFrom; }
set { IncludeReachableFrom = value; }
}

/// <summary>
/// A pointer to a commit object or a list of pointers to consider as starting points.
/// <para>
Expand All @@ -60,21 +44,6 @@ internal IList<object> SinceList
get { return ToList(IncludeReachableFrom); }
}

/// <summary>
/// A pointer to a commit object or a list of pointers which will be excluded (along with ancestors) from the enumeration.
/// <para>
/// Can be either a <see cref="string"/> containing the sha or reference canonical name to use,
/// a <see cref="Branch"/>, a <see cref="Reference"/>, a <see cref="Commit"/>, a <see cref="Tag"/>,
/// a <see cref="TagAnnotation"/>, an <see cref="ObjectId"/> or even a mixed collection of all of the above.
/// </para>
/// </summary>
[Obsolete("This property will be removed in the next release. Please use ExcludeReachableFrom instead.")]
public object Until
{
get { return ExcludeReachableFrom; }
set { ExcludeReachableFrom = value; }
}

/// <summary>
/// A pointer to a commit object or a list of pointers which will be excluded (along with ancestors) from the enumeration.
/// <para>
Expand Down
24 changes: 0 additions & 24 deletions LibGit2Sharp/CommitLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,6 @@ public IEnumerable<LogEntry> QueryBy(string path, FollowFilter filter)
return new FileHistory(repo, path, new CommitFilter { SortBy = filter.SortBy });
}

/// <summary>
/// Find the best possible merge base given two <see cref="Commit"/>s.
/// </summary>
/// <param name="first">The first <see cref="Commit"/>.</param>
/// <param name="second">The second <see cref="Commit"/>.</param>
/// <returns>The merge base or null if none found.</returns>
[Obsolete("This method will be removed in the next release. Please use ObjectDatabase.FindMergeBase() instead.")]
public Commit FindMergeBase(Commit first, Commit second)
{
return repo.ObjectDatabase.FindMergeBase(first, second);
}

/// <summary>
/// Find the best possible merge base given two or more <see cref="Commit"/> according to the <see cref="MergeBaseFindingStrategy"/>.
/// </summary>
/// <param name="commits">The <see cref="Commit"/>s for which to find the merge base.</param>
/// <param name="strategy">The strategy to leverage in order to find the merge base.</param>
/// <returns>The merge base or null if none found.</returns>
[Obsolete("This method will be removed in the next release. Please use ObjectDatabase.FindMergeBase() instead.")]
public Commit FindMergeBase(IEnumerable<Commit> commits, MergeBaseFindingStrategy strategy)
{
return repo.ObjectDatabase.FindMergeBase(commits, strategy);
}

private class CommitEnumerator : IEnumerator<Commit>
{
private readonly Repository repo;
Expand Down
6 changes: 0 additions & 6 deletions LibGit2Sharp/CompareOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ public CompareOptions()
/// </summary>
public bool IncludeUnmodified { get; set; }

/// <summary>
/// Use the "patience diff" algorithm.
/// </summary>
[Obsolete("This property will be removed in the next release. Please use Algorithm instead.")]
public bool UsePatienceAlgorithm { get; set; }

/// <summary>
/// Algorithm to be used when performing a Diff.
/// By default, <see cref="DiffAlgorithm.Myers"/> will be used.
Expand Down
30 changes: 0 additions & 30 deletions LibGit2Sharp/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,36 +195,6 @@ public static Configuration BuildFrom(
return new Configuration(null, repositoryConfigurationFileLocation, globalConfigurationFileLocation, xdgConfigurationFileLocation, systemConfigurationFileLocation);
}

/// <summary>
/// Access configuration values without a repository. Generally you want to access configuration via an instance of <see cref="Repository"/> instead.
/// </summary>
/// <param name="globalConfigurationFileLocation">Path to a Global configuration file. If null, the default path for a global configuration file will be probed.</param>
[Obsolete("This method will be removed in the next release. Please use Configuration.BuildFrom(string, string) instead.")]
public Configuration(string globalConfigurationFileLocation)
: this(null, null, globalConfigurationFileLocation, null, null)
{ }

/// <summary>
/// Access configuration values without a repository. Generally you want to access configuration via an instance of <see cref="Repository"/> instead.
/// </summary>
/// <param name="globalConfigurationFileLocation">Path to a Global configuration file. If null, the default path for a global configuration file will be probed.</param>
/// <param name="xdgConfigurationFileLocation">Path to a XDG configuration file. If null, the default path for a XDG configuration file will be probed.</param>
[Obsolete("This method will be removed in the next release. Please use Configuration.BuildFrom(string, string, string) instead.")]
public Configuration(string globalConfigurationFileLocation, string xdgConfigurationFileLocation)
: this(null, null, globalConfigurationFileLocation, xdgConfigurationFileLocation, null)
{ }

/// <summary>
/// Access configuration values without a repository. Generally you want to access configuration via an instance of <see cref="Repository"/> instead.
/// </summary>
/// <param name="globalConfigurationFileLocation">Path to a Global configuration file. If null, the default path for a global configuration file will be probed.</param>
/// <param name="xdgConfigurationFileLocation">Path to a XDG configuration file. If null, the default path for a XDG configuration file will be probed.</param>
/// <param name="systemConfigurationFileLocation">Path to a System configuration file. If null, the default path for a system configuration file will be probed.</param>
[Obsolete("This method will be removed in the next release. Please use Configuration.BuildFrom(string, string, string, string) instead.")]
public Configuration(string globalConfigurationFileLocation, string xdgConfigurationFileLocation, string systemConfigurationFileLocation)
: this(null, null, globalConfigurationFileLocation, xdgConfigurationFileLocation, systemConfigurationFileLocation)
{ }

/// <summary>
/// Determines which configuration file has been found.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,12 @@ internal static extern IntPtr git_reflog_entry_committer(
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
internal static extern string git_reflog_entry_message(SafeHandle entry);

[DllImport(libgit2)]
internal static extern int git_refspec_transform(
GitBuf buf,
GitRefSpecHandle refspec,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name);

[DllImport(libgit2)]
internal static extern int git_refspec_rtransform(
GitBuf buf,
Expand Down Expand Up @@ -1139,6 +1145,16 @@ internal static extern string git_refspec_src(
[DllImport(libgit2)]
internal static extern bool git_refspec_force(GitRefSpecHandle refSpec);

[DllImport(libgit2)]
internal static extern bool git_refspec_src_matches(
GitRefSpecHandle resfpec,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string reference);

[DllImport(libgit2)]
internal static extern bool git_refspec_dst_matches(
GitRefSpecHandle resfpec,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string reference);

[DllImport(libgit2)]
internal static extern int git_remote_autotag(RemoteSafeHandle remote);

Expand Down
21 changes: 21 additions & 0 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,17 @@ public static string git_reflog_entry_message(SafeHandle entry)

#region git_refspec

public static string git_refspec_transform(GitRefSpecHandle refSpecPtr, string name)
{
using (var buf = new GitBuf())
{
int res = NativeMethods.git_refspec_transform(buf, refSpecPtr, name);
Ensure.ZeroResult(res);

return LaxUtf8Marshaler.FromNative(buf.ptr) ?? string.Empty;
}
}

public static string git_refspec_rtransform(GitRefSpecHandle refSpecPtr, string name)
{
using (var buf = new GitBuf())
Expand Down Expand Up @@ -2053,6 +2064,16 @@ public static bool git_refspec_force(GitRefSpecHandle refSpec)
return NativeMethods.git_refspec_force(refSpec);
}

public static bool git_refspec_src_matches(GitRefSpecHandle refspec, string reference)
{
return NativeMethods.git_refspec_src_matches(refspec, reference);
}

public static bool git_refspec_dst_matches(GitRefSpecHandle refspec, string reference)
{
return NativeMethods.git_refspec_dst_matches(refspec, reference);
}

#endregion

#region git_remote_
Expand Down
Loading