Skip to content
Merged
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
21 changes: 21 additions & 0 deletions LibGit2Sharp.Tests/RemoteFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
5 changes: 5 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
17 changes: 15 additions & 2 deletions LibGit2Sharp/RemoteUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,25 @@ public virtual TagFetchMode TagFetchMode
}
}

/// <summary>
/// Sets the url defined for this <see cref="Remote"/>
/// </summary>
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);
}
}
}

/// <summary>
/// Sets the list of <see cref="RefSpec"/>s defined for this <see cref="Remote"/> that are intended to
/// be used during a Fetch operation
/// </summary>
/// <remarks>Changing the list updates the <see cref="Remote" />.</remarks>
public virtual ICollection<string> FetchRefSpecs
{
get { return fetchRefSpecs; }
Expand All @@ -97,7 +111,6 @@ public virtual ICollection<string> FetchRefSpecs
/// Sets or gets the list of <see cref="RefSpec"/>s defined for this <see cref="Remote"/> that are intended to
/// be used during a Push operation
/// </summary>
/// <remarks>Changing the list updates the <see cref="Remote" />.</remarks>
public virtual ICollection<string> PushRefSpecs
{
get { return pushRefSpecs; }
Expand Down