8000 Support separate push url for remotes · thatfrankdev/libgit2sharp@2cf68ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 2cf68ce

Browse files
author
Ryan Roden-Corrent
committed
Support separate push url for remotes
1 parent a0776fa commit 2cf68ce

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

LibGit2Sharp.Tests/RemoteFixture.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ public void CanSetRemoteUrl()
9494
}
9595
}
9696

97+
[Fact]
98+
public void CanSetRemotePushUrl()
99+
{
100+
string path = SandboxBareTestRepo();
101+
using (var repo = new Repository(path))
102+
{
103+
const string name = "upstream";
104+
const string url = "https://github.com/libgit2/libgit2sharp.git";
105+
const string pushurl = "https://github.com/libgit2/libgit2.git";
106+
107+
repo.Network.Remotes.Add(name, url);
108+
Remote remote = repo.Network.Remotes[name];
109+
Assert.NotNull(remote);
110+
111+
Remote updatedremote = repo.Network.Remotes.Update(remote,
112+
r => r.PushUrl = pushurl);
113+
114+
Assert.Equal(pushurl, updatedremote.PushUrl);
115+
}
116+
}
117+
97118
[Fact]
98119
public void CanCheckEqualityOfRemote()
99120
{

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,11 @@ internal static extern int git_remote_set_url(
10751075
RemoteSafeHandle remote,
10761076
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url);
10771077

1078+
[DllImport(libgit2)]
1079+
internal static extern int git_remote_set_pushurl(
1080+
RemoteSafeHandle remote,
1081+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url);
1082+
10781083
[DllImport(libgit2)]
10791084
internal static extern int git_remote_is_valid_name(
10801085
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string remote_name);
@@ -1104,6 +1109,10 @@ internal static extern int git_remote_lookup(
11041109
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
11051110
internal static extern string git_remote_url(RemoteSafeHandle remote);
11061111

1112+
[DllImport(libgit2)]
1113+
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
1114+
internal static extern string git_remote_pushurl(RemoteSafeHandle remote);
1115+
11071116
[DllImport(libgit2)]
11081117
internal static extern void git_remote_set_autotag(RemoteSafeHandle remote, TagFetchMode option);
11091118

LibGit2Sharp/Core/Proxy.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,15 @@ public static void git_remote_set_url(RemoteSafeHandle remote, string url)
20402040
Ensure.ZeroResult(res);
20412041
}
20422042
}
2043+
2044+
public static void git_remote_set_pushurl(RemoteSafeHandle remote, string url)
2045+
{
2046+
using (ThreadAffinity())
2047+
{
2048+
int res = NativeMethods.git_remote_set_pushurl(remote, url);
2049+
Ensure.ZeroResult(res);
2050+
}
2051+
}
20432052

20442053
public static void git_remote_fetch(RemoteSafeHandle remote, Signature signature, string logMessage)
20452054
{
@@ -2223,6 +2232,11 @@ public static string git_remote_url(RemoteSafeHandle remote)
22232232
return NativeMethods.git_remote_url(remote);
22242233
}
22252234

2235+
public static string git_remote_pushurl(RemoteSafeHandle remote)
2236+
{
2237+
return NativeMethods.git_remote_pushurl(remote);
2238+
}
2239+
22262240
#endregion
22272241

22282242
#region git_repository_

LibGit2Sharp/Remote.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace LibGit2Sharp
1515
public class Remote : IEquatable<Remote>, IBelongToARepository
1616
{
1717
private static readonly LambdaEqualityHelper<Remote> equalityHelper =
18-
new LambdaEqualityHelper<Remote>(x => x.Name, x => x.Url);
18+
new LambdaEqualityHelper<Remote>(x => x.Name, x => x.Url, x => x.PushUrl);
1919

2020
internal readonly Repository repository;
2121

@@ -32,6 +32,7 @@ private Remote(RemoteSafeHandle handle, Repository repository)
3232
this.repository = repository;
3333
Name = Proxy.git_remote_name(handle);
3434
Url = Proxy.git_remote_url(handle);
35+
PushUrl = Proxy.git_remote_pushurl(handle);
3536
TagFetchMode = Proxy.git_remote_autotag(handle);
3637
refSpecs = new RefSpecCollection(handle);
3738
}
@@ -53,6 +54,12 @@ internal static Remote BuildFromPtr(RemoteSafeHandle handle, Repository repo)
5354
/// </summary>
5455
public virtual string Url { get; private set; }
5556

57+
/// <summary>
58+
/// Gets the distinct push url for this remote repository, if set.
59+
/// If no separate push url is specified, PushUrl is null.
60+
/// </summary>
61+
public virtual string PushUrl { get; private set; }
62+
5663
/// <summary>
5764
/// Gets the Tag Fetch Mode of the remote - indicating how tags are fetched.
5865
/// </summary>

LibGit2Sharp/RemoteUpdater.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ public virtual string Url
7676
Proxy.git_remote_save(remoteHandle);
7777
}
7878
}
79+
80+
/// <summary>
81+
/// Sets the push url defined for this <see cref="Remote"/>
82+
/// </summary>
83+
public virtual string PushUrl
84+
{
85+
set
86+
{
87+
Proxy.git_remote_set_pushurl(remoteHandle, value);
88+
Proxy.git_remote_save(remoteHandle);
89+
}
90+
}
7991

8092
/// <summary>
8193
/// Sets the list of <see cref="RefSpec"/>s defined for this <see cref="Remote"/> that are intended to

0 commit comments

Comments
 (0)
0