MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / getFixedToolEnvForCopilotMutation

Function getFixedToolEnvForCopilotMutation

src/shared/utils.ts:313–336  ·  view source on GitHub ↗
({ processEnv, toolEnv }: { processEnv: Record<string, string | undefined>; toolEnv: Record<string, string>; })

Source from the content-addressed store, hash-verified

311 * @returns The default toolEnv to use.
312 */
313export 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}

Callers 2

processes.test.tsFile · 0.90
getToolEnvFunction · 0.90

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected