From 5aba26e0dc9747be024d686c414bc42b524193cd Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 31 Jul 2018 11:07:21 -0400 Subject: [PATCH] Other fixups --- src/Tgstation.Server.Api/Models/Repository.cs | 2 +- .../Components/Repository/IRepository.cs | 10 +++++----- .../Components/Repository/Repository.cs | 15 +++++++-------- .../Controllers/RepositoryController.cs | 12 ++++++++++-- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Tgstation.Server.Api/Models/Repository.cs b/src/Tgstation.Server.Api/Models/Repository.cs index 0970a9655c..9b65efa513 100644 --- a/src/Tgstation.Server.Api/Models/Repository.cs +++ b/src/Tgstation.Server.Api/Models/Repository.cs @@ -51,7 +51,7 @@ namespace Tgstation.Server.Api.Models public string Reference { get; set; } /// - /// for new s + /// for new s. Note that merges that conflict will not be performed /// [Permissions(WriteRight = RepositoryRights.MergePullRequest)] public List NewTestMerges { get; set; } diff --git a/src/Tgstation.Server.Host/Components/Repository/IRepository.cs b/src/Tgstation.Server.Host/Components/Repository/IRepository.cs index a2821a2eb9..13dde17437 100644 --- a/src/Tgstation.Server.Host/Components/Repository/IRepository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/IRepository.cs @@ -62,8 +62,8 @@ namespace Tgstation.Server.Host.Components.Repository /// The access string to fetch from the origin repository /// The for the operation /// Optional function to report 0-100 progress of the clone - /// A resulting in the SHA of the new HEAD on success, on merge conflict - Task AddTestMerge(int pullRequestNumber, string targetCommit, string committerName, string committerEmail, string accessString, Action progressReporter, CancellationToken cancellationToken); + /// A resulting in a representing the merge result that is after a fast forward or up to date, on a merge, on a conflict + Task AddTestMerge(int pullRequestNumber, string targetCommit, string committerName, string committerEmail, string accessString, Action progressReporter, CancellationToken cancellationToken); /// /// Fetch commits from the origin repository @@ -79,7 +79,7 @@ namespace Tgstation.Server.Host.Components.Repository /// /// The for the operation /// A resulting in the SHA of the new HEAD - Task ResetToOrigin(CancellationToken cancellationToken); + Task ResetToOrigin(CancellationToken cancellationToken); /// /// Requires the current HEAD to be a tracked reference. Merges the reference to what it tracks on the origin repository @@ -87,8 +87,8 @@ namespace Tgstation.Server.Host.Components.Repository /// The name of the merge committer /// The e-mail of the merge committer /// The for the operation - /// A resulting in the SHA of the new HEAD. if the merge resulted in conflict - Task MergeOrigin(string committerName, string committerEmail, CancellationToken cancellationToken); + /// A resulting in a representing the merge result that is after a fast forward or up to date, on a merge, on a conflict + Task MergeOrigin(string committerName, string committerEmail, CancellationToken cancellationToken); /// /// Force push the current repository HEAD to ; diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs index 39552fa2c6..9dbab666f3 100644 --- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs @@ -139,7 +139,7 @@ namespace Tgstation.Server.Host.Components.Repository } /// - public async Task AddTestMerge(int pullRequestNumber, string targetCommit, string committerName, string committerEmail, string accessString, Action progressReporter, CancellationToken cancellationToken) + public async Task AddTestMerge(int pullRequestNumber, string targetCommit, string committerName, string committerEmail, string accessString, Action progressReporter, CancellationToken cancellationToken) { if (!IsGitHubRepository) @@ -206,10 +206,10 @@ namespace Tgstation.Server.Host.Components.Repository if (result.Status == MergeStatus.Conflicts) { await eventConsumer.HandleEvent(EventType.RepoMergeConflict, new List { originalCommit.Tip.Sha, targetCommit, originalCommit.FriendlyName ?? UnknownReference, prBranchName }, cancellationToken).ConfigureAwait(false); - return null; + return false; } - return result.Commit.Sha; + return true; } /// @@ -285,13 +285,13 @@ namespace Tgstation.Server.Host.Components.Repository }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); /// - public async Task ResetToOrigin(CancellationToken cancellationToken) + public async Task ResetToOrigin(CancellationToken cancellationToken) { if (!repository.Head.IsTracking) throw new InvalidOperationException("Cannot reset to origin while not on a tracked reference!"); var trackedBranch = repository.Head.TrackedBranch; await eventConsumer.HandleEvent(EventType.RepoResetOrigin, new List { trackedBranch.FriendlyName, trackedBranch.Tip.Sha }, cancellationToken).ConfigureAwait(false); - return await Task.Factory.StartNew(() => + await Task.Factory.StartNew(() => { Commands.Checkout((LibGit2Sharp.Repository)repository, repository.Head.TrackedBranch, new CheckoutOptions { @@ -299,7 +299,6 @@ namespace Tgstation.Server.Host.Components.Repository }); cancellationToken.ThrowIfCancellationRequested(); repository.RemoveUntrackedFiles(); - return trackedBranch.Tip.Sha; }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); } @@ -312,7 +311,7 @@ namespace Tgstation.Server.Host.Components.Repository } /// - public async Task MergeOrigin(string committerName, string committerEmail, CancellationToken cancellationToken) + public async Task MergeOrigin(string committerName, string committerEmail, CancellationToken cancellationToken) { MergeResult result = null; Branch trackedBranch = null; @@ -350,7 +349,7 @@ namespace Tgstation.Server.Host.Components.Repository return null; } - return Head; + return result.Status != MergeStatus.NonFastForward; } /// diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index 8f7346534b..f05938f75a 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -336,8 +336,12 @@ namespace Tgstation.Server.Host.Controllers doneFetches = 1; if (!modelHasShaOrReference) { - await repo.MergeOrigin(committerName, currentModel.CommitterEmail, cancellationToken).ConfigureAwait(false); + var fastForward = await repo.MergeOrigin(committerName, currentModel.CommitterEmail, cancellationToken).ConfigureAwait(false); + if (!fastForward.HasValue) + throw new InvalidOperationException("Merge conflict occurred during origin update!"); await UpdateRevInfo().ConfigureAwait(false); + if (fastForward.Value) + lastRevisionInfo.OriginCommitSha = repo.Head; } } @@ -372,7 +376,11 @@ namespace Tgstation.Server.Host.Controllers { var prTask = gitHubClient.PullRequest.Get(repoOwner, repoName, I.Number); - await repo.AddTestMerge(I.Number, I.PullRequestRevision, committerName, currentModel.CommitterEmail, accessString, x => progressReporter((x + 100 * doneFetches) / numFetches), cancellationToken).ConfigureAwait(false); + var mergeResult = await repo.AddTestMerge(I.Number, I.PullRequestRevision, committerName, currentModel.CommitterEmail, accessString, x => progressReporter((x + 100 * doneFetches) / numFetches), cancellationToken).ConfigureAwait(false); + + if (!mergeResult.HasValue) //conflict, we don't care, dd already knows + continue; + ++doneFetches; var revInfoUpdateTask = UpdateRevInfo();