-
Notifications
You must be signed in to change notification settings - Fork 899
Introduce RemoteCollection.Rename. #741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using LibGit2Sharp.Core.Handles; | ||
using LibGit2Sharp.Handlers; | ||
|
||
// ReSharper disable InconsistentNaming | ||
namespace LibGit2Sharp.Core | ||
|
@@ -1958,6 +1959,33 @@ public static string git_remote_name(RemoteSafeHandle remote) | |
return NativeMethods.git_remote_name(remote); | ||
} | ||
|
||
public static void git_remote_rename(RepositorySafeHandle repo, string name, string new_name, RemoteRenameFailureHandler callback) | ||
{ | ||
using (ThreadAffinity()) | ||
{ | ||
using (RemoteSafeHandle remote = git_remote_load(repo, name, false)) | ||
{ | ||
if (remote == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (callback == null) | ||
{ | ||
callback = (problem) => {}; | ||
} | ||
|
||
int res = NativeMethods.git_remote_rename( | ||
remote, | ||
new_name, | ||
(problem, payload) => { callback(problem); return 0; }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could send the callback as payload, but this works too and it's shorter and more concise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't we rather pass Grmpf... The callback doesn't seem to be as optional as it should be (cf https://github.com/libgit2/libgit2/blob/development/src/remote.c#L1450) /cc @carlosmn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yesh, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should go with returning a list of strings instead of using a callback, but making it optional would be a good first step. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would you handle normal rename issues then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would these "normal" issues be? AFAICT we only call this for non-default refspecs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see, you meant a ref param with a list of strings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, what in C# would be an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I'd rather avoid relying on ref/out params on public API as none of the user facing methods behave this way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I'm talking about the C interface. Hence the "would" :p You still get to keep your fancy return values. |
||
IntPtr.Zero); | ||
|
||
Ensure.ZeroResult(res); | ||
} | ||
} | ||
} | ||
|
||
public static void git_remote_save(RemoteSafeHandle remote) | ||
{ | ||
using (ThreadAffinity()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.