Skip to content

Commit

Permalink
Merge pull request #305: BackgroundFetch: disable interactive auth
Browse files Browse the repository at this point in the history
The [`GCM_INTERACTIVE`](https://github.com/microsoft/Git-Credential-Manager-for-Windows/blob/0d9a0dd5f0d52e8586feb816069b1db5d5e2dbca/Docs/Environment.md#gcm_interactive) environment variable toggles whether or not the interactive prompt will appear when trying to gain credentials.

Disable interactive auth when running background fetch.

See also git-ecosystem/git-credential-manager#90.
  • Loading branch information
derrickstolee authored Jan 23, 2020
2 parents 0da7c43 + 1493bf6 commit 5dffde9
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 5dffde9

Please sign in to comment.