3using System.Threading.Tasks;
7using Microsoft.Extensions.Logging;
8using Microsoft.Extensions.Options;
24 public bool InUse => semaphore.CurrentCount == 0;
72 readonly ILogger<RepositoryManager>
logger;
100 ILogger<RepositoryManager>
logger)
103 this.commands =
commands ??
throw new ArgumentNullException(nameof(
commands));
110 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
117 logger.LogTrace(
"Disposing...");
124 string? initialBranch,
128 bool recurseSubmodules,
129 CancellationToken cancellationToken)
131 ArgumentNullException.ThrowIfNull(url);
140 logger.LogInformation(
"Begin clone {url} to {path} (Branch: {initialBranch})", url, repositoryPath, initialBranch);
146 logger.LogTrace(
"Semaphore acquired for clone");
150 using var cloneProgressReporter = progressReporter.
CreateSection(
null, 0.75f);
151 using var checkoutProgressReporter = progressReporter.
CreateSection(
null, 0.25f);
152 var cloneOptions =
new CloneOptions
154 RecurseSubmodules = recurseSubmodules,
155 OnCheckoutProgress = (path, completed, remaining) =>
157 if (checkoutProgressReporter ==
null)
160 var percentage = (double)completed / remaining;
163 BranchName = initialBranch,
166 cloneOptions.FetchOptions.Hydrate(
168 cloneProgressReporter,
182 logger.LogTrace(
"Deleting partially cloned repository...");
189 logger.LogError(innerException,
"Error deleting partially cloned repository!");
196 logger.LogDebug(
"Repository exists, clone aborted!");
203 logger.LogTrace(
"Semaphore released after clone");
207 logger.LogInformation(
"Clone complete!");
212 public async ValueTask<IRepository?>
LoadRepository(CancellationToken cancellationToken)
214 logger.LogTrace(
"Begin LoadRepository...");
221 await
semaphore.WaitAsync(cancellationToken);
224 logger.LogTrace(
"Semaphore acquired for load");
240 logger.LogTrace(
"Releasing semaphore due to Repository disposal...");
246 logger.LogTrace(
"Releasing semaphore as load failed");
251 catch (RepositoryNotFoundException e)
253 logger.LogTrace(e,
"Repository not found!");
261 logger.LogInformation(
"Deleting repository...");
266 logger.LogTrace(
"Semaphore acquired, deleting Repository directory...");
272 logger.LogTrace(
"Semaphore released after delete attempt");
readonly ILogger< Repository > repositoryLogger
The ILogger created Repositorys.
RepositoryManager(ILibGit2RepositoryFactory repositoryFactory, ILibGit2Commands commands, IIOManager ioManager, IEventConsumer eventConsumer, IPostWriteHandler postWriteHandler, IGitRemoteFeaturesFactory gitRemoteFeaturesFactory, IOptionsMonitor< GeneralConfiguration > generalConfigurationOptions, ILogger< Repository > repositoryLogger, ILogger< RepositoryManager > logger)
Initializes a new instance of the RepositoryManager class.
async ValueTask DeleteRepository(CancellationToken cancellationToken)
Delete the current repository.A ValueTask representing the running operation.
readonly ILibGit2RepositoryFactory repositoryFactory
The ILibGit2RepositoryFactory for the RepositoryManager.
readonly SemaphoreSlim semaphore
Used for controlling single access to the IRepository.
async ValueTask< IRepository?> LoadRepository(CancellationToken cancellationToken)
Attempt to load the IRepository from the default location.A ValueTask<TResult> resulting in the loade...
readonly ILibGit2Commands commands
The ILibGit2Commands for the RepositoryManager.
bool InUse
If something is holding a lock on the repository.
readonly IPostWriteHandler postWriteHandler
The IPostWriteHandler for the RepositoryManager.
readonly IOptionsMonitor< GeneralConfiguration > generalConfigurationOptions
The IOptionsMonitor<TOptions> of GeneralConfiguration for the RepositoryManager.
readonly IIOManager ioManager
The IIOManager for the RepositoryManager.
async ValueTask< IRepository?> CloneRepository(Uri url, string? initialBranch, string? username, string? password, JobProgressReporter progressReporter, bool recurseSubmodules, CancellationToken cancellationToken)
Clone the repository at url .A ValueTask<TResult> resulting i the newly cloned IRepository,...
readonly ILogger< RepositoryManager > logger
The ILogger for the RepositoryManager.
readonly IEventConsumer eventConsumer
The IEventConsumer for the RepositoryManager.
bool CloneInProgress
If a CloneRepository(Uri, string, string, string, JobProgressReporter, bool, CancellationToken) opera...
readonly IGitRemoteFeaturesFactory gitRemoteFeaturesFactory
The IGitRemoteFeaturesFactory for the RepositoryManager.
Operation exceptions thrown from the context of a Models.Job.
Progress reporter for a Job.
JobProgressReporter CreateSection(string? newStageName, double percentage)
Create a subsection of the JobProgressReporter with its optional own stage name.
void ReportProgress(double? progress)
Report progress.
Async lock context helper.
static async ValueTask< SemaphoreSlimContext > Lock(SemaphoreSlim semaphore, CancellationToken cancellationToken, ILogger? logger=null)
Asyncronously locks a semaphore .
Consumes EventTypes and takes the appropriate actions.
CredentialsHandler GenerateCredentialsHandler(string? username, string? password)
Generate a CredentialsHandler from a given username and password .
Factory for creating IGitRemoteFeatures.
For low level interactions with a LibGit2Sharp.IRepository.
Factory for creating LibGit2Sharp.IRepositorys.
Task Clone(Uri url, CloneOptions cloneOptions, string path, CancellationToken cancellationToken)
Clone a remote LibGit2Sharp.IRepository.
ValueTask< LibGit2Sharp.IRepository > CreateFromPath(string path, CancellationToken cancellationToken)
Load a LibGit2Sharp.IRepository from a given path .
Factory for creating and loading IRepositorys.
Interface for using filesystems.
string ResolvePath()
Retrieve the full path of the current working directory.
Task DeleteDirectory(string path, CancellationToken cancellationToken)
Recursively delete a directory, removes and does not enter any symlinks encounterd.
Task< bool > DirectoryExists(string path, CancellationToken cancellationToken)
Check that the directory at path exists.
Handles changing file modes/permissions after writing.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.