Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-12-14 23:38:10 +0300
committerCarlos Martín Nieto <cmn@dwim.me>2016-03-07 12:43:18 +0300
commit53b66beadfb6f59283fb90133e52ab783d7026fd (patch)
tree821b18790711d791104084c240414e03deff8aef
parent4bb5f5f55623c8c9b175a1dcc342e7bcc29f0c98 (diff)
Bind the missing refspec methods
These are actions, so they need the handle which we previously made the code keep around.
-rw-r--r--LibGit2Sharp.Tests/RefSpecFixture.cs38
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs16
-rw-r--r--LibGit2Sharp/Core/Proxy.cs21
-rw-r--r--LibGit2Sharp/RefSpec.cs40
4 files changed, 115 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/RefSpecFixture.cs b/LibGit2Sharp.Tests/RefSpecFixture.cs
index dc82a5fc..09454716 100644
--- a/LibGit2Sharp.Tests/RefSpecFixture.cs
+++ b/LibGit2Sharp.Tests/RefSpecFixture.cs
@@ -190,5 +190,43 @@ namespace LibGit2Sharp.Tests
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);
+ }
+ }
}
}
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 8978abda..94cbe7c2 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -1113,6 +1113,12 @@ namespace LibGit2Sharp.Core
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,
GitRefSpecHandle refSpec,
@@ -1140,6 +1146,16 @@ namespace LibGit2Sharp.Core
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);
[DllImport(libgit2)]
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 35371d88..b19fa649 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -2017,6 +2017,17 @@ namespace LibGit2Sharp.Core
#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())
@@ -2053,6 +2064,16 @@ namespace LibGit2Sharp.Core
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_
diff --git a/LibGit2Sharp/RefSpec.cs b/LibGit2Sharp/RefSpec.cs
index c5114696..aeeabb75 100644
--- a/LibGit2Sharp/RefSpec.cs
+++ b/LibGit2Sharp/RefSpec.cs
@@ -82,6 +82,46 @@ namespace LibGit2Sharp
}
}
+ /// <summary>
+ /// Check whether the given reference matches the source (lhs) part of
+ /// this refspec.
+ /// </summary>
+ /// <param name="reference">The reference name to check</param>
+ public virtual bool SourceMatches(string reference)
+ {
+ return Proxy.git_refspec_src_matches(handle, reference);
+ }
+
+ /// <summary>
+ /// Check whether the given reference matches the target (rhs) part of
+ /// this refspec.
+ /// </summary>
+ /// <param name="reference">The reference name to check</param>
+ public virtual bool DestinationMatches(string reference)
+ {
+ return Proxy.git_refspec_dst_matches(handle, reference);
+ }
+
+ /// <summary>
+ /// Perform the transformation described by this refspec on the given
+ /// reference name (from source to destination).
+ /// </summary>
+ /// <param name="reference">The reference name to transform</param>
+ public virtual string Transform(string reference)
+ {
+ return Proxy.git_refspec_transform(handle, reference);
+ }
+
+ /// <summary>
+ /// Perform the reverse of the transformation described by this refspec
+ /// on the given reference name (from destination to source).
+ /// </summary>
+ /// <param name="reference">The reference name to transform</param>
+ public virtual string ReverseTransform(string reference)
+ {
+ return Proxy.git_refspec_rtransform(handle, reference);
+ }
+
private string DebuggerDisplay
{
get