Skip to content

Commit

Permalink
BackgroundFetch: disable interactive auth
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Jan 23, 2020
1 parent 0da7c43 commit 1493bf6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
28 changes: 22 additions & 6 deletions Scalar.Common/Git/GitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -683,7 +696,8 @@ protected virtual Result InvokeGitImpl(
Action<StreamWriter> writeStdIn,
Action<string> parseStdOutLine,
int timeoutMs,
string gitObjectsDirectory = null)
string gitObjectsDirectory = null,
bool userInteractive = true)
{
if (failedToSetEncoding && writeStdIn != null)
{
Expand All @@ -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();
Expand Down Expand Up @@ -840,7 +855,8 @@ private Result InvokeGitInWorkingDirectoryRoot(
string command,
bool fetchMissingObjects,
Action<StreamWriter> writeStdIn = null,
Action<string> parseStdOutLine = null)
Action<string> parseStdOutLine = null,
bool userInteractive = true)
{
return this.InvokeGitImpl(
command,
Expand Down
3 changes: 2 additions & 1 deletion Scalar.UnitTests/Mock/Git/MockGitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ protected override Result InvokeGitImpl(
Action<StreamWriter> writeStdIn,
Action<string> parseStdOutLine,
int timeoutMs,
string gitObjectsDirectory = null)
string gitObjectsDirectory = null,
bool userInteractive = true)
{
this.CommandsRun.Add(command);

Expand Down

0 comments on commit 1493bf6

Please sign in to comment.