fix(worker): keep Git Credential Manager from prompting during company fetch/push

This commit is contained in:
mika kuns
2026-10-01 12:18:06 +02:00
parent 0e6a48e268
commit 674db27f6e
2 changed files with 4 additions and 2 deletions
@@ -56,12 +56,13 @@ public sealed class AzureDevOpsClient
public static string AuthHeaderValue(string pat) => "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(":" + pat)); public static string AuthHeaderValue(string pat) => "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(":" + pat));
/// <summary> /// <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. /// over as <c>http.extraHeader</c> via <c>GIT_CONFIG_*</c> so it never shows up in a command line.
/// </summary> /// </summary>
public static IReadOnlyDictionary<string, string> GitAuthEnv(string? pat) 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)) if (!string.IsNullOrEmpty(pat))
{ {
env["GIT_CONFIG_COUNT"] = "1"; env["GIT_CONFIG_COUNT"] = "1";
@@ -61,6 +61,7 @@ public sealed class AzureDevOpsClientTests : IDisposable
var env = AzureDevOpsClient.GitAuthEnv("geheim"); var env = AzureDevOpsClient.GitAuthEnv("geheim");
Assert.Equal("0", env["GIT_TERMINAL_PROMPT"]); Assert.Equal("0", env["GIT_TERMINAL_PROMPT"]);
Assert.Equal("never", env["GCM_INTERACTIVE"]);
Assert.Equal("1", env["GIT_CONFIG_COUNT"]); Assert.Equal("1", env["GIT_CONFIG_COUNT"]);
Assert.Equal("http.extraHeader", env["GIT_CONFIG_KEY_0"]); Assert.Equal("http.extraHeader", env["GIT_CONFIG_KEY_0"]);
Assert.Equal("Authorization: Basic OmdlaGVpbQ==", env["GIT_CONFIG_VALUE_0"]); Assert.Equal("Authorization: Basic OmdlaGVpbQ==", env["GIT_CONFIG_VALUE_0"]);