Skip to content

Commit 3916ea5

Browse files
tclemnulltoken
authored andcommitted
Delegate the handling of the default refSpec to libgit2 when creating a new Remote
Fix #164
1 parent bb202dc commit 3916ea5

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

LibGit2Sharp.Tests/RemoteFixture.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ public void CreatingANewRemoteAddsADefaultRefSpec()
8686
var refSpec = repo.Config.Get<string>("remote", remote.Name, "fetch", null);
8787
Assert.NotNull(refSpec);
8888

89-
//TODO: Uncomment the line below once https://github.com/libgit2/libgit2/pull/737 is merged
90-
//Assert.Equal("+refs/heads/*:refs/remotes/upstream/*", refSpec);
89+
Assert.Equal("+refs/heads/*:refs/remotes/upstream/*", refSpec);
9190
}
9291
}
9392

@@ -107,8 +106,7 @@ public void CanAddANewRemoteWithAFetchRefSpec()
107106
var refSpec = repo.Config.Get<string>("remote", name, "fetch", null);
108107
Assert.NotNull(refSpec);
109108

110-
//TODO: Uncomment the line below once https://github.com/libgit2/libgit2/pull/737 is merged
111-
//Assert.Equal(fetchRefSpec, refSpec);
109+
Assert.Equal(fetchRefSpec, refSpec);
112110
}
113111
}
114112
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,13 @@ public static extern int git_remote_load(
502502
[return : MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))]
503503
public static extern string git_remote_name(RemoteSafeHandle remote);
504504

505+
[DllImport(libgit2)]
506+
public static extern int git_remote_add(
507+
out RemoteSafeHandle remote,
508+
RepositorySafeHandle repo,
509+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name,
510+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string url);
511+
505512
[DllImport(libgit2)]
506513
public static extern int git_remote_new(
507514
out RemoteSafeHandle remote,

LibGit2Sharp/RemoteCollection.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,17 @@ IEnumerator IEnumerable.GetEnumerator()
9191
/// <returns>A new <see cref = "Remote" />.</returns>
9292
public virtual Remote Add(string name, string url)
9393
{
94-
string fetchRefSpec = string.Format("+refs/heads/*:refs/remotes/{0}/*", name);
94+
Ensure.ArgumentNotNull(name, "name");
95+
Ensure.ArgumentNotNull(url, "url");
96+
97+
RemoteSafeHandle handle;
98+
99+
Ensure.Success(NativeMethods.git_remote_add(out handle, repository.Handle, name, url));
95100

96-
return Add(name, url, fetchRefSpec);
101+
using (handle)
102+
{
103+
return Remote.CreateFromPtr(handle);
104+
}
97105
}
98106

99107
/// <summary>

0 commit comments

Comments
 (0)