2using System.Collections.Generic;
3using System.Globalization;
6using System.Threading.Tasks;
9using LibGit2Sharp.Handlers;
10using Microsoft.Extensions.Logging;
38 public const string OriginTrackingErrorTemplate =
"Unable to determine most recent origin commit of {sha}. Marking it as an origin commit. This may result in invalid git metadata until the next hard reset to an origin reference.";
147 ILogger<Repository>
logger,
152 this.commands =
commands ??
throw new ArgumentNullException(nameof(
commands));
157 ArgumentNullException.ThrowIfNull(gitRemoteFeaturesFactory);
159 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
177 logger.LogTrace(
"Disposing...");
183#pragma warning disable CA1506
186 string committerName,
187 string committerEmail,
190 bool updateSubmodules,
192 CancellationToken cancellationToken)
194 ArgumentNullException.ThrowIfNull(testMergeParameters);
195 ArgumentNullException.ThrowIfNull(committerName);
196 ArgumentNullException.ThrowIfNull(committerEmail);
197 ArgumentNullException.ThrowIfNull(progressReporter);
200 "Begin AddTestMerge: #{prNumber} at {targetSha} ({comment}) by <{committerName} ({committerEmail})>",
201 testMergeParameters.
Number,
208 throw new InvalidOperationException(
"Cannot test merge with an Unknown RemoteGitProvider!");
210 var commitMessage = String.Format(
211 CultureInfo.InvariantCulture,
212 "TGS Test Merge (#{0}){1}{2}",
213 testMergeParameters.
Number,
214 testMergeParameters.
Comment !=
null
215 ? Environment.NewLine
217 testMergeParameters.
Comment ?? String.Empty);
219 var testMergeBranchName = String.Format(CultureInfo.InvariantCulture,
"tm-{0}", testMergeParameters.
Number);
223 var refSpecList =
new List<string> { refSpec };
224 var logMessage = String.Format(CultureInfo.InvariantCulture,
"Test merge #{0}", testMergeParameters.
Number);
228 MergeResult result =
null;
230 var progressFactor = 1.0 / (updateSubmodules ? 3 : 2);
232 var sig =
new Signature(
new Identity(committerName, committerEmail), DateTimeOffset.UtcNow);
233 List<string> conflictedPaths =
null;
234 await Task.Factory.StartNew(
241 logger.LogTrace(
"Fetching refspec {refSpec}...", refSpec);
243 var remote =
libGitRepo.Network.Remotes.First();
251 OnProgress = (a) => !cancellationToken.IsCancellationRequested,
253 progressReporter.
CreateSection($
"Fetch {refSpec}", progressFactor),
255 OnUpdateTips = (a, b, c) => !cancellationToken.IsCancellationRequested,
260 catch (UserCancelledException)
263 catch (LibGit2SharpException ex)
268 cancellationToken.ThrowIfCancellationRequested();
272 cancellationToken.ThrowIfCancellationRequested();
274 var objectName = testMergeParameters.TargetCommitSha ?? localBranchName;
275 var gitObject =
libGitRepo.Lookup(objectName) ??
throw new JobException($
"Could not find object to merge: {objectName}");
277 testMergeParameters.TargetCommitSha = gitObject.Sha;
279 cancellationToken.ThrowIfCancellationRequested();
285 CommitOnSuccess = commitMessage == null,
286 FailOnConflict = false,
287 FastForwardStrategy = FastForwardStrategy.NoFastForward,
289 OnCheckoutProgress = CheckoutProgressHandler(
290 progressReporter.CreateSection($
"Merge {testMergeParameters.TargetCommitSha[..7]}", progressFactor)),
298 cancellationToken.ThrowIfCancellationRequested();
300 if (result.Status == MergeStatus.Conflicts)
303 conflictedPaths =
new List<string>();
304 foreach (var file
in repoStatus)
305 if (file.State == FileStatus.Conflicted)
306 conflictedPaths.Add(file.FilePath);
308 var revertTo = originalCommit.CanonicalName ?? originalCommit.Tip.Sha;
309 logger.LogDebug(
"Merge conflict, aborting and reverting to {revertTarget}", revertTo);
312 cancellationToken.ThrowIfCancellationRequested();
319 TaskScheduler.Current);
321 if (result.Status == MergeStatus.Conflicts)
323 var arguments =
new List<string>
325 originalCommit.Tip.Sha,
331 arguments.AddRange(conflictedPaths);
341 ConflictingFiles = conflictedPaths,
345 if (result.Status != MergeStatus.UpToDate)
347 logger.LogTrace(
"Committing merge: \"{commitMessage}\"...", commitMessage);
348 await Task.Factory.StartNew(
349 () =>
libGitRepo.Commit(commitMessage, sig, sig,
new CommitOptions
351 PrettifyMessage =
true,
355 TaskScheduler.Current);
357 if (updateSubmodules)
360 progressReporter.
CreateSection(
"Update Submodules", progressFactor),
372 testMergeParameters.Number.ToString(CultureInfo.InvariantCulture),
373 testMergeParameters.TargetCommitSha,
374 testMergeParameters.Comment,
384#pragma warning restore CA1506
391 bool updateSubmodules,
393 CancellationToken cancellationToken)
395 ArgumentNullException.ThrowIfNull(committish);
396 ArgumentNullException.ThrowIfNull(progressReporter);
397 logger.LogDebug(
"Checkout object: {committish}...", committish);
399 await Task.Factory.StartNew(
405 progressReporter.
CreateSection(
null, updateSubmodules ? 2.0 / 3 : 1.0),
410 TaskScheduler.Current);
412 if (updateSubmodules)
426 bool deploymentPipeline,
427 CancellationToken cancellationToken)
429 ArgumentNullException.ThrowIfNull(progressReporter);
430 logger.LogDebug(
"Fetch origin...");
432 await Task.Factory.StartNew(
435 var remote =
libGitRepo.Network.Remotes.First();
442 .Select(x => x.Specification),
447 OnProgress = (a) => !cancellationToken.IsCancellationRequested,
448 OnTransferProgress = TransferProgressHandler(progressReporter.CreateSection(
"Fetch Origin", 1.0), cancellationToken),
449 OnUpdateTips = (a, b, c) => !cancellationToken.IsCancellationRequested,
450 CredentialsProvider = credentialsProvider.GenerateCredentialsHandler(username, password),
452 "Fetch origin commits");
454 catch (UserCancelledException)
456 cancellationToken.ThrowIfCancellationRequested();
458 catch (LibGit2SharpException ex)
465 TaskScheduler.Current);
473 bool updateSubmodules,
474 bool deploymentPipeline,
475 CancellationToken cancellationToken)
477 ArgumentNullException.ThrowIfNull(progressReporter);
480 logger.LogTrace(
"Reset to origin...");
482 await
eventConsumer.
HandleEvent(
EventType.RepoResetOrigin,
new List<string> { trackedBranch.FriendlyName, trackedBranch.Tip.Sha }, deploymentPipeline, cancellationToken);
484 trackedBranch.Tip.Sha,
485 progressReporter.
CreateSection(
null, updateSubmodules ? 2.0 / 3 : 1.0),
488 if (updateSubmodules)
501 ArgumentNullException.ThrowIfNull(sha);
502 ArgumentNullException.ThrowIfNull(progressReporter);
504 logger.LogDebug(
"Reset to sha: {sha}", sha[..7]);
507 cancellationToken.ThrowIfCancellationRequested();
509 var gitObject =
libGitRepo.Lookup(sha, ObjectType.Commit);
510 cancellationToken.ThrowIfCancellationRequested();
512 if (gitObject ==
null)
513 throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
"Cannot reset to non-existent SHA: {0}", sha));
515 libGitRepo.Reset(ResetMode.Hard, gitObject.Peel<Commit>(),
new CheckoutOptions
517 OnCheckoutProgress = CheckoutProgressHandler(progressReporter.CreateSection($
"Reset to {gitObject.Sha}", 1.0)),
522 TaskScheduler.Current);
525 public async Task
CopyTo(
string path, CancellationToken cancellationToken)
527 ArgumentNullException.ThrowIfNull(path);
528 logger.LogTrace(
"Copying to {path}...", path);
530 new List<string> {
".git" },
536 return Task.CompletedTask;
545 public Task<string>
GetOriginSha(CancellationToken cancellationToken) => Task.Factory.StartNew(
551 cancellationToken.ThrowIfCancellationRequested();
557 TaskScheduler.Current);
562 string committerName,
563 string committerEmail,
564 bool deploymentPipeline,
565 CancellationToken cancellationToken)
567 ArgumentNullException.ThrowIfNull(progressReporter);
569 MergeResult result =
null;
570 Branch trackedBranch =
null;
573 var oldTip = oldHead.Tip;
575 await Task.Factory.StartNew(
583 cancellationToken.ThrowIfCancellationRequested();
587 "Merge origin/{trackedBranch}: <{committerName} ({committerEmail})>",
588 trackedBranch.FriendlyName,
591 result =
libGitRepo.Merge(trackedBranch,
new Signature(committerName, committerEmail, DateTimeOffset.UtcNow),
new MergeOptions
593 CommitOnSuccess = true,
594 FailOnConflict = true,
595 FastForwardStrategy = FastForwardStrategy.Default,
597 OnCheckoutProgress = CheckoutProgressHandler(progressReporter.CreateSection(
"Merge Origin", 1.0)),
600 cancellationToken.ThrowIfCancellationRequested();
602 if (result.Status == MergeStatus.Conflicts)
604 logger.LogDebug(
"Merge conflict, aborting and reverting to {oldHeadFriendlyName}", oldHead.FriendlyName);
605 progressReporter.ReportProgress(0);
606 libGitRepo.Reset(ResetMode.Hard, oldTip, new CheckoutOptions
608 OnCheckoutProgress = CheckoutProgressHandler(progressReporter.CreateSection($
"Hard Reset to {oldHead.FriendlyName}", 1.0)),
610 cancellationToken.ThrowIfCancellationRequested();
617 TaskScheduler.Current);
619 if (result.Status == MergeStatus.Conflicts)
626 trackedBranch.Tip.Sha,
628 trackedBranch.FriendlyName,
635 return result.Status == MergeStatus.FastForward;
643 string committerName,
644 string committerEmail,
645 bool synchronizeTrackedBranch,
646 bool deploymentPipeline,
647 CancellationToken cancellationToken)
649 ArgumentNullException.ThrowIfNull(committerName);
650 ArgumentNullException.ThrowIfNull(committerEmail);
651 ArgumentNullException.ThrowIfNull(progressReporter);
653 if (username ==
null && password ==
null)
655 logger.LogTrace(
"Not synchronizing due to lack of credentials!");
659 logger.LogTrace(
"Begin Synchronize...");
661 ArgumentNullException.ThrowIfNull(username);
662 ArgumentNullException.ThrowIfNull(password);
664 var startHead = Head;
666 logger.LogTrace(
"Configuring <{committerName} ({committerEmail})> as author/committer", committerName, committerEmail);
667 await Task.Factory.StartNew(
670 libGitRepo.Config.Set(
"user.name", committerName);
671 cancellationToken.ThrowIfCancellationRequested();
672 libGitRepo.Config.Set(
"user.email", committerEmail);
676 TaskScheduler.Current);
678 cancellationToken.ThrowIfCancellationRequested();
681 await eventConsumer.HandleEvent(
685 ioMananger.ResolvePath(),
692 logger.LogTrace(
"Resetting and cleaning untracked files...");
693 await Task.Factory.StartNew(
696 libGitRepo.Reset(ResetMode.Hard, libGitRepo.Head.Tip,
new CheckoutOptions
698 OnCheckoutProgress = CheckoutProgressHandler(progressReporter.CreateSection(
"Hard reset and remove untracked files", 0.1)),
700 cancellationToken.ThrowIfCancellationRequested();
701 libGitRepo.RemoveUntrackedFiles();
705 TaskScheduler.Current);
708 var remainingProgressFactor = 0.9;
709 if (!synchronizeTrackedBranch)
711 await PushHeadToTemporaryBranch(
714 progressReporter.
CreateSection(
"Push to temporary branch", remainingProgressFactor),
719 var sameHead = Head == startHead;
720 if (sameHead || !Tracking)
722 logger.LogTrace(
"Aborted synchronize due to {abortReason}!", sameHead ?
"lack of changes" :
"not being on tracked reference");
726 logger.LogInformation(
"Synchronizing with origin...");
728 return await Task.Factory.StartNew(
731 var remote = libGitRepo.Network.Remotes.First();
734 libGitRepo.Network.Push(
737 progressReporter.
CreateSection(
"Push to origin", remainingProgressFactor),
743 catch (NonFastForwardException)
745 logger.LogInformation(
"Synchronize aborted, non-fast forward!");
748 catch (UserCancelledException e)
750 cancellationToken.ThrowIfCancellationRequested();
751 throw new InvalidOperationException(
"Caught UserCancelledException without cancellationToken triggering", e);
753 catch (LibGit2SharpException e)
755 logger.LogWarning(e,
"Unable to make synchronization push!");
761 TaskScheduler.Current);
765 public Task<bool>
IsSha(
string committish, CancellationToken cancellationToken) => Task.Factory.StartNew(
769 var gitObject = libGitRepo.Lookup(committish, ObjectType.Tag);
770 if (gitObject !=
null)
772 cancellationToken.ThrowIfCancellationRequested();
775 if (libGitRepo.Branches[committish] !=
null)
777 cancellationToken.ThrowIfCancellationRequested();
780 if (libGitRepo.Lookup<Commit>(committish) !=
null)
786 TaskScheduler.Current);
789 public Task<bool>
ShaIsParent(
string sha, CancellationToken cancellationToken) => Task.Factory.StartNew(
792 var targetCommit = libGitRepo.Lookup<Commit>(sha);
793 if (targetCommit ==
null)
795 logger.LogTrace(
"Commit {sha} not found in repository", sha);
799 cancellationToken.ThrowIfCancellationRequested();
801 var mergeResult = libGitRepo.Merge(
804 DefaultCommitterName,
805 DefaultCommitterEmail,
806 DateTimeOffset.UtcNow),
809 FastForwardStrategy = FastForwardStrategy.FastForwardOnly,
810 FailOnConflict = true,
813 if (mergeResult.Status == MergeStatus.UpToDate)
820 CheckoutModifiers = CheckoutModifiers.Force,
828 TaskScheduler.Current);
834 CancellationToken cancellationToken) => gitRemoteFeatures.GetTestMerge(
840 public Task<DateTimeOffset>
TimestampCommit(
string sha, CancellationToken cancellationToken) => Task.Factory.StartNew(
843 ArgumentNullException.ThrowIfNull(sha);
845 var commit = libGitRepo.Lookup<Commit>(sha) ??
throw new JobException($
"Commit {sha} does not exist in the repository!");
846 return commit.Committer.When.ToUniversalTime();
850 TaskScheduler.Current);
860 logger.LogTrace(
"Checkout: {committish}", committish);
862 var stage = $
"Checkout {committish}";
863 progressReporter = progressReporter.
CreateSection(stage, 1.0);
865 cancellationToken.ThrowIfCancellationRequested();
867 var checkoutOptions =
new CheckoutOptions
869 CheckoutModifiers = CheckoutModifiers.Force,
870 OnCheckoutProgress = CheckoutProgressHandler(progressReporter),
873 void RunCheckout() => commands.Checkout(
882 catch (NotFoundException)
885 var remoteName = $
"origin/{committish}";
886 var remoteBranch = libGitRepo.Branches.FirstOrDefault(
887 branch => branch.FriendlyName.Equals(remoteName, StringComparison.Ordinal));
888 cancellationToken.ThrowIfCancellationRequested();
890 if (remoteBranch ==
default)
893 logger.LogDebug(
"Creating local branch for {remoteBranchFriendlyName}...", remoteBranch.FriendlyName);
894 var branch = libGitRepo.CreateBranch(committish, remoteBranch.Tip);
896 libGitRepo.Branches.Update(branch, branchUpdate => branchUpdate.TrackedBranch = remoteBranch.CanonicalName);
898 cancellationToken.ThrowIfCancellationRequested();
903 cancellationToken.ThrowIfCancellationRequested();
905 libGitRepo.RemoveUntrackedFiles();
919 logger.LogInformation(
"Pushing changes to temporary remote branch...");
920 var branch = libGitRepo.CreateBranch(RemoteTemporaryBranchName);
923 cancellationToken.ThrowIfCancellationRequested();
924 var remote = libGitRepo.Network.Remotes.First();
927 var forcePushString = String.Format(CultureInfo.InvariantCulture,
"+{0}:{0}", branch.CanonicalName);
928 libGitRepo.Network.Push(remote, forcePushString, GeneratePushOptions(progressReporter.CreateSection(
null, 0.9), username, password, cancellationToken));
929 var removalString = String.Format(CultureInfo.InvariantCulture,
":{0}", branch.CanonicalName);
930 libGitRepo.Network.Push(remote, removalString, GeneratePushOptions(progressReporter.CreateSection(
null, 0.1), username, password, cancellationToken));
932 catch (UserCancelledException)
934 cancellationToken.ThrowIfCancellationRequested();
936 catch (LibGit2SharpException e)
938 logger.LogWarning(e,
"Unable to push to temporary branch!");
943 libGitRepo.Branches.Remove(branch);
948 TaskScheduler.Current);
960 var subProgressReporter = progressReporter.
CreateSection(
null, 0.5);
962 return new PushOptions
964 OnPackBuilderProgress = (stage, current, total) =>
966 var baseProgress = stage == PackBuilderStage.Counting ? 0 : 0.5;
967 var addon = total > 0 && current <= total ? (0.5 * ((double)current / total)) : 0;
969 return !cancellationToken.IsCancellationRequested;
971 OnNegotiationCompletedBeforePush = (a) =>
973 subProgressReporter = progressReporter.
CreateSection(
null, 0.5);
974 return !cancellationToken.IsCancellationRequested;
976 OnPushTransferProgress = (a, sentBytes, totalBytes) =>
979 return !cancellationToken.IsCancellationRequested;
981 CredentialsProvider = credentialsProvider.GenerateCredentialsHandler(username, password),
998 bool deploymentPipeline,
999 CancellationToken cancellationToken)
1001 var submoduleCount = libGitRepo.Submodules.Count();
1002 if (submoduleCount == 0)
1004 logger.LogTrace(
"No submodules, skipping update");
1008 logger.LogTrace(
"Updating submodules with{orWithout} credentials...", username ==
null ?
"out" : String.Empty);
1010 var factor = 1.0 / submoduleCount / 2;
1011 foreach (var submodule
in libGitRepo.Submodules)
1013 var submoduleUpdateOptions =
new SubmoduleUpdateOptions
1016 OnTransferProgress = TransferProgressHandler(
1017 progressReporter.CreateSection($
"Fetch submodule {submodule.Name}", factor),
1019 OnProgress = output => !cancellationToken.IsCancellationRequested,
1020 OnUpdateTips = (a, b, c) => !cancellationToken.IsCancellationRequested,
1021 CredentialsProvider = credentialsProvider.GenerateCredentialsHandler(username, password),
1022 OnCheckoutProgress = CheckoutProgressHandler(
1023 progressReporter.CreateSection($
"Checkout submodule {submodule.Name}", factor)),
1026 logger.LogDebug(
"Updating submodule {submoduleName}...", submodule.Name);
1027 Task RawSubModuleUpdate() => Task.Factory.StartNew(
1028 () => libGitRepo.Submodules.Update(submodule.Name, submoduleUpdateOptions),
1031 TaskScheduler.Current);
1034 await RawSubModuleUpdate();
1036 catch (LibGit2SharpException ex)
1040 progressReporter.ReportProgress(
null);
1041 credentialsProvider.CheckBadCredentialsException(ex);
1042 logger.LogWarning(ex,
"Initial update of submodule {submoduleName} failed. Deleting submodule directories and re-attempting...", submodule.Name);
1045 ioMananger.DeleteDirectory($
".git/modules/{submodule.Path}", cancellationToken),
1046 ioMananger.DeleteDirectory(submodule.Path, cancellationToken));
1048 logger.LogTrace(
"Second update attempt for submodule {submoduleName}...", submodule.Name);
1051 await RawSubModuleUpdate();
1053 catch (UserCancelledException)
1055 cancellationToken.ThrowIfCancellationRequested();
1057 catch (LibGit2SharpException ex2)
1059 credentialsProvider.CheckBadCredentialsException(ex2);
1060 logger.LogTrace(ex2,
"Retried update of submodule {submoduleName} failed!", submodule.Name);
1061 throw new AggregateException(ex, ex2);
1065 await eventConsumer.HandleEvent(
1067 new List<string> { submodule.Name },
1083 if (completedSteps == 0)
1085 else if (totalSteps < completedSteps || totalSteps == 0)
1089 percentage = ((double)completedSteps) / totalSteps;
1094 if (percentage ==
null)
1096 "Bad checkout progress values (Please tell Dominion)! Completeds: {completed}, Total: {total}",
1100 progressReporter.ReportProgress(percentage);
1112 var totalObjectsToProcess = transferProgress.TotalObjects * 2;
1113 var processedObjects = transferProgress.IndexedObjects + transferProgress.ReceivedObjects;
1114 if (totalObjectsToProcess < processedObjects || totalObjectsToProcess == 0)
1118 percentage = (double)processedObjects / totalObjectsToProcess;
1123 if (percentage ==
null)
1125 "Bad transfer progress values (Please tell Cyberboss)! Indexed: {indexed}, Received: {received}, Total: {total}",
1126 transferProgress.IndexedObjects,
1127 transferProgress.ReceivedObjects,
1128 transferProgress.TotalObjects);
1130 progressReporter.ReportProgress(percentage);
1131 return !cancellationToken.IsCancellationRequested;
Represents configurable settings for a git repository.
Parameters for creating a TestMerge.
virtual ? string TargetCommitSha
The sha of the test merge revision to merge. If not specified, the latest commit from the source will...
string? Comment
Optional comment about the test.
int Number
The number of the test merge source.
string Reference
The current reference the IRepository HEAD is using. This can be a branch or tag.
readonly IIOManager ioMananger
The IIOManager for the Repository.
void RawCheckout(string committish, JobProgressReporter progressReporter, CancellationToken cancellationToken)
Runs a blocking force checkout to committish .
readonly ILibGit2Commands commands
The ILibGit2Commands for the Repository.
async Task CopyTo(string path, CancellationToken cancellationToken)
Copies the current working directory to a given path . A Task representing the running operation.
const string OriginTrackingErrorTemplate
Template error message for when tracking of the most recent origin commit fails.
Task ResetToSha(string sha, JobProgressReporter progressReporter, CancellationToken cancellationToken)
Requires the current HEAD to be a reference. Hard resets the reference to the given sha....
const string DefaultCommitterEmail
The default password for committers.
string Head
The SHA of the IRepository HEAD.
bool Tracking
If Reference tracks an upstream branch.
const string RemoteTemporaryBranchName
The branch name used for publishing testmerge commits.
string RemoteRepositoryOwner
If RemoteGitProvider is not RemoteGitProvider.Unknown this will be set with the owner of the reposito...
bool disposed
If the Repository was disposed.
Uri Origin
The current origin remote the IRepository is using.
Repository(LibGit2Sharp.IRepository libGitRepo, ILibGit2Commands commands, IIOManager ioMananger, IEventConsumer eventConsumer, ICredentialsProvider credentialsProvider, IPostWriteHandler postWriteHandler, IGitRemoteFeaturesFactory gitRemoteFeaturesFactory, ILogger< Repository > logger, GeneralConfiguration generalConfiguration, Action onDispose)
Initializes a new instance of the Repository class.
Task< Models.TestMerge > GetTestMerge(TestMergeParameters parameters, RepositorySettings repositorySettings, CancellationToken cancellationToken)
Retrieve the Models.TestMerge representation of given test merge parameters . A Task<TResult> resulti...
readonly LibGit2Sharp.IRepository libGitRepo
The LibGit2Sharp.IRepository for the Repository.
Task PushHeadToTemporaryBranch(string username, string password, JobProgressReporter progressReporter, CancellationToken cancellationToken)
Force push the current repository HEAD to RemoteTemporaryBranchName;.
readonly IGitRemoteFeatures gitRemoteFeatures
The IGitRemoteFeatures for the Repository.
async Task FetchOrigin(JobProgressReporter progressReporter, string username, string password, bool deploymentPipeline, CancellationToken cancellationToken)
Fetch commits from the origin repository. A Task representing the running operation.
TransferProgressHandler TransferProgressHandler(JobProgressReporter progressReporter, CancellationToken cancellationToken)
Generate a LibGit2Sharp.Handlers.TransferProgressHandler from a given progressReporter and cancellat...
PushOptions GeneratePushOptions(JobProgressReporter progressReporter, string username, string password, CancellationToken cancellationToken)
Generate a standard set of PushOptions.
readonly ILogger< Repository > logger
The ILogger for the Repository.
async Task< bool > Sychronize(JobProgressReporter progressReporter, string username, string password, string committerName, string committerEmail, bool synchronizeTrackedBranch, bool deploymentPipeline, CancellationToken cancellationToken)
Runs the synchronize event script and attempts to push any changes made to the IRepository if on a tr...
async Task< bool?> MergeOrigin(JobProgressReporter progressReporter, string committerName, string committerEmail, bool deploymentPipeline, CancellationToken cancellationToken)
Requires the current HEAD to be a tracked reference. Merges the reference to what it tracks on the or...
async Task ResetToOrigin(JobProgressReporter progressReporter, string username, string password, bool updateSubmodules, bool deploymentPipeline, CancellationToken cancellationToken)
Requires the current HEAD to be a tracked reference. Hard resets the reference to what it tracks on t...
Task< bool > ShaIsParent(string sha, CancellationToken cancellationToken)
Check if a given sha is a parent of the current Head. A Task<TResult> resulting in true if sha is a...
readonly IPostWriteHandler postWriteHandler
The IPostWriteHandler for the Repository.
const string DefaultCommitterName
The default username for committers.
const string UnknownReference
Used when a reference cannot be determined.
Task< string > GetOriginSha(CancellationToken cancellationToken)
Get the tracked reference's current SHA. A Task<TResult> resulting in the tracked origin reference's ...
Task< bool > IsSha(string committish, CancellationToken cancellationToken)
Checks if a given committish is a sha. A Task<TResult> resulting in true if committish is a sha,...
async Task UpdateSubmodules(JobProgressReporter progressReporter, string username, string password, bool deploymentPipeline, CancellationToken cancellationToken)
Recusively update all Submodules in the libGitRepo.
readonly IEventConsumer eventConsumer
The IEventConsumer for the Repository.
readonly Action onDispose
Action to be taken when Dispose is called.
async Task CheckoutObject(string committish, string username, string password, bool updateSubmodules, JobProgressReporter progressReporter, CancellationToken cancellationToken)
Checks out a given committish . A Task representing the running operation.
CheckoutProgressHandler CheckoutProgressHandler(JobProgressReporter progressReporter)
Converts a given progressReporter to a LibGit2Sharp.Handlers.CheckoutProgressHandler.
async Task< TestMergeResult > AddTestMerge(TestMergeParameters testMergeParameters, string committerName, string committerEmail, string username, string password, bool updateSubmodules, JobProgressReporter progressReporter, CancellationToken cancellationToken)
Attempt to merge the revision specified by a given set of testMergeParameters into HEAD....
string RemoteRepositoryName
If RemoteGitProvider is not RemoteGitProvider.Unknown this will be set with the name of the repositor...
readonly ICredentialsProvider credentialsProvider
The ICredentialsProvider for the Repository.
Task< DateTimeOffset > TimestampCommit(string sha, CancellationToken cancellationToken)
Gets the DateTimeOffset a given sha was created on. A Task<TResult> resulting in the DateTimeOffset ...
readonly GeneralConfiguration generalConfiguration
The GeneralConfiguration for the Repository.
Represents the result of a repository test merge attempt.
MergeStatus Status
The resulting MergeStatus.
General configuration options.
IIOManager that resolves paths to Environment.CurrentDirectory.
const TaskCreationOptions BlockingTaskCreationOptions
The TaskCreationOptions used to spawn Tasks for potentially long running, blocking operations.
Operation exceptions thrown from the context of a Models.Job.
Progress reporter for a Job.
void ReportProgress(double? progress)
Report progress.
JobProgressReporter CreateSection(string newStageName, double percentage)
Create a subsection of the JobProgressReporter with its optional own stage name.
Consumes EventTypes and takes the appropriate actions.
Task HandleEvent(EventType eventType, IEnumerable< string > parameters, bool deploymentPipeline, CancellationToken cancellationToken)
Handle a given eventType .
For generating CredentialsHandlers.
CredentialsHandler GenerateCredentialsHandler(string username, string password)
Generate a CredentialsHandler from a given username and password .
void CheckBadCredentialsException(LibGit2SharpException exception)
Rethrow the authentication failure message as a JobException if it is one.
Factory for creating IGitRemoteFeatures.
IGitRemoteFeatures CreateGitRemoteFeatures(IRepository repository)
Create the IGitRemoteFeatures for a given repository .
Provides features for remote git services.
string TestMergeLocalBranchNameFormatter
Get.
string TestMergeRefSpecFormatter
Gets a formatter string which creates the remote refspec for fetching the HEAD of passed in test merg...
For low level interactions with a LibGit2Sharp.IRepository.
void Fetch(LibGit2Sharp.IRepository repository, IEnumerable< string > refSpecs, Remote remote, FetchOptions fetchOptions, string logMessage)
Runs a blocking fetch operation on a given repository .
Represents an on-disk git repository.
string Head
The SHA of the IRepository HEAD.
Interface for using filesystems.
string ResolvePath()
Retrieve the full path of the current working directory.
Task CopyDirectory(IEnumerable< string > ignore, Func< string, string, Task > postCopyCallback, string src, string dest, int? taskThrottle, CancellationToken cancellationToken)
Copies a directory from src to dest .
Handles changing file modes/permissions after writing.
void HandleWrite(string filePath)
For handling system specific necessities after a write.
bool NeedsPostWrite(string sourceFilePath)
Check if a given sourceFilePath will need HandleWrite(string) called on a copy of it.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
RemoteGitProvider
Indicates the remote git host.
EventType
Types of events. Mirror in tgs.dm.