mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-07-18 19:43:02 +01:00
Rename ShaIsParent to CommittishIsParent
Update functionality to reflect this.
This commit is contained in:
+1
-1
@@ -198,7 +198,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
|
||||
return;
|
||||
|
||||
// We don't just assume, actually check the repo contains the merge commit.
|
||||
if (await repository.ShaIsParent(pr.MergeCommitSha, cancellationToken))
|
||||
if (await repository.CommittishIsParent(pr.MergeCommitSha, cancellationToken))
|
||||
{
|
||||
if (lastMerged == null || lastMerged.MergedAt < pr.MergedAt)
|
||||
lastMerged = pr;
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
|
||||
return;
|
||||
|
||||
// We don't just assume, actually check the repo contains the merge commit.
|
||||
if (await repository.ShaIsParent(mergeRequest.MergeCommitSha, cancellationToken))
|
||||
if (await repository.CommittishIsParent(mergeRequest.MergeCommitSha, cancellationToken))
|
||||
{
|
||||
if (lastMerged == null || lastMerged.ClosedAt < mergeRequest.ClosedAt)
|
||||
lastMerged = mergeRequest;
|
||||
|
||||
@@ -152,7 +152,7 @@ namespace Tgstation.Server.Host.Components.Engine
|
||||
progressSection2,
|
||||
cancellationToken);
|
||||
|
||||
if (!await repo.ShaIsParent("fab769776dada6b9bcad546094d78c604049e0e9", cancellationToken))
|
||||
if (!await repo.CommittishIsParent("fab769776dada6b9bcad546094d78c604049e0e9", cancellationToken))
|
||||
throw new JobException(ErrorCode.OpenDreamTooOld);
|
||||
|
||||
return new RepositoryEngineInstallationData(IOManager, repo, InstallationSourceSubDirectory);
|
||||
|
||||
@@ -170,13 +170,13 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
ValueTask CopyTo(string path, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Check if a given <paramref name="sha"/> is a parent of the current <see cref="Head"/>.
|
||||
/// Check if a given <paramref name="committish"/> is a parent of the current <see cref="Head"/>.
|
||||
/// </summary>
|
||||
/// <param name="sha">The SHA to check.</param>
|
||||
/// <param name="committish">The committish of the SHA to check.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if <paramref name="sha"/> is a parent of <see cref="Head"/>, <see langword="false"/> otherwise.</returns>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if <paramref name="committish"/> is a parent of <see cref="Head"/>, <see langword="false"/> otherwise.</returns>
|
||||
/// <remarks>This function is NOT reentrant.</remarks>
|
||||
Task<bool> ShaIsParent(string sha, CancellationToken cancellationToken);
|
||||
Task<bool> CommittishIsParent(string committish, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Get the tracked reference's current SHA.
|
||||
|
||||
@@ -791,16 +791,34 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
TaskScheduler.Current);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<bool> ShaIsParent(string sha, CancellationToken cancellationToken) => Task.Factory.StartNew(
|
||||
public Task<bool> CommittishIsParent(string committish, CancellationToken cancellationToken) => Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
var targetCommit = libGitRepo.Lookup<Commit>(sha);
|
||||
if (targetCommit == null)
|
||||
var targetObject = libGitRepo.Lookup(committish);
|
||||
if (targetObject == null)
|
||||
{
|
||||
logger.LogTrace("Commit {sha} not found in repository", sha);
|
||||
logger.LogTrace("Committish {committish} not found in repository", committish);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (targetObject is not Commit targetCommit)
|
||||
{
|
||||
if (targetObject is not TagAnnotation)
|
||||
{
|
||||
logger.LogTrace("Committish {committish} is a {type} and does not point to a commit!", committish, targetObject.GetType().Name);
|
||||
return false;
|
||||
}
|
||||
|
||||
targetCommit = targetObject.Peel<Commit>();
|
||||
if (targetCommit == null)
|
||||
{
|
||||
logger.LogError(
|
||||
"TagAnnotation {committish} was found but the commit associated with it could not be found in repository!",
|
||||
committish);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var startSha = Head;
|
||||
var mergeResult = libGitRepo.Merge(
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Tgstation.Server.Host.Components.Engine.Tests
|
||||
|
||||
var cloneAttempts = 0;
|
||||
var mockRepository = new Mock<IRepository>();
|
||||
mockRepository.Setup(x => x.ShaIsParent(It.IsNotNull<string>(), It.IsAny<CancellationToken>())).ReturnsAsync(true);
|
||||
mockRepository.Setup(x => x.CommittishIsParent(It.IsNotNull<string>(), It.IsAny<CancellationToken>())).ReturnsAsync(true);
|
||||
var mockRepositoryManager = new Mock<IRepositoryManager>();
|
||||
mockRepositoryManager.Setup(x => x.CloneRepository(
|
||||
generalConfig.OpenDreamGitUrl,
|
||||
|
||||
@@ -42,10 +42,10 @@ namespace Tgstation.Server.Tests
|
||||
|
||||
const string StartSha = "af4da8beb9f9b374b04a3cc4d65acca662e8cc1a";
|
||||
await repo.CheckoutObject(StartSha, null, null, true, new JobProgressReporter(Mock.Of<ILogger<JobProgressReporter>>(), null, (stage, progress) => { }), CancellationToken.None);
|
||||
var result = await repo.ShaIsParent("2f8588a3ca0f6b027704a2a04381215619de3412", CancellationToken.None);
|
||||
var result = await repo.CommittishIsParent("2f8588a3ca0f6b027704a2a04381215619de3412", CancellationToken.None);
|
||||
Assert.IsTrue(result);
|
||||
Assert.AreEqual(StartSha, repo.Head);
|
||||
result = await repo.ShaIsParent("f636418bf47d238d33b0e4a34f0072b23a8aad0e", CancellationToken.None);
|
||||
result = await repo.CommittishIsParent("f636418bf47d238d33b0e4a34f0072b23a8aad0e", CancellationToken.None);
|
||||
Assert.IsFalse(result);
|
||||
Assert.AreEqual(StartSha, repo.Head);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user