diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs index c4f9eaaea9..3cf8df9d21 100644 --- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs @@ -116,6 +116,16 @@ namespace Tgstation.Server.Host.Components.Repository /// A based on static CheckoutProgressHandler CheckoutProgressHandler(Action progressReporter) => (a, completedSteps, totalSteps) => progressReporter((int)(((float)completedSteps) / totalSteps * 100)); + /// + /// Rethrow the authentication failure message as a if it is one. + /// + /// The current . + static void CheckBadCredentialsException(LibGit2SharpException exception) + { + if (exception.Message == "too many redirects or authentication replays") + throw new JobException("Bad git credentials exchange!", exception); + } + /// /// Construct a /// @@ -324,6 +334,10 @@ namespace Tgstation.Server.Host.Components.Repository logMessage); } catch (UserCancelledException) { } + catch (LibGit2SharpException ex) + { + CheckBadCredentialsException(ex); + } cancellationToken.ThrowIfCancellationRequested(); @@ -432,24 +446,35 @@ namespace Tgstation.Server.Host.Components.Repository var remote = libGitRepo.Network.Remotes.First(); try { - Commands.Fetch((LibGit2Sharp.Repository)libGitRepo, remote.Name, remote.FetchRefSpecs.Select(x => x.Specification), new FetchOptions - { - Prune = true, - OnProgress = (a) => !cancellationToken.IsCancellationRequested, - OnTransferProgress = (a) => + commands.Fetch( + libGitRepo, + remote + .FetchRefSpecs + .Select(x => x.Specification), + remote, + new FetchOptions { - var percentage = 100 * (((float)a.IndexedObjects + a.ReceivedObjects) / (a.TotalObjects * 2)); - progressReporter((int)percentage); - return !cancellationToken.IsCancellationRequested; + Prune = true, + OnProgress = (a) => !cancellationToken.IsCancellationRequested, + OnTransferProgress = (a) => + { + var percentage = 100 * (((float)a.IndexedObjects + a.ReceivedObjects) / (a.TotalObjects * 2)); + progressReporter((int)percentage); + return !cancellationToken.IsCancellationRequested; + }, + OnUpdateTips = (a, b, c) => !cancellationToken.IsCancellationRequested, + CredentialsProvider = credentialsProvider.GenerateCredentialsHandler(username, password) }, - OnUpdateTips = (a, b, c) => !cancellationToken.IsCancellationRequested, - CredentialsProvider = credentialsProvider.GenerateCredentialsHandler(username, password) - }, "Fetch origin commits"); + "Fetch origin commits"); } catch (UserCancelledException) { cancellationToken.ThrowIfCancellationRequested(); } + catch (LibGit2SharpException ex) + { + CheckBadCredentialsException(ex); + } }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); } @@ -480,7 +505,7 @@ namespace Tgstation.Server.Host.Components.Repository { cancellationToken.ThrowIfCancellationRequested(); } - catch(LibGit2SharpException e) + catch (LibGit2SharpException e) { logger.LogWarning(e, "Unable to push to temporary branch!"); }