({ processEnv, toolEnv }: { processEnv: Record<string, string | undefined>; toolEnv: Record<string, string>; })
| 311 | * @returns The default toolEnv to use. |
| 312 | */ |
| 313 | export function getFixedToolEnvForCopilotMutation({ processEnv, toolEnv }: { processEnv: Record<string, string | undefined>; toolEnv: Record<string, string>; }): Record<string, string> { |
| 314 | // Workaround GitHub Copilot mutating the extension host processes env variables |
| 315 | // to include safe.bareRepository=explicit which breaks Swift PM. |
| 316 | // |
| 317 | // If the last config added was safe.bareRepository=explicit, then reduce the count to remove it. |
| 318 | |
| 319 | const newToolEnv = Object.assign({}, toolEnv); |
| 320 | const configCountEnvVarValue = processEnv.GIT_CONFIG_COUNT; |
| 321 | // Has a value? |
| 322 | if (typeof configCountEnvVarValue === "string") { |
| 323 | const configCount = parseInt(configCountEnvVarValue, 10); |
| 324 | // Is numeric? |
| 325 | if (Number.isInteger(configCount)) { |
| 326 | const lastConfigIndex = configCount - 1; |
| 327 | // Last setting is the one we're trying to eliminate? |
| 328 | if (processEnv[`GIT_CONFIG_KEY_${lastConfigIndex}`] === "safe.bareRepository" |
| 329 | && processEnv[`GIT_CONFIG_VALUE_${lastConfigIndex}`] === "explicit") |
| 330 | // Wind back the count to exclude it. |
| 331 | newToolEnv.GIT_CONFIG_COUNT = (configCount - 1).toString(); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | return newToolEnv; |
| 336 | } |
no test coverage detected