/// <inheritdoc /> public static IObservable<IObservableRepository> Clone( string sourceUrl, string workingDirectory, IObserver<Tuple<string, int>> observer, CredentialsHandler credentials = null) { var isCancelled = false; var options = new CloneOptions { Checkout = true, CredentialsProvider = credentials, OnTransferProgress = progress => { // TODO: how should we signal for the "indexing objects" events var p = (100 * progress.ReceivedObjects) / progress.TotalObjects; var receivingMessage = String.Format("Receiving objects: {0}% ({1}/{2})", p, progress.ReceivedObjects, progress.TotalObjects); observer.OnNext(Tuple.Create(receivingMessage, p)); return !isCancelled; }, IsBare = false, OnCheckoutProgress = ProgressFactory.CreateHandlerWithoutMessages(observer) }; var directoryInfo = new DirectoryInfo(workingDirectory); var initialMessage = String.Format("Cloning into '{0}'...", directoryInfo.Name); observer.OnNext(Tuple.Create(initialMessage, 0)); return Observable.Create<ObservableRepository>(subj => { var sub = Observable.Start(() => { var directory = Repository.Clone(sourceUrl, workingDirectory, options); observer.OnNext(Tuple.Create("clone completed", 100)); observer.OnCompleted(); return new ObservableRepository(directory, credentials); }, Scheduler.Default).Subscribe(subj); return new CompositeDisposable( sub, Disposable.Create(() => { isCancelled = true; observer.OnCompleted(); })); }); }
public void Fetch(string remoteName, CredentialsHandler credentials, IEventStream?eventStream = null, bool prune = false) { if (repository.Network.Remotes.FirstOrDefault(x => x.Name == remoteName) is Remote remote) { Fetch(remote, credentials, eventStream, prune); } }
public GitProvider(ILogger <GitProvider> logger, GitProviderOptions providerOptions) { _logger = logger; _providerOptions = providerOptions; if (string.IsNullOrWhiteSpace(_providerOptions.LocalPath)) { throw new ArgumentNullException(nameof(_providerOptions.LocalPath), $"{nameof(_providerOptions.LocalPath)} cannot be NULL or empty."); } if (string.IsNullOrWhiteSpace(_providerOptions.RepositoryUrl)) { throw new ArgumentNullException(nameof(_providerOptions.RepositoryUrl), $"{nameof(_providerOptions.RepositoryUrl)} cannot be NULL or empty."); } if (string.IsNullOrWhiteSpace(_providerOptions.Username)) { throw new ArgumentNullException(nameof(_providerOptions.Username), $"{nameof(_providerOptions.Username)} cannot be NULL or empty."); } if (string.IsNullOrWhiteSpace(_providerOptions.Password)) { throw new ArgumentNullException(nameof(_providerOptions.Password), $"{nameof(_providerOptions.Password)} cannot be NULL or empty."); } _credentialsHandler = (url, user, cred) => new UsernamePasswordCredentials { Username = _providerOptions.Username, Password = _providerOptions.Password }; }
/// <summary> /// List references in a 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="url">The url to list from.</param> /// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param> /// <returns>The references in the remote repository.</returns> public virtual IEnumerable <Reference> ListReferences(string url, CredentialsHandler credentialsProvider) { Ensure.ArgumentNotNull(url, "url"); Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider"); return(ListReferencesInternal(url, credentialsProvider)); }
public void Pull(UsernamePasswordCredentials gitCredentials, Signature signature) { Repository repo = new Repository(RepositoryPath); // Get git credentials CredentialsHandler credentialsHandler = new CredentialsHandler( (url, usernameFromUrl, types) => gitCredentials); // Pull repository PullOptions pullOptions = new PullOptions { FetchOptions = new FetchOptions() }; pullOptions.FetchOptions.CredentialsProvider = credentialsHandler; Signature merger = signature; Commands.Pull(repo, merger, pullOptions); // Compress changes to zip file File.Delete(ZipFilePath); using (ZipArchive zipArchive = ZipFile.Open(ZipFilePath, ZipArchiveMode.Create)) { foreach (string f in DirSearch(RepositoryPath)) { zipArchive.CreateEntryFromFile(f, f.Replace(RepositoryPath + @"\", "")); } } }
private void setupOptions(string Username, SecureString SecurePassword, string RepoPath, string RepoUrl) { credentials = new SecureUsernamePasswordCredentials() { Username = Username, Password = SecurePassword }; var credentialsProvider = new CredentialsHandler((_url, _user, _cred) => new SecureUsernamePasswordCredentials { Username = Username, Password = SecurePassword }); fetchOptions = new FetchOptions() { CredentialsProvider = credentialsProvider }; pullOptions = new PullOptions() { FetchOptions = fetchOptions }; pushOptions = new PushOptions() { CredentialsProvider = credentialsProvider }; cloneOptions = new CloneOptions() { CredentialsProvider = credentialsProvider }; statusOptions = new StatusOptions() { ExcludeSubmodules = true, IncludeUnaltered = false }; }
static CredentialsHandler CreateCredentialsHandler(IRepository repo, string remoteName) { var remote = repo.Network.Remotes[remoteName]; var remoteUri = new Uri(remote.Url); var secrets = new SecretStore("git"); var auth = new BasicAuthentication(secrets); var targetUrl = remoteUri.GetLeftPart(UriPartial.Authority); var creds = auth.GetCredentials(new TargetUri(targetUrl)); if (creds == null) { return(null); } CredentialsHandler credentialsHandler = (url, user, cred) => new UsernamePasswordCredentials { Username = creds.Username, Password = creds.Password }; return(credentialsHandler); }
/// <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="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param> /// <returns>The references in the <see cref="Remote"/> repository.</returns> public virtual IEnumerable <Reference> ListReferences(Remote remote, CredentialsHandler credentialsProvider) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider"); return(ListReferencesInternal(remote.Url, credentialsProvider)); }
public void Pull(string branchName, CredentialsHandler GitCredentialsHandler) { LibGit2Sharp.PullOptions pullOptions = new LibGit2Sharp.PullOptions(); pullOptions.FetchOptions = new FetchOptions(); pullOptions.FetchOptions.CredentialsProvider = GitCredentialsHandler; LibGit2Sharp.Commands.Pull(repository, new LibGit2Sharp.Signature(UserName, Email, new DateTimeOffset(DateTime.Now)), pullOptions); }
public override IRepository Clone(string remotePathOrUrl, string workingDirectory, SecureCredentials credentials = null) { try { var name = GetProjectNameFromDirectory(remotePathOrUrl); if (credentials == null) { LibGit2Sharp.Repository.Clone(remotePathOrUrl, workingDirectory); } else { var credentialsHandler = new CredentialsHandler((url, usernameFromUrl, types) => new SecureUsernamePasswordCredentials { Username = credentials.Username, Password = credentials.Password }); var options = new CloneOptions { CredentialsProvider = credentialsHandler }; LibGit2Sharp.Repository.Clone(remotePathOrUrl, workingDirectory, options); } return(new Repository(name, workingDirectory, remotePathOrUrl)); } catch (LibGit2SharpException ex) { throw new SourceControlException(SourceControlText.GitRepoNotCloned, ex); } }
public async Task GetProgressFromASyncOperation() { CredentialsHandler credentials = (url, usernameFromUrl, types) => new UsernamePasswordCredentials { Username = "******", Password = "******" }; var repository = new ObservableRepository( @"C:\Users\brendanforster\Documents\GìtHūb\testing-pushspecs", credentials); Func <int, int> translate = x => x / 3; var pullObserver = new ReplaySubject <Tuple <string, int> >(); var pushObserver = new ReplaySubject <Tuple <string, int> >(); var pullResult = await repository.Pull(pullObserver); Assert.NotEqual(MergeStatus.Conflicts, pullResult.Status); await repository.Push(pushObserver); var list = await pullObserver.Select(x => translate(x.Item2) * 2) .Concat(pushObserver.Select(x => 67 + translate(x.Item2))) .ToList(); Assert.NotEmpty(list); Assert.Equal(100, list.Last()); }
public PushCommand(IEventStream eventStream, MainThread mainThread, IGitRepository repository, CredentialsHandler credentialsProvider, SyncView view) { this.eventStream = eventStream; this.mainThread = mainThread; this.repository = repository; this.credentialsProvider = credentialsProvider; this.view = view; }
/// <summary> /// Build clone options for an empty .git directory with only the used parameter /// </summary> /// <param name="credentialsHandler"></param> /// <returns></returns> private static CloneOptions GetCloneOptions(CredentialsHandler credentialsHandler) { return(new CloneOptions { IsBare = true, CredentialsProvider = credentialsHandler }); }
public void PushToRemote(string branchName, CredentialsHandler GitCredentialsHandler) { Branch branch = repository.Branches["refs/heads/" + branchName]; var pushOptions = new PushOptions() { }; pushOptions.CredentialsProvider = GitCredentialsHandler; repository.Network.Push(branch, pushOptions); }
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; }
private CredentialsHandler GetSourceCredentialsHandler() { var credentials = new UsernamePasswordCredentials() { Username = SourceControlUser, Password = SourceControlPass, }; CredentialsHandler credentialHandler = (_url, _user, _cred) => credentials; return(credentialHandler); }
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(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, 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, RepositorySettings repository, string userName, string passWord) : this(project, repository) { _credentials = new UsernamePasswordCredentials() { Username = userName, Password = passWord }; _credentialsHandler = (url, user, cred) => _credentials; }
internal RemoteCallbacks( ProgressHandler onProgress = null, TransferProgressHandler onDownloadProgress = null, UpdateTipsHandler onUpdateTips = null, CredentialsHandler credentialsProvider = null) { Progress = onProgress; DownloadTransferProgress = onDownloadProgress; UpdateTips = onUpdateTips; CredentialsProvider = credentialsProvider; }
public static void ResetTag(string tag, PathConstruction.AbsolutePath projectPath, string repositoryUrl, CredentialsHandler credentialsHandler = null) { var repository = GitRepositoryBuilder.GetRepository(repositoryUrl, projectPath, credentialsHandler); if (repository.Tags.Any(s => string.Equals(s.FriendlyName, tag, StringComparison.OrdinalIgnoreCase))) { DeleteTag(tag, projectPath, repositoryUrl, credentialsHandler); } CreateTag(tag, projectPath, repositoryUrl, credentialsHandler); }
public void Initialize() { _logger.LogInformation("Initializing {Name} provider with options {Options}.", Name, new { _providerOptions.RepositoryUrl, _providerOptions.LocalPath, _providerOptions.Branch, _providerOptions.PollingInterval, _providerOptions.SearchPattern }); if (Directory.Exists(_providerOptions.LocalPath)) { _logger.LogInformation("A local repository already exists at {LocalPath}.", _providerOptions.LocalPath); _logger.LogInformation("Deleting directory {LocalPath}.", _providerOptions.LocalPath); DeleteDirectory(_providerOptions.LocalPath); } if (!Directory.Exists(_providerOptions.LocalPath)) { _logger.LogInformation("Creating directory {LocalPath}.", _providerOptions.LocalPath); Directory.CreateDirectory(_providerOptions.LocalPath); } if (_providerOptions.Username != null && _providerOptions.Password != null) { _credentialsHandler = (url, user, cred) => new UsernamePasswordCredentials { Username = _providerOptions.Username, Password = _providerOptions.Password }; } var cloneOptions = new CloneOptions { CredentialsProvider = _credentialsHandler, BranchName = _providerOptions.Branch }; _logger.LogInformation("Cloning git repository {RepositoryUrl} to {LocalPath}.", _providerOptions.RepositoryUrl, _providerOptions.LocalPath); var path = Repository.Clone(_providerOptions.RepositoryUrl, _providerOptions.LocalPath, cloneOptions); _logger.LogInformation("Repository cloned to {path}.", path); using var repo = new Repository(_providerOptions.LocalPath); var hash = repo.Head.Tip.Sha.Substring(0, 6); _logger.LogInformation("Current HEAD is [{hash}] '{MessageShort}'.", hash, repo.Head.Tip.MessageShort); }
private static object @lock = new object(); // Потокобезопасность не гарантируется библиотекой libgit2 // url example [email protected]:user/myrepo.git public GitRepo(string url, DirectoryInfo reposBaseDir, string publicKey, string privateKey, DirectoryInfo keysTempDirectory, ILogger logger) { this.url = url; this.reposBaseDir = reposBaseDir; this.logger = logger; if (!reposBaseDir.Exists) { reposBaseDir.Create(); } Monitor.Enter(@lock); var filenameGuid = Guid.NewGuid().ToString(); privateKeyPath = Path.Combine(keysTempDirectory.FullName, filenameGuid); publicKeyPath = privateKeyPath + ".pub"; File.WriteAllText(privateKeyPath, privateKey); File.WriteAllText(publicKeyPath, publicKey); credentialsHandler = (_, __, ___) => new SshUserKeyCredentials { Username = "******", Passphrase = "", PublicKey = publicKeyPath, PrivateKey = privateKeyPath, }; try { if (!TryUpdateExistingRepo()) { Clone(); } } catch (LibGit2SharpException ex) { Dispose(); // Если объект не создан, извне Dispose не вызовут if (ex.Message.Contains("SSH")) { throw new GitException(ex.Message, ex) { MayBeSSHException = true } } ; throw; } catch (Exception ex) { Dispose(); // Если объект не создан, извне Dispose не вызовут throw; } }
private CredentialsHandler GetCredentialsHandler() { string user = Environment.GetEnvironmentVariable("GH_USER"); string token = Environment.GetEnvironmentVariable("GH_TOKEN"); var handler = new CredentialsHandler( (url, usernameFromUrl, types) => new UsernamePasswordCredentials() { Username = usernameFromUrl ?? user, Password = token }); return(handler); }
internal RemoteCallbacks(PushOptions pushOptions) { if (pushOptions == null) { return; } PushTransferProgress = pushOptions.OnPushTransferProgress; PackBuilderProgress = pushOptions.OnPackBuilderProgress; CredentialsProvider = pushOptions.CredentialsProvider; CertificateCheck = pushOptions.CertificateCheck; PushStatusError = pushOptions.OnPushStatusError; PrePushCallback = pushOptions.OnNegotiationCompletedBeforePush; }
public static void PushChanges(Repository repository, CredentialsHandler credentialsHandler, string remote, string branch, string tagName) { try { var remotes = repository.Network.Remotes[remote]; var options = new PushOptions {CredentialsProvider = credentialsHandler}; string pushRefSpec = string.Format("refs/heads/{0}:refs/tags/{1}", branch, tagName); repository.Network.Push(remotes, pushRefSpec, options); } catch (Exception e) { Console.WriteLine("Exception:RepoActions:PushChanges " + e.Message); } }
public void Push(UsernamePasswordCredentials gitCredentials) { Repository repo = new Repository(RepositoryPath); // Get git credentials CredentialsHandler credentialsHandler = new CredentialsHandler( (url, usernameFromUrl, types) => gitCredentials); // Pull repository PushOptions options = new PushOptions { CredentialsProvider = credentialsHandler }; repo.Network.Push(repo.Branches["refs/heads/master"], options); }
/// <inheritdoc /> public static IObservable <IObservableRepository> Clone( string sourceUrl, string workingDirectory, IObserver <Tuple <string, int> > observer, CredentialsHandler credentials = null) { var isCancelled = false; var options = new CloneOptions { Checkout = true, CredentialsProvider = credentials, OnTransferProgress = progress => { // TODO: how should we signal for the "indexing objects" events var p = (100 * progress.ReceivedObjects) / progress.TotalObjects; var receivingMessage = String.Format("Receiving objects: {0}% ({1}/{2})", p, progress.ReceivedObjects, progress.TotalObjects); observer.OnNext(Tuple.Create(receivingMessage, p)); return(!isCancelled); }, IsBare = false, OnCheckoutProgress = ProgressFactory.CreateHandlerWithoutMessages(observer) }; var directoryInfo = new DirectoryInfo(workingDirectory); var initialMessage = String.Format("Cloning into '{0}'...", directoryInfo.Name); observer.OnNext(Tuple.Create(initialMessage, 0)); return(Observable.Create <ObservableRepository>(subj => { var sub = Observable.Start(() => { var directory = Repository.Clone(sourceUrl, workingDirectory, options); observer.OnNext(Tuple.Create("clone completed", 100)); observer.OnCompleted(); return new ObservableRepository(directory, credentials); }, Scheduler.Default).Subscribe(subj); return new CompositeDisposable( sub, Disposable.Create(() => { isCancelled = true; observer.OnCompleted(); })); })); }
public void LoadRepo(Repo repoToLoad) { _repo?.Dispose(); var localRepoRelativePath = repoToLoad.FriendlyName.ToLower().Replace(" ", "_"); var localRepoAbsolutePath = Path.Combine(AppContext.BaseDirectory, "reposcache", localRepoRelativePath); CredentialsHandler credentialsHandler = null; if (!string.IsNullOrEmpty(_settings.Username)) { credentialsHandler = (url, usernameFromUrl, types) => new UsernamePasswordCredentials { Username = _settings.Username, Password = _settings.Password }; } bool recentlyCloned = false; if (!Directory.Exists(localRepoAbsolutePath)) { var cloneOptions = new CloneOptions(); if (credentialsHandler != null) { cloneOptions.CredentialsProvider = credentialsHandler; } Repository.Clone(repoToLoad.Url, localRepoAbsolutePath, cloneOptions); _logger.LogInformation($"Cloned {repoToLoad.Url} to folder {localRepoAbsolutePath}"); recentlyCloned = true; } _repo = new Repository(localRepoAbsolutePath); if (!recentlyCloned) { var fetchOptions = new FetchOptions(); if (credentialsHandler != null) { fetchOptions.CredentialsProvider = credentialsHandler; } var remote = _repo.Network.Remotes.First(r => r.Name == "origin"); var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification); Commands.Fetch(_repo, remote.Name, refSpecs, fetchOptions, ""); _logger.LogInformation($"Fetched origin for {repoToLoad.FriendlyName} in folder {localRepoAbsolutePath}"); } }
/// <summary> /// Pushes the local branch to the given remote. /// </summary> /// <returns>The name of the branch it's been pushed to.</returns> private string PushBranch(Repository repo, Remote origin, string gitHubToken) { var currentBranch = repo.Head; var remoteBranchName = $"release-pr-{DateTime.UtcNow:yyyyMMddTHHmmss'Z'}"; CredentialsHandler credentials = (url, user, cred) => new UsernamePasswordCredentials { Username = gitHubToken, Password = "" }; // TODO: Work out why I can't pass currentBranch.FriendlyName in as the src. repo.Network.Push(origin, $"HEAD:refs/heads/{remoteBranchName}", new PushOptions { CredentialsProvider = credentials }); return(remoteBranchName); }
public FetchCommand( IEnumerable <CherryPickConfig> repositories, IEventStream eventStream, CredentialsHandler credentials, CherryPickerView view, MainThread mainThread) { this.repositories = repositories; this.eventStream = eventStream; this.credentials = credentials; this.view = view; this.mainThread = mainThread; IsVisible = IsEnabled = !view.IsRootMode; }
public static void PushChanges(Repository repository, CredentialsHandler credentialsHandler, string remote, string branch, string tagName) { try { var remotes = repository.Network.Remotes[remote]; var options = new PushOptions { CredentialsProvider = credentialsHandler }; string pushRefSpec = string.Format("refs/heads/{0}:refs/tags/{1}", branch, tagName); repository.Network.Push(remotes, pushRefSpec, options); } catch (Exception e) { Console.WriteLine("Exception:RepoActions:PushChanges " + e.Message); } }
/// <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="credentialsProvider">The optional <see cref="Func{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, CredentialsHandler credentialsProvider = null) { Ensure.ArgumentNotNull(remote, "remote"); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { if (credentialsProvider != null) { var callbacks = new RemoteCallbacks(null, null, null, credentialsProvider); 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); } }
/// <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="credentialsProvider">The optional <see cref="Func{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, CredentialsHandler credentialsProvider = null) { Ensure.ArgumentNotNull(remote, "remote"); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_lookup(repository.Handle, remote.Name, true)) { if (credentialsProvider != null) { var callbacks = new RemoteCallbacks(credentialsProvider); 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)); } }
internal RemoteCallbacks(FetchOptionsBase fetchOptions) { if (fetchOptions == null) { return; } Progress = fetchOptions.OnProgress; DownloadTransferProgress = fetchOptions.OnTransferProgress; UpdateTips = fetchOptions.OnUpdateTips; CredentialsProvider = fetchOptions.CredentialsProvider; CertificateCheck = fetchOptions.CertificateCheck; }
/// <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="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param> /// <returns>The references in the <see cref="Remote"/> repository.</returns> public virtual IEnumerable<Reference> ListReferences(Remote remote, CredentialsHandler credentialsProvider) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider"); return ListReferencesInternal(remote.Url, credentialsProvider); }
/// <summary> /// List references in a 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="url">The url to list from.</param> /// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param> /// <returns>The references in the remote repository.</returns> public virtual IEnumerable<Reference> ListReferences(string url, CredentialsHandler credentialsProvider) { Ensure.ArgumentNotNull(url, "url"); Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider"); return ListReferencesInternal(url, credentialsProvider); }
public CredentialProvider(IScreen screen, ICredentialStore credentialStore) { this.store = credentialStore; this.CredentialHandler = new CredentialsHandler(this.OnCredentialsRequested); }
private IEnumerable<Reference> ListReferencesInternal(string url, CredentialsHandler credentialsProvider) { using (RemoteHandle remoteHandle = BuildRemoteHandle(repository.Handle, url)) { GitRemoteCallbacks gitCallbacks = new GitRemoteCallbacks { version = 1 }; GitProxyOptions proxyOptions = new GitProxyOptions { Version = 1 }; if (credentialsProvider != null) { var callbacks = new RemoteCallbacks(credentialsProvider); gitCallbacks = callbacks.GenerateCallbacks(); } Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch, ref gitCallbacks, ref proxyOptions); return Proxy.git_remote_ls(repository, remoteHandle); } }
internal RemoteCallbacks(CredentialsHandler credentialsProvider) { CredentialsProvider = credentialsProvider; }