diff --git a/LibGit2Sharp.Tests/RemoteFixture.cs b/LibGit2Sharp.Tests/RemoteFixture.cs index f07ba3ffb..72a2fa674 100644 --- a/LibGit2Sharp.Tests/RemoteFixture.cs +++ b/LibGit2Sharp.Tests/RemoteFixture.cs @@ -68,6 +68,27 @@ public void CanSetTagFetchMode(TagFetchMode tagFetchMode) } } + [Fact] + public void CanSetRemoteUrl() + { + string path = CloneBareTestRepo(); + using (var repo = new Repository(path)) + { + const string name = "upstream"; + const string url = "https://github.com/libgit2/libgit2sharp.git"; + const string newUrl = "https://github.com/libgit2/libgit2.git"; + + repo.Network.Remotes.Add(name, url); + Remote remote = repo.Network.Remotes[name]; + Assert.NotNull(remote); + + Remote updatedremote = repo.Network.Remotes.Update(remote, + r => r.Url = newUrl); + + Assert.Equal(newUrl, updatedremote.Url); + } + } + [Fact] public void CanCheckEqualityOfRemote() { diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 9a3d72076..558748ed1 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -1069,6 +1069,11 @@ internal static extern int git_remote_fetch( [DllImport(libgit2)] internal static extern int git_remote_set_push_refspecs(RemoteSafeHandle remote, ref GitStrArray array); + [DllImport(libgit2)] + internal static extern int git_remote_set_url( + RemoteSafeHandle remote, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url); + [DllImport(libgit2)] internal static extern int git_remote_is_valid_name( [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string remote_name); diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index 5ab210936..0dbd910da 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -1975,6 +1975,15 @@ public static void git_remote_set_push_refspecs(RemoteSafeHandle remote, IEnumer } } + public static void git_remote_set_url(RemoteSafeHandle remote, string url) + { + using (ThreadAffinity()) + { + int res = NativeMethods.git_remote_set_url(remote, url); + Ensure.ZeroResult(res); + } + } + public static void git_remote_fetch(RemoteSafeHandle remote, Signature signature, string logMessage) { using (ThreadAffinity()) diff --git a/LibGit2Sharp/RemoteUpdater.cs b/LibGit2Sharp/RemoteUpdater.cs index 3759ff498..e63172817 100644 --- a/LibGit2Sharp/RemoteUpdater.cs +++ b/LibGit2Sharp/RemoteUpdater.cs @@ -82,11 +82,25 @@ public virtual TagFetchMode TagFetchMode } } + /// + /// Sets the url defined for this + /// + public virtual string Url + { + set + { + using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repo.Handle, remote.Name, true)) + { + Proxy.git_remote_set_url(remoteHandle, value); + Proxy.git_remote_save(remoteHandle); + } + } + } + /// /// Sets the list of s defined for this that are intended to /// be used during a Fetch operation /// - /// Changing the list updates the . public virtual ICollection FetchRefSpecs { get { return fetchRefSpecs; } @@ -97,7 +111,6 @@ public virtual ICollection FetchRefSpecs /// Sets or gets the list of s defined for this that are intended to /// be used during a Push operation /// - /// Changing the list updates the . public virtual ICollection PushRefSpecs { get { return pushRefSpecs; }