mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-26 06:27:19 +01:00
Add support for showing conflicting files in repo update error
This commit is contained in:
@@ -85,7 +85,7 @@
|
||||
InstanceAutoUpdateStart,
|
||||
|
||||
/// <summary>
|
||||
/// Parameters: Base sha, target sha, base reference, target reference
|
||||
/// Parameters: Base sha, target sha, base reference, target reference, all conflicting files
|
||||
/// </summary>
|
||||
[EventScript("RepoMergeConflict")]
|
||||
RepoMergeConflict,
|
||||
|
||||
@@ -69,8 +69,8 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
/// <param name="updateSubmodules">If a submodule update should be attempted after the merge.</param>
|
||||
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="Nullable{T}"/> <see cref="bool"/> representing the merge result that is <see langword="true"/> after a fast forward or up to date, <see langword="false"/> on a non-fast-forward, <see langword="null"/> on a conflict.</returns>
|
||||
Task<bool?> AddTestMerge(
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="TestMergeResult"/>.</returns>
|
||||
Task<TestMergeResult> AddTestMerge(
|
||||
TestMergeParameters testMergeParameters,
|
||||
string committerName,
|
||||
string committerEmail,
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
|
||||
/// <inheritdoc />
|
||||
#pragma warning disable CA1506 // TODO: Decomplexify
|
||||
public async Task<bool?> AddTestMerge(
|
||||
public async Task<TestMergeResult> AddTestMerge(
|
||||
TestMergeParameters testMergeParameters,
|
||||
string committerName,
|
||||
string committerEmail,
|
||||
@@ -225,6 +225,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
var progressFactor = 1.0 / (updateSubmodules ? 3 : 2);
|
||||
|
||||
var sig = new Signature(new Identity(committerName, committerEmail), DateTimeOffset.UtcNow);
|
||||
List<string> conflictedPaths = null;
|
||||
await Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
@@ -279,7 +280,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
result = libGitRepo.Merge(testMergeParameters.TargetCommitSha, sig, new MergeOptions
|
||||
{
|
||||
CommitOnSuccess = commitMessage == null,
|
||||
FailOnConflict = true,
|
||||
FailOnConflict = false, // Needed to get conflicting files
|
||||
FastForwardStrategy = FastForwardStrategy.NoFastForward,
|
||||
SkipReuc = true,
|
||||
OnCheckoutProgress = CheckoutProgressHandler(
|
||||
@@ -295,6 +296,12 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
|
||||
if (result.Status == MergeStatus.Conflicts)
|
||||
{
|
||||
var repoStatus = libGitRepo.RetrieveStatus();
|
||||
conflictedPaths = new List<string>();
|
||||
foreach (var file in repoStatus)
|
||||
if (file.State == FileStatus.Conflicted)
|
||||
conflictedPaths.Add(file.FilePath);
|
||||
|
||||
var revertTo = originalCommit.CanonicalName ?? originalCommit.Tip.Sha;
|
||||
logger.LogDebug("Merge conflict, aborting and reverting to {0}", revertTo);
|
||||
progressReporter.ReportProgress(0);
|
||||
@@ -306,23 +313,29 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
},
|
||||
cancellationToken,
|
||||
DefaultIOManager.BlockingTaskCreationOptions,
|
||||
TaskScheduler.Current)
|
||||
;
|
||||
TaskScheduler.Current);
|
||||
|
||||
if (result.Status == MergeStatus.Conflicts)
|
||||
{
|
||||
var arguments = new List<string>
|
||||
{
|
||||
originalCommit.Tip.Sha,
|
||||
testMergeParameters.TargetCommitSha,
|
||||
originalCommit.FriendlyName ?? UnknownReference,
|
||||
testMergeBranchName,
|
||||
};
|
||||
|
||||
arguments.AddRange(conflictedPaths);
|
||||
|
||||
await eventConsumer.HandleEvent(
|
||||
EventType.RepoMergeConflict,
|
||||
new List<string>
|
||||
{
|
||||
originalCommit.Tip.Sha,
|
||||
testMergeParameters.TargetCommitSha,
|
||||
originalCommit.FriendlyName ?? UnknownReference,
|
||||
testMergeBranchName,
|
||||
},
|
||||
cancellationToken)
|
||||
;
|
||||
return null;
|
||||
arguments,
|
||||
cancellationToken);
|
||||
return new TestMergeResult
|
||||
{
|
||||
Status = result.Status,
|
||||
ConflictingFiles = conflictedPaths,
|
||||
};
|
||||
}
|
||||
|
||||
if (result.Status != MergeStatus.UpToDate)
|
||||
@@ -356,10 +369,12 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
testMergeParameters.TargetCommitSha,
|
||||
testMergeParameters.Comment,
|
||||
},
|
||||
cancellationToken)
|
||||
;
|
||||
cancellationToken);
|
||||
|
||||
return result.Status != MergeStatus.NonFastForward;
|
||||
return new TestMergeResult
|
||||
{
|
||||
Status = result.Status,
|
||||
};
|
||||
}
|
||||
#pragma warning restore CA1506
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using LibGit2Sharp;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -499,11 +501,11 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
NextProgressReporter($"Test merge #{newTestMerge.Number}"),
|
||||
cancellationToken);
|
||||
|
||||
if (mergeResult == null)
|
||||
if (mergeResult.Status == MergeStatus.Conflicts)
|
||||
throw new JobException(
|
||||
ErrorCode.RepoTestMergeConflict,
|
||||
new JobException(
|
||||
$"Test Merge #{newTestMerge.Number} at {newTestMerge.TargetCommitSha[..7]} conflicted!"));
|
||||
$"Test Merge #{newTestMerge.Number} at {newTestMerge.TargetCommitSha[..7]} conflicted! Conflicting files:{Environment.NewLine}{String.Join(Environment.NewLine, mergeResult.ConflictingFiles.Select(file => $"\t- /{file}"))}"));
|
||||
|
||||
Models.TestMerge fullTestMerge;
|
||||
try
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using LibGit2Sharp;
|
||||
|
||||
namespace Tgstation.Server.Host.Components.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the result of a repository test merge attempt.
|
||||
/// </summary>
|
||||
public sealed class TestMergeResult
|
||||
{
|
||||
/// <summary>
|
||||
/// The resulting <see cref="MergeStatus"/>.
|
||||
/// </summary>
|
||||
public MergeStatus Status { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// List of conflicting file paths relative to the repository root. Only present if <see cref="Status"/> is <see cref="MergeStatus.Conflicts"/>.
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> ConflictingFiles { get; init; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user