Skip to content

Commit 2597ae8

Browse files
author
Edward Thomson
committed
Update git_remote_rename to reflect new libgit2 signature
1 parent a05561b commit 2597ae8

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

LibGit2Sharp.Tests/RemoteFixture.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ public void CanRenameExistingRemote()
259259
}
260260

261261
[Fact]
262-
public void CanRenameNonExistingRemote()
262+
public void RenamingNonExistingRemoteThrows()
263263
{
264264
using (var repo = new Repository(StandardTestRepoPath))
265265
{
266-
Assert.Null(repo.Network.Remotes["i_dont_exist"]);
267-
268-
repo.Network.Remotes.Rename("i_dont_exist", "i_dont_either", problem => Assert.True(false));
269-
Assert.Null(repo.Network.Remotes["i_dont_either"]);
266+
Assert.Throws<NotFoundException>(() =>
267+
{
268+
repo.Network.Remotes.Rename("i_dont_exist", "i_dont_either");
269+
});
270270
}
271271
}
272272

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ internal static extern int git_branch_remote_name(
215215
[DllImport(libgit2)]
216216
internal static extern int git_remote_rename(
217217
ref GitStrArray problems,
218-
RemoteSafeHandle remote,
218+
RepositorySafeHandle repo,
219+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string old_name,
219220
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string new_name);
220221

221222
internal delegate int git_remote_rename_problem_cb(

LibGit2Sharp/Core/Proxy.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,39 +2125,38 @@ public static void git_remote_rename(RepositorySafeHandle repo, string name, str
21252125
{
21262126
using (ThreadAffinity())
21272127
{
2128-
using (RemoteSafeHandle remote = git_remote_load(repo, name, false))
2128+
if (callback == null)
21292129
{
2130-
if (remote == null)
2131-
{
2132-
return;
2133-
}
2130+
callback = problem => {};
2131+
}
21342132

2135-
if (callback == null)
2136-
{
2137-
callback = problem => {};
2138-
}
2133+
var array = new GitStrArrayNative();
21392134

2140-
var array = new GitStrArrayNative();
2135+
try
2136+
{
2137+
int res = NativeMethods.git_remote_rename(
2138+
ref array.Array,
2139+
repo,
2140+
name,
2141+
new_name);
21412142

2142-
try
2143+
if (res == (int)GitErrorCode.NotFound)
21432144
{
2144-
int res = NativeMethods.git_remote_rename(
2145-
ref array.Array,
2146-
remote,
2147-
new_name);
2145+
throw new NotFoundException(
2146+
string.Format("Remote '{0}' does not exist and cannot be renamed.", name));
2147+
}
21482148

2149-
Ensure.ZeroResult(res);
2149+
Ensure.ZeroResult(res);
21502150

2151-
foreach (var item in array.ReadStrings())
2152-
{
2153-
callback(item);
2154-
}
2155-
}
2156-
finally
2151+
foreach (var item in array.ReadStrings())
21572152
{
2158-
array.Dispose();
2153+
callback(item);
21592154
}
21602155
}
2156+
finally
2157+
{
2158+
array.Dispose();
2159+
}
21612160
}
21622161
}
21632162

0 commit comments

Comments
 (0)