From 80c28e91d88ff40ce7ea3fc74a086e2471b58658 Mon Sep 17 00:00:00 2001 From: Jerome Doby Date: Fri, 8 Feb 2013 17:42:34 -0600 Subject: [PATCH 1/5] Added Credentials parameter for Push Signed-off-by: Jerome Doby --- LibGit2Sharp/Network.cs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index c9af43e30..087876ecd 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -58,17 +58,19 @@ public virtual RemoteCollection Remotes /// The source objectish to push. /// The reference to update on the remote. /// Handler for reporting failed push updates. + /// Optional instance for SSH authentication. public virtual void Push( Remote remote, string objectish, string destinationSpec, - PushStatusErrorHandler onPushStatusError) + PushStatusErrorHandler onPushStatusError, + Credentials credentials) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); Ensure.ArgumentNotNullOrEmptyString(destinationSpec, destinationSpec); - Push(remote, string.Format("{0}:{1}", objectish, destinationSpec), onPushStatusError); + Push(remote, string.Format("{0}:{1}", objectish, destinationSpec), onPushStatusError, credentials); } /// @@ -76,16 +78,18 @@ public virtual void Push( /// /// The to push to. /// The pushRefSpec to push. - /// Handler for reporting failed push updates. + /// Handler for reporting failed push updates. + /// Optional instance for SSH authentication. public virtual void Push( Remote remote, string pushRefSpec, - PushStatusErrorHandler onPushStatusError) + PushStatusErrorHandler onPushStatusError, + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); - Push(remote, new string[] { pushRefSpec }, onPushStatusError); + Push(remote, new string[] { pushRefSpec }, onPushStatusError, credentials); } /// @@ -94,10 +98,12 @@ public virtual void Push( /// The to push to. /// The pushRefSpecs to push. /// Handler for reporting failed push updates. + /// Optional instance for SSH authentication. public virtual void Push( Remote remote, IEnumerable pushRefSpecs, - PushStatusErrorHandler onPushStatusError) + PushStatusErrorHandler onPushStatusError, + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); @@ -113,6 +119,15 @@ public virtual void Push( // Load the remote. using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { + if ( credentials != null ) { + Proxy.git_remote_set_cred_acquire_cb( + remoteHandle, + ( out IntPtr cred, IntPtr url, uint types, IntPtr payload ) => + NativeMethods.git_cred_userpass_plaintext_new( out cred, credentials.Username, credentials.Password ), + IntPtr.Zero + ); + } + try { Proxy.git_remote_connect(remoteHandle, GitDirection.Push); From ecdd23563fdc0d2d334465a4a03e18d71576bad2 Mon Sep 17 00:00:00 2001 From: Jerome Doby Date: Fri, 8 Feb 2013 23:44:45 -0600 Subject: [PATCH 2/5] Parameters for NetworkExtension.Push() to accept Credentials. Signed-off-by: Jerome Doby --- LibGit2Sharp/Network.cs | 23 ++++++++++++----------- LibGit2Sharp/NetworkExtensions.cs | 29 +++++++++++++++++------------ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index 087876ecd..2ecef3996 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -64,7 +64,7 @@ public virtual void Push( string objectish, string destinationSpec, PushStatusErrorHandler onPushStatusError, - Credentials credentials) + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); @@ -119,16 +119,17 @@ public virtual void Push( // Load the remote. using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { - if ( credentials != null ) { - Proxy.git_remote_set_cred_acquire_cb( - remoteHandle, - ( out IntPtr cred, IntPtr url, uint types, IntPtr payload ) => - NativeMethods.git_cred_userpass_plaintext_new( out cred, credentials.Username, credentials.Password ), - IntPtr.Zero - ); - } - - try + if (credentials != null) + { + Proxy.git_remote_set_cred_acquire_cb( + remoteHandle, + (out IntPtr cred, IntPtr url, uint types, IntPtr payload) => + NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password), + IntPtr.Zero + ); + } + + try { Proxy.git_remote_connect(remoteHandle, GitDirection.Push); diff --git a/LibGit2Sharp/NetworkExtensions.cs b/LibGit2Sharp/NetworkExtensions.cs index 9e7a41299..587c9c832 100644 --- a/LibGit2Sharp/NetworkExtensions.cs +++ b/LibGit2Sharp/NetworkExtensions.cs @@ -17,19 +17,21 @@ public static class NetworkExtensions /// The being worked with. /// The to push to. /// The source objectish to push. - /// The reference to update on the remote. + /// The reference to update on the remote. + /// Optional instance for SSH authentication. /// Results of the push operation. public static PushResult Push( this Network network, Remote remote, string objectish, - string destinationSpec) + string destinationSpec, + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); Ensure.ArgumentNotNullOrEmptyString(destinationSpec, "destinationSpec"); - return network.Push(remote, string.Format("{0}:{1}", objectish, destinationSpec)); + return network.Push(remote, string.Format("{0}:{1}", objectish, destinationSpec), credentials); } /// @@ -37,14 +39,15 @@ public static PushResult Push( /// /// The being worked with. /// The to push to. - /// The pushRefSpec to push. + /// The pushRefSpec to push. + /// Optional instance for SSH authentication. /// Results of the push operation. - public static PushResult Push(this Network network, Remote remote, string pushRefSpec) + public static PushResult Push(this Network network, Remote remote, string pushRefSpec, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); - return network.Push(remote, new string[] { pushRefSpec }); + return network.Push(remote, new string[] { pushRefSpec }, credentials); } /// @@ -52,19 +55,21 @@ public static PushResult Push(this Network network, Remote remote, string pushRe /// /// The being worked with. /// The to push to. - /// The pushRefSpecs to push. + /// The pushRefSpecs to push. + /// Optional instance for SSH authentication. /// Results of the push operation. - public static PushResult Push(this Network network, Remote remote, IEnumerable pushRefSpecs) + public static PushResult Push(this Network network, Remote remote, IEnumerable pushRefSpecs, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); List failedRemoteUpdates = new List(); - network.Push( - remote, - pushRefSpecs, - failedRemoteUpdates.Add); + network.Push( + remote, + pushRefSpecs, + failedRemoteUpdates.Add, + credentials); return new PushResult(failedRemoteUpdates); } From 2e9786cbc039d4a9b86834bedc8ebd46fcf65dbe Mon Sep 17 00:00:00 2001 From: Jerome Doby Date: Sat, 9 Feb 2013 00:10:48 -0600 Subject: [PATCH 3/5] Fixed whitespace. Signed-off-by: Jerome Doby --- LibGit2Sharp/Network.cs | 34 +++++++++++++++---------------- LibGit2Sharp/NetworkExtensions.cs | 24 +++++++++++----------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index 2ecef3996..15f931bc8 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -58,7 +58,7 @@ public virtual RemoteCollection Remotes /// The source objectish to push. /// The reference to update on the remote. /// Handler for reporting failed push updates. - /// Optional instance for SSH authentication. + /// Optional instance for SSH authentication. public virtual void Push( Remote remote, string objectish, @@ -78,13 +78,13 @@ public virtual void Push( /// /// The to push to. /// The pushRefSpec to push. - /// Handler for reporting failed push updates. - /// Optional instance for SSH authentication. + /// Handler for reporting failed push updates. + /// Optional instance for SSH authentication. public virtual void Push( Remote remote, string pushRefSpec, PushStatusErrorHandler onPushStatusError, - Credentials credentials = null) + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); @@ -98,12 +98,12 @@ public virtual void Push( /// The to push to. /// The pushRefSpecs to push. /// Handler for reporting failed push updates. - /// Optional instance for SSH authentication. + /// Optional instance for SSH authentication. public virtual void Push( Remote remote, IEnumerable pushRefSpecs, PushStatusErrorHandler onPushStatusError, - Credentials credentials = null) + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); @@ -119,17 +119,17 @@ public virtual void Push( // Load the remote. using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { - if (credentials != null) - { - Proxy.git_remote_set_cred_acquire_cb( - remoteHandle, - (out IntPtr cred, IntPtr url, uint types, IntPtr payload) => - NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password), - IntPtr.Zero - ); - } - - try + if (credentials != null) + { + Proxy.git_remote_set_cred_acquire_cb( + remoteHandle, + (out IntPtr cred, IntPtr url, uint types, IntPtr payload) => + NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password), + IntPtr.Zero + ); + } + + try { Proxy.git_remote_connect(remoteHandle, GitDirection.Push); diff --git a/LibGit2Sharp/NetworkExtensions.cs b/LibGit2Sharp/NetworkExtensions.cs index 587c9c832..db609ce98 100644 --- a/LibGit2Sharp/NetworkExtensions.cs +++ b/LibGit2Sharp/NetworkExtensions.cs @@ -17,15 +17,15 @@ public static class NetworkExtensions /// The being worked with. /// The to push to. /// The source objectish to push. - /// The reference to update on the remote. - /// Optional instance for SSH authentication. + /// The reference to update on the remote. + /// Optional instance for SSH authentication. /// Results of the push operation. public static PushResult Push( this Network network, Remote remote, string objectish, string destinationSpec, - Credentials credentials = null) + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); @@ -39,8 +39,8 @@ public static PushResult Push( /// /// The being worked with. /// The to push to. - /// The pushRefSpec to push. - /// Optional instance for SSH authentication. + /// The pushRefSpec to push. + /// Optional instance for SSH authentication. /// Results of the push operation. public static PushResult Push(this Network network, Remote remote, string pushRefSpec, Credentials credentials = null) { @@ -55,8 +55,8 @@ public static PushResult Push(this Network network, Remote remote, string pushRe /// /// The being worked with. /// The to push to. - /// The pushRefSpecs to push. - /// Optional instance for SSH authentication. + /// The pushRefSpecs to push. + /// Optional instance for SSH authentication. /// Results of the push operation. public static PushResult Push(this Network network, Remote remote, IEnumerable pushRefSpecs, Credentials credentials = null) { @@ -65,11 +65,11 @@ public static PushResult Push(this Network network, Remote remote, IEnumerable failedRemoteUpdates = new List(); - network.Push( - remote, - pushRefSpecs, - failedRemoteUpdates.Add, - credentials); + network.Push( + remote, + pushRefSpecs, + failedRemoteUpdates.Add, + credentials); return new PushResult(failedRemoteUpdates); } From e8638d0f70a1699f1def2d1a49803dd496f1d91e Mon Sep 17 00:00:00 2001 From: Jerome Doby Date: Sat, 9 Feb 2013 14:56:39 -0600 Subject: [PATCH 4/5] Fixed documentation. Signed-off-by: Jerome Doby --- LibGit2Sharp/Network.cs | 9 ++++----- LibGit2Sharp/NetworkExtensions.cs | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index 15f931bc8..82813900f 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -58,7 +58,7 @@ public virtual RemoteCollection Remotes /// The source objectish to push. /// The reference to update on the remote. /// Handler for reporting failed push updates. - /// Optional instance for SSH authentication. + /// Credentials to use for user/pass authentication public virtual void Push( Remote remote, string objectish, @@ -79,7 +79,7 @@ public virtual void Push( /// The to push to. /// The pushRefSpec to push. /// Handler for reporting failed push updates. - /// Optional instance for SSH authentication. + /// Credentials to use for user/pass authentication public virtual void Push( Remote remote, string pushRefSpec, @@ -98,7 +98,7 @@ public virtual void Push( /// The to push to. /// The pushRefSpecs to push. /// Handler for reporting failed push updates. - /// Optional instance for SSH authentication. + /// Credentials to use for user/pass authentication public virtual void Push( Remote remote, IEnumerable pushRefSpecs, @@ -125,8 +125,7 @@ public virtual void Push( remoteHandle, (out IntPtr cred, IntPtr url, uint types, IntPtr payload) => NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password), - IntPtr.Zero - ); + IntPtr.Zero); } try diff --git a/LibGit2Sharp/NetworkExtensions.cs b/LibGit2Sharp/NetworkExtensions.cs index db609ce98..7b260194e 100644 --- a/LibGit2Sharp/NetworkExtensions.cs +++ b/LibGit2Sharp/NetworkExtensions.cs @@ -18,7 +18,7 @@ public static class NetworkExtensions /// The to push to. /// The source objectish to push. /// The reference to update on the remote. - /// Optional instance for SSH authentication. + /// Credentials to use for user/pass authentication /// Results of the push operation. public static PushResult Push( this Network network, @@ -40,7 +40,7 @@ public static PushResult Push( /// The being worked with. /// The to push to. /// The pushRefSpec to push. - /// Optional instance for SSH authentication. + /// Credentials to use for user/pass authentication /// Results of the push operation. public static PushResult Push(this Network network, Remote remote, string pushRefSpec, Credentials credentials = null) { @@ -56,7 +56,7 @@ public static PushResult Push(this Network network, Remote remote, string pushRe /// The being worked with. /// The to push to. /// The pushRefSpecs to push. - /// Optional instance for SSH authentication. + /// Credentials to use for user/pass authentication /// Results of the push operation. public static PushResult Push(this Network network, Remote remote, IEnumerable pushRefSpecs, Credentials credentials = null) { From cf47deab66ae52170f5717a147ad759d58b48ab2 Mon Sep 17 00:00:00 2001 From: Jerome Doby Date: Fri, 8 Feb 2013 17:42:34 -0600 Subject: [PATCH 5/5] Added Credentials parameter for Push Signed-off-by: Jerome Doby --- LibGit2Sharp/Network.cs | 25 ++++++++++++++++++++----- LibGit2Sharp/NetworkExtensions.cs | 17 +++++++++++------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index c9af43e30..82813900f 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -58,17 +58,19 @@ public virtual RemoteCollection Remotes /// The source objectish to push. /// The reference to update on the remote. /// Handler for reporting failed push updates. + /// Credentials to use for user/pass authentication public virtual void Push( Remote remote, string objectish, string destinationSpec, - PushStatusErrorHandler onPushStatusError) + PushStatusErrorHandler onPushStatusError, + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); Ensure.ArgumentNotNullOrEmptyString(destinationSpec, destinationSpec); - Push(remote, string.Format("{0}:{1}", objectish, destinationSpec), onPushStatusError); + Push(remote, string.Format("{0}:{1}", objectish, destinationSpec), onPushStatusError, credentials); } /// @@ -77,15 +79,17 @@ public virtual void Push( /// The to push to. /// The pushRefSpec to push. /// Handler for reporting failed push updates. + /// Credentials to use for user/pass authentication public virtual void Push( Remote remote, string pushRefSpec, - PushStatusErrorHandler onPushStatusError) + PushStatusErrorHandler onPushStatusError, + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); - Push(remote, new string[] { pushRefSpec }, onPushStatusError); + Push(remote, new string[] { pushRefSpec }, onPushStatusError, credentials); } /// @@ -94,10 +98,12 @@ public virtual void Push( /// The to push to. /// The pushRefSpecs to push. /// Handler for reporting failed push updates. + /// Credentials to use for user/pass authentication public virtual void Push( Remote remote, IEnumerable pushRefSpecs, - PushStatusErrorHandler onPushStatusError) + PushStatusErrorHandler onPushStatusError, + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); @@ -113,6 +119,15 @@ public virtual void Push( // Load the remote. using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { + if (credentials != null) + { + Proxy.git_remote_set_cred_acquire_cb( + remoteHandle, + (out IntPtr cred, IntPtr url, uint types, IntPtr payload) => + NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password), + IntPtr.Zero); + } + try { Proxy.git_remote_connect(remoteHandle, GitDirection.Push); diff --git a/LibGit2Sharp/NetworkExtensions.cs b/LibGit2Sharp/NetworkExtensions.cs index 9e7a41299..7b260194e 100644 --- a/LibGit2Sharp/NetworkExtensions.cs +++ b/LibGit2Sharp/NetworkExtensions.cs @@ -18,18 +18,20 @@ public static class NetworkExtensions /// The to push to. /// The source objectish to push. /// The reference to update on the remote. + /// Credentials to use for user/pass authentication /// Results of the push operation. public static PushResult Push( this Network network, Remote remote, string objectish, - string destinationSpec) + string destinationSpec, + Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); Ensure.ArgumentNotNullOrEmptyString(destinationSpec, "destinationSpec"); - return network.Push(remote, string.Format("{0}:{1}", objectish, destinationSpec)); + return network.Push(remote, string.Format("{0}:{1}", objectish, destinationSpec), credentials); } /// @@ -38,13 +40,14 @@ public static PushResult Push( /// The being worked with. /// The to push to. /// The pushRefSpec to push. + /// Credentials to use for user/pass authentication /// Results of the push operation. - public static PushResult Push(this Network network, Remote remote, string pushRefSpec) + public static PushResult Push(this Network network, Remote remote, string pushRefSpec, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); - return network.Push(remote, new string[] { pushRefSpec }); + return network.Push(remote, new string[] { pushRefSpec }, credentials); } /// @@ -53,8 +56,9 @@ public static PushResult Push(this Network network, Remote remote, string pushRe /// The being worked with. /// The to push to. /// The pushRefSpecs to push. + /// Credentials to use for user/pass authentication /// Results of the push operation. - public static PushResult Push(this Network network, Remote remote, IEnumerable pushRefSpecs) + public static PushResult Push(this Network network, Remote remote, IEnumerable pushRefSpecs, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); @@ -64,7 +68,8 @@ public static PushResult Push(this Network network, Remote remote, IEnumerable