diff --git a/LibGit2Sharp.Tests/RemoteFixture.cs b/LibGit2Sharp.Tests/RemoteFixture.cs
index b25277faa..b33213495 100644
--- a/LibGit2Sharp.Tests/RemoteFixture.cs
+++ b/LibGit2Sharp.Tests/RemoteFixture.cs
@@ -189,5 +189,30 @@ public void CanCreateARemoteWithASpecifiedFetchRefSpec()
Assert.Equal("+refs/heads/*:refs/remotes/grmpf/*", remote.RefSpecs.Single().Specification);
}
}
+
+ [Fact]
+ public void CanDeleteExistingRemote()
+ {
+ var path = CloneStandardTestRepo();
+ using (var repo = new Repository(path))
+ {
+ Assert.NotNull(repo.Network.Remotes["origin"]);
+ Assert.NotEmpty(repo.Refs.FromGlob("refs/remotes/origin/*"));
+
+ repo.Network.Remotes.Remove("origin");
+ Assert.Null(repo.Network.Remotes["origin"]);
+ Assert.Empty(repo.Refs.FromGlob("refs/remotes/origin/*"));
+ }
+ }
+
+ [Fact]
+ public void CanDeleteNonExistingRemote()
+ {
+ using (var repo = new Repository(StandardTestRepoPath))
+ {
+ Assert.Null(repo.Network.Remotes["i_dont_exist"]);
+ repo.Network.Remotes.Remove("i_dont_exist");
+ }
+ }
}
}
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 09e6ac22d..faf1e02b5 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -994,6 +994,9 @@ internal static extern int git_remote_create_with_fetchspec(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string refspec);
+ [DllImport(libgit2)]
+ internal static extern int git_remote_delete(RemoteSafeHandle remote);
+
[DllImport(libgit2)]
internal static extern void git_remote_disconnect(RemoteSafeHandle remote);
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 64744d0d7..167645b26 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -1785,6 +1785,24 @@ public static void git_remote_connect(RemoteSafeHandle remote, GitDirection dire
}
}
+ public static void git_remote_delete(RepositorySafeHandle repo, string name)
+ {
+ using (ThreadAffinity())
+ {
+ using (RemoteSafeHandle remote = git_remote_load(repo, name, false))
+ {
+ if (remote == null)
+ {
+ return;
+ }
+
+ int res = NativeMethods.git_remote_delete(remote);
+ Ensure.ZeroResult(res);
+ remote.SetHandleAsInvalid();
+ }
+ }
+ }
+
public static void git_remote_disconnect(RemoteSafeHandle remote)
{
using (ThreadAffinity())
diff --git a/LibGit2Sharp/RemoteCollection.cs b/LibGit2Sharp/RemoteCollection.cs
index bd031eeba..443dc3f5f 100644
--- a/LibGit2Sharp/RemoteCollection.cs
+++ b/LibGit2Sharp/RemoteCollection.cs
@@ -137,6 +137,18 @@ public virtual bool IsValidName(string name)
return Remote.IsValidName(name);
}
+ ///
+ /// Deletes the with the specified name.
+ ///
+ /// The name of the remote to remove.
+ /// A new .
+ public virtual void Remove(string name)
+ {
+ Ensure.ArgumentNotNull(name, "name");
+
+ Proxy.git_remote_delete(repository.Handle, name);
+ }
+
private string DebuggerDisplay
{
get