mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-25 20:44:46 -07:00
fix(core): safely append GIT_CONFIG overrides without breaking user config
This commit is contained in:
@@ -1704,8 +1704,14 @@ describe('ShellExecutionService environment variables', () => {
|
|||||||
await new Promise(process.nextTick);
|
await new Promise(process.nextTick);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should include headless git and gh environment variables in non-interactive mode', async () => {
|
it('should include headless git and gh environment variables in non-interactive mode and append git config safely', async () => {
|
||||||
vi.resetModules();
|
vi.resetModules();
|
||||||
|
vi.stubEnv('GIT_CONFIG_COUNT', '2');
|
||||||
|
vi.stubEnv('GIT_CONFIG_KEY_0', 'core.editor');
|
||||||
|
vi.stubEnv('GIT_CONFIG_VALUE_0', 'vim');
|
||||||
|
vi.stubEnv('GIT_CONFIG_KEY_1', 'pull.rebase');
|
||||||
|
vi.stubEnv('GIT_CONFIG_VALUE_1', 'true');
|
||||||
|
|
||||||
const { ShellExecutionService } = await import(
|
const { ShellExecutionService } = await import(
|
||||||
'./shellExecutionService.js'
|
'./shellExecutionService.js'
|
||||||
);
|
);
|
||||||
@@ -1729,13 +1735,23 @@ describe('ShellExecutionService environment variables', () => {
|
|||||||
expect(cpEnv).toHaveProperty('GCM_INTERACTIVE', 'never');
|
expect(cpEnv).toHaveProperty('GCM_INTERACTIVE', 'never');
|
||||||
expect(cpEnv).toHaveProperty('DISPLAY', '');
|
expect(cpEnv).toHaveProperty('DISPLAY', '');
|
||||||
expect(cpEnv).toHaveProperty('DBUS_SESSION_BUS_ADDRESS', '');
|
expect(cpEnv).toHaveProperty('DBUS_SESSION_BUS_ADDRESS', '');
|
||||||
expect(cpEnv).toHaveProperty('GIT_CONFIG_COUNT', '1');
|
|
||||||
expect(cpEnv).toHaveProperty('GIT_CONFIG_KEY_0', 'credential.helper');
|
// Existing values should be preserved
|
||||||
expect(cpEnv).toHaveProperty('GIT_CONFIG_VALUE_0', '');
|
expect(cpEnv).toHaveProperty('GIT_CONFIG_KEY_0', 'core.editor');
|
||||||
|
expect(cpEnv).toHaveProperty('GIT_CONFIG_VALUE_0', 'vim');
|
||||||
|
expect(cpEnv).toHaveProperty('GIT_CONFIG_KEY_1', 'pull.rebase');
|
||||||
|
expect(cpEnv).toHaveProperty('GIT_CONFIG_VALUE_1', 'true');
|
||||||
|
|
||||||
|
// The new credential.helper override should be appended at index 2
|
||||||
|
expect(cpEnv).toHaveProperty('GIT_CONFIG_COUNT', '3');
|
||||||
|
expect(cpEnv).toHaveProperty('GIT_CONFIG_KEY_2', 'credential.helper');
|
||||||
|
expect(cpEnv).toHaveProperty('GIT_CONFIG_VALUE_2', '');
|
||||||
|
|
||||||
// Ensure child_process exits
|
// Ensure child_process exits
|
||||||
mockChildProcess.emit('exit', 0, null);
|
mockChildProcess.emit('exit', 0, null);
|
||||||
mockChildProcess.emit('close', 0, null);
|
mockChildProcess.emit('close', 0, null);
|
||||||
await new Promise(process.nextTick);
|
await new Promise(process.nextTick);
|
||||||
|
|
||||||
|
vi.unstubAllEnvs();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -305,6 +305,12 @@ export class ShellExecutionService {
|
|||||||
const guardedCommand = ensurePromptvarsDisabled(commandToExecute, shell);
|
const guardedCommand = ensurePromptvarsDisabled(commandToExecute, shell);
|
||||||
const spawnArgs = [...argsPrefix, guardedCommand];
|
const spawnArgs = [...argsPrefix, guardedCommand];
|
||||||
|
|
||||||
|
const sanitizedEnv = sanitizeEnvironment(process.env, sanitizationConfig);
|
||||||
|
const gitConfigCount = parseInt(
|
||||||
|
sanitizedEnv['GIT_CONFIG_COUNT'] || '0',
|
||||||
|
10,
|
||||||
|
);
|
||||||
|
|
||||||
const child = cpSpawn(executable, spawnArgs, {
|
const child = cpSpawn(executable, spawnArgs, {
|
||||||
cwd,
|
cwd,
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
@@ -312,7 +318,7 @@ export class ShellExecutionService {
|
|||||||
shell: false,
|
shell: false,
|
||||||
detached: !isWindows,
|
detached: !isWindows,
|
||||||
env: {
|
env: {
|
||||||
...sanitizeEnvironment(process.env, sanitizationConfig),
|
...sanitizedEnv,
|
||||||
[GEMINI_CLI_IDENTIFICATION_ENV_VAR]:
|
[GEMINI_CLI_IDENTIFICATION_ENV_VAR]:
|
||||||
GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE,
|
GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE,
|
||||||
TERM: 'xterm-256color',
|
TERM: 'xterm-256color',
|
||||||
@@ -325,9 +331,9 @@ export class ShellExecutionService {
|
|||||||
GCM_INTERACTIVE: 'never',
|
GCM_INTERACTIVE: 'never',
|
||||||
DISPLAY: '',
|
DISPLAY: '',
|
||||||
DBUS_SESSION_BUS_ADDRESS: '',
|
DBUS_SESSION_BUS_ADDRESS: '',
|
||||||
GIT_CONFIG_COUNT: '1',
|
GIT_CONFIG_COUNT: (gitConfigCount + 1).toString(),
|
||||||
GIT_CONFIG_KEY_0: 'credential.helper',
|
[`GIT_CONFIG_KEY_${gitConfigCount}`]: 'credential.helper',
|
||||||
GIT_CONFIG_VALUE_0: '',
|
[`GIT_CONFIG_VALUE_${gitConfigCount}`]: '',
|
||||||
PAGER: 'cat',
|
PAGER: 'cat',
|
||||||
GIT_PAGER: 'cat',
|
GIT_PAGER: 'cat',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user