3 using Microsoft.Extensions.Logging;
6 using System.Threading.Tasks;
18 readonly ILogger<LibGit2RepositoryFactory>
logger;
26 this.logger = logger ??
throw new ArgumentNullException(nameof(logger));
32 logger.LogTrace(
"Creating in-memory libgit2 repository...");
36 logger.LogTrace(
"Successfully created in-memory libgit2 repository.");
50 throw new ArgumentNullException(nameof(path));
55 logger.LogTrace(
"Creating libgit2 repostory at {0}...", path);
59 TaskCreationOptions.LongRunning,
60 TaskScheduler.Current);
64 public Task Clone(Uri url, CloneOptions cloneOptions,
string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() =>
68 logger.LogTrace(
"Cloning {0} into {1}...", url, path);
69 LibGit2Sharp.Repository.Clone(url.ToString(), path, cloneOptions);
71 catch (UserCancelledException ex)
73 logger.LogTrace(
"Suppressing clone cancellation exception: {0}", ex);
74 cancellationToken.ThrowIfCancellationRequested();
76 }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
79 public CredentialsHandler GenerateCredentialsHandler(
string username,
string password) => (a, b, supportedCredentialTypes) =>
81 var hasCreds = username != null;
82 var supportsUserPass = supportedCredentialTypes.HasFlag(SupportedCredentialTypes.UsernamePassword);
83 var supportsAnonymous = supportedCredentialTypes.HasFlag(SupportedCredentialTypes.Default);
85 logger.LogTrace(
"Credentials requested. Present: {0}. Supports anonymous: {1}. Supports user/pass: {2}", hasCreds, supportsAnonymous, supportsUserPass);
86 if (supportsUserPass && hasCreds)
87 return new UsernamePasswordCredentials
93 if (supportsAnonymous)
94 return new DefaultCredentials();
ErrorCode
Types of ErrorMessages that the API may return.
Use server authentication
readonly ILogger< LibGit2RepositoryFactory > logger
The ILogger for the LibGit2RepositoryFactory.
LibGit2Sharp.IRepository CreateInMemory()
Create an in-memeory LibGit2Sharp.IRepository.
Factory for creating LibGit2Sharp.IRepositorys.
LibGit2RepositoryFactory(ILogger< LibGit2RepositoryFactory > logger)
Initializes a new instance of the LibGit2RepositoryFactory .
Operation exceptions thrown from the context of a Models.Job
Represents a git repository
Task< LibGit2Sharp.IRepository > CreateFromPath(string path, CancellationToken cancellationToken)
Load a LibGit2Sharp.IRepository from a given path .