fix(worker): keep Git Credential Manager from prompting during company fetch/push
This commit is contained in:
@@ -56,12 +56,13 @@ public sealed class AzureDevOpsClient
|
||||
public static string AuthHeaderValue(string pat) => "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(":" + pat));
|
||||
|
||||
/// <summary>
|
||||
/// Environment for a git network call: never prompt (a background process would hang), and hand the PAT
|
||||
/// Environment for a git network call: never prompt — neither the terminal nor Git Credential Manager's GUI
|
||||
/// (a background process would hang on either) — and hand the PAT
|
||||
/// over as <c>http.extraHeader</c> via <c>GIT_CONFIG_*</c> so it never shows up in a command line.
|
||||
/// </summary>
|
||||
public static IReadOnlyDictionary<string, string> GitAuthEnv(string? pat)
|
||||
{
|
||||
var env = new Dictionary<string, string> { ["GIT_TERMINAL_PROMPT"] = "0" };
|
||||
var env = new Dictionary<string, string> { ["GIT_TERMINAL_PROMPT"] = "0", ["GCM_INTERACTIVE"] = "never" };
|
||||
if (!string.IsNullOrEmpty(pat))
|
||||
{
|
||||
env["GIT_CONFIG_COUNT"] = "1";
|
||||
|
||||
@@ -61,6 +61,7 @@ public sealed class AzureDevOpsClientTests : IDisposable
|
||||
var env = AzureDevOpsClient.GitAuthEnv("geheim");
|
||||
|
||||
Assert.Equal("0", env["GIT_TERMINAL_PROMPT"]);
|
||||
Assert.Equal("never", env["GCM_INTERACTIVE"]);
|
||||
Assert.Equal("1", env["GIT_CONFIG_COUNT"]);
|
||||
Assert.Equal("http.extraHeader", env["GIT_CONFIG_KEY_0"]);
|
||||
Assert.Equal("Authorization: Basic OmdlaGVpbQ==", env["GIT_CONFIG_VALUE_0"]);
|
||||
|
||||
Reference in New Issue
Block a user