Skip to content

Commit e375250

Browse files
committed
fixup! Moar
1 parent 7e0c64b commit e375250

File tree

4 files changed

+83
-8
lines changed

4 files changed

+83
-8
lines changed

LibGit2Sharp/Configuration.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ public virtual void Unset(string key, ConfigurationLevel level)
151151
}
152152
}
153153

154+
internal void UnsetMultivar(string key, ConfigurationLevel level)
155+
{
156+
Ensure.ArgumentNotNullOrEmptyString(key, "key");
157+
158+
using (ConfigurationSafeHandle h = RetrieveConfigurationHandle(level, true, configHandle))
159+
{
160+
Proxy.git_config_delete_multivar(h, key);
161+
}
162+
}
163+
154164
/// <summary>
155165
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
156166
/// </summary>

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ internal static extern int git_commit_create_from_ids(
274274
[DllImport(libgit2)]
275275
internal static extern int git_config_delete_entry(ConfigurationSafeHandle cfg, string name);
276276

277+
[DllImport(libgit2)]
278+
internal static extern int git_config_delete_multivar(
279+
ConfigurationSafeHandle cfg,
280+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof (StrictUtf8Marshaler))] string name,
281+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string regexp);
282+
277283
[DllImport(libgit2)]
278284
internal static extern int git_config_find_global(GitBuf global_config_path);
279285

@@ -1072,12 +1078,24 @@ internal static extern int git_remote_set_url(
10721078
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string remote,
10731079
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url);
10741080

1081+
[DllImport(libgit2)]
1082+
internal static extern int git_remote_add_fetch(
1083+
RepositorySafeHandle repo,
1084+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string remote,
1085+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url);
1086+
10751087
[DllImport(libgit2)]
10761088
internal static extern int git_remote_set_pushurl(
10771089
RepositorySafeHandle repo,
10781090
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string remote,
10791091
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url);
10801092

1093+
[DllImport(libgit2)]
1094+
internal static extern int git_remote_add_push(
1095+
RepositorySafeHandle repo,
1096+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string remote,
1097+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url);
1098+
10811099
[DllImport(libgit2)]
10821100
internal static extern int git_remote_is_valid_name(
10831101
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string remote_name);

LibGit2Sharp/Core/Proxy.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,22 @@ public static bool git_config_delete(ConfigurationSafeHandle config, string name
472472
}
473473
}
474474

475+
public static bool git_config_delete_multivar(ConfigurationSafeHandle config, string name)
476+
{
477+
using (ThreadAffinity())
478+
{
479+
int res = NativeMethods.git_config_delete_multivar(config, name, ".*");
480+
481+
if (res == (int)GitErrorCode.NotFound)
482+
{
483+
return false;
484+
}
485+
486+
Ensure.ZeroResult(res);
487+
return true;
488+
}
489+
}
490+
475491
public static FilePath git_config_find_global()
476492
{
477493
return ConvertPath(NativeMethods.git_config_find_global);
@@ -2159,6 +2175,15 @@ public static void git_remote_set_url(RepositorySafeHandle repo, string remote,
21592175
}
21602176
}
21612177

2178+
public static void git_remote_add_fetch(RepositorySafeHandle repo, string remote, string url)
2179+
{
2180+
using (ThreadAffinity())
2181+
{
2182+
int res = NativeMethods.git_remote_add_fetch(repo, remote, url);
2183+
Ensure.ZeroResult(res);
2184+
}
2185+
}
2186+
21622187
public static void git_remote_set_pushurl(RepositorySafeHandle repo, string remote, string url)
21632188
{
21642189
using (ThreadAffinity())
@@ -2168,6 +2193,15 @@ public static void git_remote_set_pushurl(RepositorySafeHandle repo, string remo
21682193
}
21692194
}
21702195

2196+
public static void git_remote_add_push(RepositorySafeHandle repo, string remote, string url)
2197+
{
2198+
using (ThreadAffinity())
2199+
{
2200+
int res = NativeMethods.git_remote_add_push(repo, remote, url);
2201+
Ensure.ZeroResult(res);
2202+
}
2203+
}
2204+
21712205
public static void git_remote_fetch(RemoteSafeHandle remote, GitFetchOptions fetchOptions, string logMessage)
21722206
{
21732207
using (ThreadAffinity())

LibGit2Sharp/RemoteUpdater.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Linq;
45
using LibGit2Sharp.Core;
56
using LibGit2Sharp.Core.Handles;
67

@@ -36,26 +37,38 @@ internal RemoteUpdater(Repository repo, Remote remote)
3637

3738
private IEnumerable<string> GetFetchRefSpecs()
3839
{
39-
throw new NotImplementedException();
40-
//return Proxy.git_remote_get_fetch_refspecs(remoteHandle);
40+
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_lookup(repo.Handle, remote.Name, true))
41+
{
42+
return Proxy.git_remote_get_fetch_refspecs(remoteHandle);
43+
}
4144
}
4245

4346
private void SetFetchRefSpecs(IEnumerable<string> value)
4447
{
45-
throw new NotImplementedException();
46-
//Proxy.git_remote_set_fetch_refspecs(remoteHandle, value);
48+
repo.Config.UnsetMultivar(string.Format("remote.{0}.fetch", remote.Name), ConfigurationLevel.Local);
49+
50+
foreach (var url in value)
51+
{
52+
Proxy.git_remote_add_fetch(repo.Handle, remote.Name, url);
53+
}
4754
}
4855

4956
private IEnumerable<string> GetPushRefSpecs()
5057
{
51-
throw new NotImplementedException();
52-
//return Proxy.git_remote_get_push_refspecs(remoteHandle);
58+
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_lookup(repo.Handle, remote.Name, true))
59+
{
60+
return Proxy.git_remote_get_push_refspecs(remoteHandle);
61+
}
5362
}
5463

5564
private void SetPushRefSpecs(IEnumerable<string> value)
5665
{
57-
throw new NotImplementedException();
58-
//Proxy.git_remote_set_push_refspecs(remoteHandle, value);
66+
repo.Config.UnsetMultivar(string.Format("remote.{0}.push", remote.Name), ConfigurationLevel.Local);
67+
68+
foreach (var url in value)
69+
{
70+
Proxy.git_remote_add_push(repo.Handle, remote.Name, url);
71+
}
5972
}
6073

6174
/// <summary>

0 commit comments

Comments
 (0)