From 1493bf640e27c1da432e828f8cfc725207e72b35 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 23 Jan 2020 13:00:04 -0500 Subject: [PATCH] BackgroundFetch: disable interactive auth Signed-off-by: Derrick Stolee --- Scalar.Common/Git/GitProcess.cs | 28 ++++++++++++++++----- Scalar.UnitTests/Mock/Git/MockGitProcess.cs | 3 ++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Scalar.Common/Git/GitProcess.cs b/Scalar.Common/Git/GitProcess.cs index f735d98009..b1b7c17d7d 100644 --- a/Scalar.Common/Git/GitProcess.cs +++ b/Scalar.Common/Git/GitProcess.cs @@ -437,8 +437,9 @@ public Result BackgroundFetch(string remote) // The user will see their remote refs update // normally when they do a foreground fetch. return this.InvokeGitInWorkingDirectoryRoot( - $"fetch {remote} --quiet --prune --no-tags --refmap= \"{refspec}\"", - fetchMissingObjects: true); + $"-c credential.interactive=never fetch {remote} --quiet --prune --no-tags --refmap= \"{refspec}\"", + fetchMissingObjects: true, + userInteractive: false); } public string[] GetRemotes() @@ -613,7 +614,14 @@ public Result MultiPackIndexRepack(string gitObjectDirectory, string batchSize) return this.InvokeGitAgainstDotGitFolder($"-c pack.threads=1 multi-pack-index repack --object-dir=\"{gitObjectDirectory}\" --batch-size={batchSize}"); } - public Process GetGitProcess(string command, string workingDirectory, string dotGitDirectory, bool fetchMissingObjects, bool redirectStandardError, string gitObjectsDirectory) + public Process GetGitProcess( + string command, + string workingDirectory, + string dotGitDirectory, + bool fetchMissingObjects, + bool redirectStandardError, + string gitObjectsDirectory, + bool userInteractive = true) { ProcessStartInfo processInfo = new ProcessStartInfo(this.gitBinPath); processInfo.WorkingDirectory = workingDirectory; @@ -652,6 +660,11 @@ public Process GetGitProcess(string command, string workingDirectory, string dot processInfo.EnvironmentVariables["GIT_TERMINAL_PROMPT"] = "0"; processInfo.EnvironmentVariables["GCM_VALIDATE"] = "0"; + if (!userInteractive) + { + processInfo.EnvironmentVariables["GCM_INTERACTIVE"] = "Never"; + } + if (gitObjectsDirectory != null) { processInfo.EnvironmentVariables["GIT_OBJECT_DIRECTORY"] = gitObjectsDirectory; @@ -683,7 +696,8 @@ protected virtual Result InvokeGitImpl( Action writeStdIn, Action parseStdOutLine, int timeoutMs, - string gitObjectsDirectory = null) + string gitObjectsDirectory = null, + bool userInteractive = true) { if (failedToSetEncoding && writeStdIn != null) { @@ -701,7 +715,8 @@ protected virtual Result InvokeGitImpl( dotGitDirectory, fetchMissingObjects: fetchMissingObjects, redirectStandardError: true, - gitObjectsDirectory: gitObjectsDirectory)) + gitObjectsDirectory: gitObjectsDirectory, + userInteractive: userInteractive)) { StringBuilder output = new StringBuilder(); StringBuilder errors = new StringBuilder(); @@ -840,7 +855,8 @@ private Result InvokeGitInWorkingDirectoryRoot( string command, bool fetchMissingObjects, Action writeStdIn = null, - Action parseStdOutLine = null) + Action parseStdOutLine = null, + bool userInteractive = true) { return this.InvokeGitImpl( command, diff --git a/Scalar.UnitTests/Mock/Git/MockGitProcess.cs b/Scalar.UnitTests/Mock/Git/MockGitProcess.cs index b1e52a3a9d..32000c76df 100644 --- a/Scalar.UnitTests/Mock/Git/MockGitProcess.cs +++ b/Scalar.UnitTests/Mock/Git/MockGitProcess.cs @@ -82,7 +82,8 @@ protected override Result InvokeGitImpl( Action writeStdIn, Action parseStdOutLine, int timeoutMs, - string gitObjectsDirectory = null) + string gitObjectsDirectory = null, + bool userInteractive = true) { this.CommandsRun.Add(command);