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:
authorMarius Ungureanu <marius.ungureanu@xamarin.com>2014-06-02 23:16:17 +0400
committerMarius Ungureanu <marius.ungureanu@xamarin.com>2014-06-06 19:29:41 +0400
commite1b6166af04a346baac90c809ea79b7b753586b1 (patch)
tree789c2d219c30e03ebad3d78936285d0117362dcc /LibGit2Sharp
parent05e6633d998176a2afddfc4814bf47564976ef26 (diff)
Introduce RemoteCollection.Rename.
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs11
-rw-r--r--LibGit2Sharp/Core/Proxy.cs28
-rw-r--r--LibGit2Sharp/Handlers.cs10
-rw-r--r--LibGit2Sharp/RemoteCollection.cs17
4 files changed, 66 insertions, 0 deletions
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index faf1e02b..ea5bff09 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -213,6 +213,17 @@ namespace LibGit2Sharp.Core
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string canonical_branch_name);
[DllImport(libgit2)]
+ internal static extern int git_remote_rename(
+ RemoteSafeHandle remote,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string new_name,
+ git_remote_rename_problem_cb callback,
+ IntPtr payload);
+
+ internal delegate int git_remote_rename_problem_cb(
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))] string problematic_refspec,
+ IntPtr payload);
+
+ [DllImport(libgit2)]
internal static extern int git_branch_upstream_name(
GitBuf buf,
RepositorySafeHandle repo,
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index e6b3940b..feb66d6c 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -6,6 +6,7 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using LibGit2Sharp.Core.Handles;
+using LibGit2Sharp.Handlers;
// ReSharper disable InconsistentNaming
namespace LibGit2Sharp.Core
@@ -1958,6 +1959,33 @@ namespace LibGit2Sharp.Core
return NativeMethods.git_remote_name(remote);
}
+ public static void git_remote_rename(RepositorySafeHandle repo, string name, string new_name, RemoteRenameFailureHandler callback)
+ {
+ using (ThreadAffinity())
+ {
+ using (RemoteSafeHandle remote = git_remote_load(repo, name, false))
+ {
+ if (remote == null)
+ {
+ return;
+ }
+
+ if (callback == null)
+ {
+ callback = (problem) => {};
+ }
+
+ int res = NativeMethods.git_remote_rename(
+ remote,
+ new_name,
+ (problem, payload) => { callback(problem); return 0; },
+ IntPtr.Zero);
+
+ Ensure.ZeroResult(res);
+ }
+ }
+ }
+
public static void git_remote_save(RemoteSafeHandle remote)
{
using (ThreadAffinity())
diff --git a/LibGit2Sharp/Handlers.cs b/LibGit2Sharp/Handlers.cs
index 17e822ab..3c0f67fc 100644
--- a/LibGit2Sharp/Handlers.cs
+++ b/LibGit2Sharp/Handlers.cs
@@ -79,6 +79,16 @@
public delegate void UnmatchedPathHandler(string unmatchedPath);
/// <summary>
+ /// Delegate definition for remote rename failure callback.
+ /// <para>
+ /// This callback will be called to notify the caller of fetch refspecs
+ /// that haven't been automatically updated and need potential manual tweaking.
+ /// </para>
+ /// </summary>
+ /// <param name="problematicRefspec">The refspec which didn't match the default.</param>
+ public delegate void RemoteRenameFailureHandler(string problematicRefspec);
+
+ /// <summary>
/// The stages of pack building.
/// </summary>
public enum PackBuilderStage
diff --git a/LibGit2Sharp/RemoteCollection.cs b/LibGit2Sharp/RemoteCollection.cs
index 300ed8f7..782316af 100644
--- a/LibGit2Sharp/RemoteCollection.cs
+++ b/LibGit2Sharp/RemoteCollection.cs
@@ -6,6 +6,7 @@ using System.Globalization;
using System.Linq;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;
+using LibGit2Sharp.Handlers;
namespace LibGit2Sharp
{
@@ -138,6 +139,22 @@ namespace LibGit2Sharp
Proxy.git_remote_delete(repository.Handle, name);
}
+ /// <summary>
+ /// Renames an existing <see cref="Remote"/>.
+ /// </summary>
+ /// <param name="name">The current remote name.</param>
+ /// <param name="newName">The new name the existing remote should bear.</param>
+ /// <param name"renameCallback">The callback to be used when problems with renaming occur. (e.g. non-default fetch refspecs)</para>
+ /// <returns>A new <see cref="Remote"/>.</returns>
+ public virtual Remote Rename(string name, string newName, RemoteRenameFailureHandler callback = null)
+ {
+ Ensure.ArgumentNotNull(name, "name");
+ Ensure.ArgumentNotNull(newName, "newName");
+
+ Proxy.git_remote_rename(repository.Handle, name, newName, callback);
+ return this[newName];
+ }
+
private string DebuggerDisplay
{
get