diff --git a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs index a100e1a3de..b9e01435b7 100644 --- a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs +++ b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs @@ -289,6 +289,7 @@ namespace Tgstation.Server.Host.Components.Deployment }; logger.LogInformation(Repository.Repository.OriginTrackingErrorTemplate, repoSha); + databaseContext.RevisionInformations.Add(revInfo); databaseContext.Instances.Attach(revInfo.Instance); await databaseContext.Save(cancellationToken).ConfigureAwait(false); } diff --git a/src/Tgstation.Server.Host/Components/Instance.cs b/src/Tgstation.Server.Host/Components/Instance.cs index d61bfa79e5..d8cf737f1d 100644 --- a/src/Tgstation.Server.Host/Components/Instance.cs +++ b/src/Tgstation.Server.Host/Components/Instance.cs @@ -308,27 +308,14 @@ namespace Tgstation.Server.Host.Components cancellationToken) .ConfigureAwait(false); - RevisionInformation currentRevInfo = null; - Task LoadRevInfo() => databaseContext.RevisionInformations - .AsQueryable() - .Where(x => x.CommitSha == startSha && x.Instance.Id == metadata.Id) - .Include(x => x.ActiveTestMerges).ThenInclude(x => x.TestMerge) - .FirstOrDefaultAsync(cancellationToken); + .AsQueryable() + .Where(x => x.CommitSha == startSha && x.Instance.Id == metadata.Id) + .Include(x => x.ActiveTestMerges).ThenInclude(x => x.TestMerge) + .FirstOrDefaultAsync(cancellationToken); + RevisionInformation currentRevInfo = null; var hasDbChanges = false; - - // take appropriate auto update actions - var shouldSyncTracked = false; - var currentRevInfoTask = LoadRevInfo(); - - var result = await repo.MergeOrigin( - repositorySettings.CommitterName, - repositorySettings.CommitterEmail, - NextProgressReporter(), - cancellationToken) - .ConfigureAwait(false); - async Task UpdateRevInfo(string currentHead, bool onOrigin, IEnumerable updatedTestMerges) { if (currentRevInfo == null) @@ -363,14 +350,25 @@ namespace Tgstation.Server.Host.Components hasDbChanges = true; } + // build current commit data if it's missing + await UpdateRevInfo(repo.Head, false, null).ConfigureAwait(false); + + var result = await repo.MergeOrigin( + repositorySettings.CommitterName, + repositorySettings.CommitterEmail, + NextProgressReporter(), + cancellationToken) + .ConfigureAwait(false); + var preserveTestMerges = repositorySettings.AutoUpdatesKeepTestMerges.Value; var remoteDeploymentManager = remoteDeploymentManagerFactory.CreateRemoteDeploymentManager( metadata, repo.RemoteGitProvider.Value); + + // take appropriate auto update actions + var shouldSyncTracked = false; if (result.HasValue) { - currentRevInfo = await currentRevInfoTask.ConfigureAwait(false); - var updatedTestMerges = await remoteDeploymentManager.RemoveMergedTestMerges( repo, repositorySettings, diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs index 0a5107bc62..a8a1903301 100644 --- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs @@ -139,6 +139,9 @@ namespace Tgstation.Server.Host.Components.Repository { if (exception.Message == "too many redirects or authentication replays") throw new JobException("Bad git credentials exchange!", exception); + + if (exception.Message == ErrorCode.RepoCredentialsRequired.Describe()) + throw new JobException(ErrorCode.RepoCredentialsRequired); } /// @@ -963,8 +966,12 @@ namespace Tgstation.Server.Host.Components.Repository // workaround for https://github.com/libgit2/libgit2/issues/3820 // kill off the modules/ folder in .git and try again CheckBadCredentialsException(ex); - logger.LogWarning(ex, "Initial update of submodule {0} failed. Deleting .git submodule directory and re-attempting...", submodule.Name); - await ioMananger.DeleteDirectory($".git/modules/{submodule.Path}", cancellationToken).ConfigureAwait(false); + logger.LogWarning(ex, "Initial update of submodule {0} failed. Deleting submodule directories and re-attempting...", submodule.Name); + + await Task.WhenAll( + ioMananger.DeleteDirectory($".git/modules/{submodule.Path}", cancellationToken), + ioMananger.DeleteDirectory(submodule.Path, cancellationToken)) + .ConfigureAwait(false); logger.LogTrace("Second update attempt for submodule {0}...", submodule.Name); try