Fix issue with CheckoutSha requests

This commit is contained in:
Jordan Brown
2020-04-25 00:15:33 -04:00
parent 2791053137
commit 1d9f38ec9c
2 changed files with 9 additions and 3 deletions
@@ -524,8 +524,13 @@ namespace Tgstation.Server.Host.Controllers
// checkout/hard reset
if (modelHasShaOrReference)
{
if ((model.CheckoutSha != null && repo.Head.ToUpperInvariant().StartsWith(model.CheckoutSha.ToUpperInvariant(), StringComparison.Ordinal))
|| (model.Reference != null && repo.Reference.ToUpperInvariant() != model.Reference.ToUpperInvariant()))
var validCheckoutSha =
model.CheckoutSha != null
&& !repo.Head.StartsWith(model.CheckoutSha, StringComparison.OrdinalIgnoreCase);
var validCheckoutReference =
model.Reference != null
&& !repo.Reference.Equals(model.Reference, StringComparison.OrdinalIgnoreCase);
if (validCheckoutSha || validCheckoutReference)
{
var committish = model.CheckoutSha ?? model.Reference;
var isSha = await repo.IsSha(committish, cancellationToken).ConfigureAwait(false);
@@ -88,6 +88,7 @@ namespace Tgstation.Server.Tests.Instance
updated = await Checkout(updated, false, false, cancellationToken);
// Fake SHA
updated.Reference = null;
updated.CheckoutSha = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
updated = await Checkout(updated, true, false, cancellationToken);
@@ -97,7 +98,7 @@ namespace Tgstation.Server.Tests.Instance
// Back
updated.Reference = workingBranch;
updated = await Checkout(updated, true, true, cancellationToken);
updated = await Checkout(updated, false, true, cancellationToken);
var testPRString = Environment.GetEnvironmentVariable("TGS4_TEST_PULL_REQUEST_NUMBER");
if (String.IsNullOrWhiteSpace(testPRString))