/// <summary> /// Push specified reference to the <see cref="Remote"/>. /// </summary> /// <param name="network">The <see cref="Network"/> being worked with.</param> /// <param name="remote">The <see cref = "Remote" /> to push to.</param> /// <param name="pushRefSpec">The pushRefSpec to push.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> /// <returns>Results of the push operation.</returns> 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 }, credentials); }
public CredentialsDialog (string uri, SupportedCredentialTypes type, Credentials cred) { this.Build (); this.UseNativeContextMenus (); labelTop1.Text = string.Format (labelTop1.Text, uri); var table = new Table (0, 0, false); table.ColumnSpacing = 6; vbox.PackStart (table, true, true, 0); Widget firstEditor = null; switch (type) { case SupportedCredentialTypes.UsernamePassword: upcred = (UsernamePasswordCredentials)cred; firstEditor = CreateEntry (table, "Username:"******"Password:"******"Passphrase:", true); break; } table.ShowAll (); Focus = firstEditor; Default = buttonOk; }
public GitRepositoryContext(IRepository repository, Credentials credentials, bool isRemote, string repoUrl) { this.repository = repository; this.isRemote = isRemote; this.credentials = credentials; this.repoUrl = repoUrl; }
internal RemoteCallbacks(FetchOptions fetchOptions) { Ensure.ArgumentNotNull(fetchOptions, "fetchOptions"); Progress = fetchOptions.OnProgress; DownloadTransferProgress = fetchOptions.OnTransferProgress; UpdateTips = fetchOptions.OnUpdateTips; Credentials = fetchOptions.Credentials; }
public void Authenticate([FromBody] BlogModel.Credentials creds) { credentials = new UsernamePasswordCredentials { Username = creds.Id, Password = creds.Password }; }
private Credentials CredentialsProvider(string url, string usernameFromUrl, SupportedCredentialTypes types) { _credentials = new UsernamePasswordCredentials { Username = _allConfiguration.VsoConfiguration.ApiUsername, Password = _allConfiguration.VsoConfiguration.ApiPassword }; return _credentials; }
internal RemoteCallbacks( ProgressHandler onProgress = null, TransferProgressHandler onDownloadProgress = null, UpdateTipsHandler onUpdateTips = null, Credentials credentials = null) { Progress = onProgress; DownloadTransferProgress = onDownloadProgress; UpdateTips = onUpdateTips; Credentials = credentials; }
public GitProvider(IVBProject project, IRepository repository, ICredentials <SecureString> secureCredentials) : this(project, repository) { _credentials = new SecureUsernamePasswordCredentials() { Username = secureCredentials.Username, Password = secureCredentials.Password }; _credentialsHandler = (url, user, cred) => _credentials; }
public GitProvider(VBProject project, IRepository repository, string userName, string passWord, ICodePaneWrapperFactory wrapperFactory) : this(project, repository, wrapperFactory) { _credentials = new UsernamePasswordCredentials() { Username = userName, Password = passWord }; _credentialsHandler = (url, user, cred) => _credentials; }
public GitProvider(VBProject project, IRepository repository, ICredentials <SecureString> credentials, ICodePaneWrapperFactory wrapperFactory) : this(project, repository, wrapperFactory) { _credentials = new SecureUsernamePasswordCredentials() { Username = credentials.Username, Password = credentials.Password }; _credentialsHandler = (url, user, cred) => _credentials; }
public GitProvider(VBProject project, IRepository repository, ICredentials<SecureString> credentials, ICodePaneWrapperFactory wrapperFactory) : this(project, repository, wrapperFactory) { _credentials = new SecureUsernamePasswordCredentials() { Username = credentials.Username, Password = credentials.Password }; _credentialsHandler = (url, user, cred) => _credentials; }
public static void RemoteFetch( Remote remote, Credentials creds, Console console ) { try { remote.Fetch( TagFetchMode.Auto, OnProgress, OnCompletion, OnUpdateTips, OnTransferProgress, credentials: creds ); } catch ( System.Exception e ) { Debug.Log( e ); } }
/// <summary> /// Push the objectish to the destination reference on the <see cref = "Remote" />. /// </summary> /// <param name="network">The <see cref="Network"/> being worked with.</param> /// <param name="remote">The <see cref = "Remote" /> to push to.</param> /// <param name="objectish">The source objectish to push.</param> /// <param name="destinationSpec">The reference to update on the remote.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> /// <returns>Results of the push operation.</returns> public static PushResult Push( this Network network, Remote remote, string objectish, string destinationSpec, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); Ensure.ArgumentNotNullOrEmptyString(destinationSpec, "destinationSpec"); return network.Push(remote, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", objectish, destinationSpec), credentials); }
/// <summary> /// Push specified references to the <see cref="Remote"/>. /// </summary> /// <param name="network">The <see cref="Network"/> being worked with.</param> /// <param name="remote">The <see cref="Remote"/> to push to.</param> /// <param name="pushRefSpecs">The pushRefSpecs to push.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> /// <returns>Results of the push operation.</returns> public static PushResult Push(this Network network, Remote remote, IEnumerable<string> pushRefSpecs, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); List<PushStatusError> failedRemoteUpdates = new List<PushStatusError>(); network.Push( remote, pushRefSpecs, failedRemoteUpdates.Add, credentials); return new PushResult(failedRemoteUpdates); }
public Repository CloneRepo(string srcUrl, out string pathToCode, string username = null, string pass = null) { string checkoutPath = string.Format("{0}gitCheckout-{1}", checkoutDirectory, DateTime.Now.Ticks); var tempDir = Directory.CreateDirectory(checkoutPath); Credentials creds = null; if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(pass)) { creds = new Credentials() {Username = username, Password = pass}; } var repo = Repository.Clone(srcUrl, checkoutPath, false, true, null, null, null, creds); pathToCode = repo.Info.WorkingDirectory; return repo; }
/// <summary> /// Push the specified branches to their tracked branches on the remote. /// </summary> /// <param name="network">The <see cref="Network"/> being worked with.</param> /// <param name="branches">The branches to push.</param> /// <param name="onPushStatusError">Handler for reporting failed push updates.</param> /// <param name="credentials">Credentials to use for user/pass authentication.</param> /// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception> public static void Push( this Network network, IEnumerable<Branch> branches, PushStatusErrorHandler onPushStatusError = null, Credentials credentials = null) { var enumeratedBranches = branches as IList<Branch> ?? branches.ToList(); foreach (var branch in enumeratedBranches) { if (string.IsNullOrEmpty(branch.UpstreamBranchCanonicalName)) { throw new LibGit2SharpException(string.Format("The branch '{0}' (\"{1}\") that you are trying to push does not track an upstream branch.", branch.Name, branch.CanonicalName)); } } foreach (var branch in enumeratedBranches) { network.Push(branch.Remote, string.Format("{0}:{1}", branch.CanonicalName, branch.UpstreamBranchCanonicalName), onPushStatusError); } }
/// <summary> /// Push specified reference to the <see cref="Remote"/>. /// </summary> /// <param name="remote">The <see cref = "Remote" /> to push to.</param> /// <param name="pushRefSpec">The pushRefSpec to push.</param> /// <param name="onPushStatusError">Handler for reporting failed push updates.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> public virtual void Push( Remote remote, string pushRefSpec, PushStatusErrorHandler onPushStatusError, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); Push(remote, new string[] { pushRefSpec }, onPushStatusError, credentials); }
/// <summary> /// Push the objectish to the destination reference on the <see cref = "Remote" />. /// </summary> /// <param name="remote">The <see cref = "Remote" /> to push to.</param> /// <param name="objectish">The source objectish to push.</param> /// <param name="destinationSpec">The reference to update on the remote.</param> /// <param name="onPushStatusError">Handler for reporting failed push updates.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> public virtual void Push( Remote remote, string objectish, string destinationSpec, PushStatusErrorHandler onPushStatusError, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); Ensure.ArgumentNotNullOrEmptyString(destinationSpec, destinationSpec); Push(remote, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", objectish, destinationSpec), onPushStatusError, credentials); }
/// <summary> /// Fetch from the <see cref = "Remote" />. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="tagFetchMode">Optional parameter indicating what tags to download.</param> /// <param name="onProgress">Progress callback. Corresponds to libgit2 progress callback.</param> /// <param name="onCompletion">Completion callback. Corresponds to libgit2 completion callback.</param> /// <param name="onUpdateTips">UpdateTips callback. Corresponds to libgit2 update_tips callback.</param> /// <param name="onTransferProgress">Callback method that transfer progress will be reported through. /// Reports the client's state regarding the received and processed (bytes, objects) from the server.</param> /// <param name="credentials">Credentials to use for username/password authentication.</param> public virtual void Fetch( Remote remote, TagFetchMode tagFetchMode = TagFetchMode.Auto, ProgressHandler onProgress = null, CompletionHandler onCompletion = null, UpdateTipsHandler onUpdateTips = null, TransferProgressHandler onTransferProgress = null, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); // We need to keep a reference to the git_cred_acquire_cb callback around // so it will not be garbage collected before we are done with it. // Note that we also have a GC.KeepAlive call at the end of the method. NativeMethods.git_cred_acquire_cb credentialCallback = null; using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { var callbacks = new RemoteCallbacks(onProgress, onCompletion, onUpdateTips); GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); Proxy.git_remote_set_autotag(remoteHandle, tagFetchMode); if (credentials != null) { credentialCallback = (out IntPtr cred, IntPtr url, IntPtr username_from_url, uint types, IntPtr payload) => NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password); Proxy.git_remote_set_cred_acquire_cb( remoteHandle, credentialCallback, IntPtr.Zero); } // It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of // the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation // to store a reference to the git_remote_callbacks structure this would introduce a subtle bug // where the managed layer could move the git_remote_callbacks to a different location in memory, // but libgit2 would still reference the old address. // // Also, if GitRemoteCallbacks were a class instead of a struct, we would need to guard against // GC occuring in between setting the remote callbacks and actual usage in one of the functions afterwords. Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks); try { Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch); Proxy.git_remote_download(remoteHandle, onTransferProgress); Proxy.git_remote_update_tips(remoteHandle); } finally { Proxy.git_remote_disconnect(remoteHandle); } } // To be safe, make sure the credential callback is kept until // alive until at least this point. GC.KeepAlive(credentialCallback); }
/// <summary> /// Fetch from the <see cref="Remote"/>. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="tagFetchMode">Optional parameter indicating what tags to download.</param> /// <param name="onProgress">Progress callback. Corresponds to libgit2 progress callback.</param> /// <param name="onUpdateTips">UpdateTips callback. Corresponds to libgit2 update_tips callback.</param> /// <param name="onTransferProgress">Callback method that transfer progress will be reported through. /// Reports the client's state regarding the received and processed (bytes, objects) from the server.</param> /// <param name="credentials">Credentials to use for username/password authentication.</param> public virtual void Fetch( Remote remote, TagFetchMode? tagFetchMode = null, ProgressHandler onProgress = null, UpdateTipsHandler onUpdateTips = null, TransferProgressHandler onTransferProgress = null, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { var callbacks = new RemoteCallbacks(onProgress, onTransferProgress, onUpdateTips, credentials); GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); if (tagFetchMode.HasValue) { Proxy.git_remote_set_autotag(remoteHandle, tagFetchMode.Value); } // It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of // the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation // to store a reference to the git_remote_callbacks structure this would introduce a subtle bug // where the managed layer could move the git_remote_callbacks to a different location in memory, // but libgit2 would still reference the old address. // // Also, if GitRemoteCallbacks were a class instead of a struct, we would need to guard against // GC occuring in between setting the remote callbacks and actual usage in one of the functions afterwords. Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks); try { Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch); Proxy.git_remote_download(remoteHandle); Proxy.git_remote_update_tips(remoteHandle); } finally { Proxy.git_remote_disconnect(remoteHandle); } } }
private void PushAddressToRemote(Repository repository) { var credentials = new Credentials() { Username = GitHubHosterConfiguration.GitHubUserName, Password = GitHubHosterConfiguration.GitHubPassword }; var head = repository.Head; repository.Network.Push(head.Remote, head.CanonicalName, credentials); }
public virtual IEnumerable <DirectReference> ListReferences(Remote remote, Credentials credentials) { return(ListReferences(remote, credentials == null ? null : new CredentialsHandler((url, user, type) => credentials))); }
/// <summary> /// Push specified references to the <see cref="Remote"/>. /// </summary> /// <param name="remote">The <see cref = "Remote" /> to push to.</param> /// <param name="pushRefSpecs">The pushRefSpecs to push.</param> /// <param name="onPushStatusError">Handler for reporting failed push updates.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> public virtual void Push( Remote remote, IEnumerable<string> pushRefSpecs, PushStatusErrorHandler onPushStatusError, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); // We need to keep a reference to the git_cred_acquire_cb callback around // so it will not be garbage collected before we are done with it. // Note that we also have a GC.KeepAlive call at the end of the method. NativeMethods.git_cred_acquire_cb credentialCallback = null; // Return early if there is nothing to push. if (!pushRefSpecs.Any()) { return; } PushCallbacks pushStatusUpdates = new PushCallbacks(onPushStatusError); // Load the remote. using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { if (credentials != null) { credentialCallback = (out IntPtr cred, IntPtr url, IntPtr username_from_url, uint types, IntPtr payload) => NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password); Proxy.git_remote_set_cred_acquire_cb( remoteHandle, credentialCallback, IntPtr.Zero); } try { Proxy.git_remote_connect(remoteHandle, GitDirection.Push); // Perform the actual push. using (PushSafeHandle pushHandle = Proxy.git_push_new(remoteHandle)) { // Add refspecs. foreach (string pushRefSpec in pushRefSpecs) { Proxy.git_push_add_refspec(pushHandle, pushRefSpec); } Proxy.git_push_finish(pushHandle); if (!Proxy.git_push_unpack_ok(pushHandle)) { throw new LibGit2SharpException("Push failed - remote did not successfully unpack."); } Proxy.git_push_status_foreach(pushHandle, pushStatusUpdates.Callback); Proxy.git_push_update_tips(pushHandle); } } finally { Proxy.git_remote_disconnect(remoteHandle); } } // To be safe, make sure the credential callback is kept until // alive until at least this point. GC.KeepAlive(credentialCallback); }
private static void CloneRepository(string repositoryUrl, string gitDirectory, Credentials credentials) { try { Repository.Clone(repositoryUrl, gitDirectory, new CloneOptions { Checkout = false, CredentialsProvider = (url, usernameFromUrl, types) => credentials }); } catch (LibGit2SharpException ex) { var message = ex.Message; if (message.Contains("401")) { throw new Exception("Unauthorised: Incorrect username/password"); } if (message.Contains("403")) { throw new Exception("Forbidden: Possbily Incorrect username/password"); } if (message.Contains("404")) { throw new Exception("Not found: The repository was not found"); } throw new Exception("There was an unknown problem with the Git repository you provided"); } }
/// <summary> /// List references in a <see cref="Remote"/> repository. /// <para> /// When the remote tips are ahead of the local ones, the retrieved /// <see cref="DirectReference"/>s may point to non existing /// <see cref="GitObject"/>s in the local repository. In that /// case, <see cref="DirectReference.Target"/> will return <c>null</c>. /// </para> /// </summary> /// <param name="remote">The <see cref="Remote"/> to list from.</param> /// <param name="credentials">The optional <see cref="Credentials"/> used to connect to remote repository.</param> /// <returns>The references in the <see cref="Remote"/> repository.</returns> public virtual IEnumerable<DirectReference> ListReferences(Remote remote, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { if (credentials != null) { var callbacks = new RemoteCallbacks(null, null, null, credentials); GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks); } Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch); return Proxy.git_remote_ls(repository, remoteHandle); } }
private void clone(int attempt = 0) { progressInfo.Add( "Standby; negotiating connection to remote repository..." ); scroll.y = int.MaxValue; UnityThreadHelper.CreateThread( () => { Credentials credentials = new Credentials(); credentials.Username = username; credentials.Password = password; try { using ( var repo = Repository.Clone( gitURL, tempDir, false, true, onTransferProgress, onCheckoutProgress, null, credentials ) ) { progressInfo.Add( "Clone complete!" ); } moveFiles(); setupState = SetupState.complete; } catch ( LibGit2SharpException e ) { progressInfo.Add( "Clone failed [PLUGIN] ==> " + e ); scroll.y = int.MaxValue; if ( attempt == 0 ) { clone(1); } hasWorkError = true; } catch ( System.Exception e ) { progressInfo.Add( "Clone Failed [OTHER] ==> " + e ); scroll.y = int.MaxValue; hasWorkError = true; } finally { try { Directory.Delete( tempDir, true ); } catch {} } } ); }
public virtual IEnumerable<DirectReference> ListReferences(Remote remote, Credentials credentials) { return ListReferences(remote, credentials == null ? null : new CredentialsHandler((url, user, type) => credentials)); }
public int AcquireCredentials(out Credentials cred, string user, params Type[] methods) { // Convert the user-provided types to libgit2's flags int allowed = 0; foreach (var method in methods) { if (method == typeof(UsernamePasswordCredentials)) { allowed |= (int)GitCredentialType.UserPassPlaintext; } else { throw new InvalidOperationException("Unknown type passes as allowed credential"); } } IntPtr credHandle = IntPtr.Zero; int res = Proxy.git_transport_smart_credentials(out credHandle, Transport, user, allowed); if (res != 0) { cred = null; return res; } if (credHandle == IntPtr.Zero) { throw new InvalidOperationException("creditals callback indicated success but returned no credentials"); } unsafe { var baseCred = (GitCredential*) credHandle; switch (baseCred->credtype) { case GitCredentialType.UserPassPlaintext: cred = UsernamePasswordCredentials.FromNative((GitCredentialUserpass*) credHandle); return 0; default: throw new InvalidOperationException("User returned an unkown credential type"); } } }
public virtual void Fetch( Remote remote, TagFetchMode? tagFetchMode = null, ProgressHandler onProgress = null, UpdateTipsHandler onUpdateTips = null, TransferProgressHandler onTransferProgress = null, Credentials credentials = null) { Fetch(remote, new FetchOptions { TagFetchMode = tagFetchMode, OnProgress = onProgress, OnUpdateTips = onUpdateTips, OnTransferProgress = onTransferProgress, Credentials = credentials }); }
/// <summary> /// Push the specified branch to its tracked branch on the remote. /// </summary> /// <param name="network">The <see cref="Network"/> being worked with.</param> /// <param name="branch">The branch to push.</param> /// <param name="onPushStatusError">Handler for reporting failed push updates.</param> /// <param name="credentials">Credentials to use for user/pass authentication.</param> /// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception> public static void Push( this Network network, Branch branch, PushStatusErrorHandler onPushStatusError = null, Credentials credentials = null) { network.Push(new[] { branch }, onPushStatusError, credentials); }