mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-12 22:31:12 -07:00
fix(core): add explicit git identity env vars to prevent sandbox checkpointing error (#19775)
Co-authored-by: David Pierce <davidapierce@google.com>
This commit is contained in:
committed by
GitHub
parent
b238a453e3
commit
5bcb6b619d
@@ -13,7 +13,11 @@ import {
|
||||
afterEach,
|
||||
type Mock,
|
||||
} from 'vitest';
|
||||
import { GitService } from './gitService.js';
|
||||
import {
|
||||
GitService,
|
||||
SHADOW_REPO_AUTHOR_NAME,
|
||||
SHADOW_REPO_AUTHOR_EMAIL,
|
||||
} from './gitService.js';
|
||||
import { Storage } from '../config/storage.js';
|
||||
import * as path from 'node:path';
|
||||
import * as fs from 'node:fs/promises';
|
||||
@@ -192,8 +196,7 @@ describe('GitService', () => {
|
||||
const service = new GitService(projectRoot, storage);
|
||||
await service.setupShadowGitRepository();
|
||||
|
||||
const expectedConfigContent =
|
||||
'[user]\n name = Gemini CLI\n email = gemini-cli@google.com\n[commit]\n gpgsign = false\n';
|
||||
const expectedConfigContent = `[user]\n name = ${SHADOW_REPO_AUTHOR_NAME}\n email = ${SHADOW_REPO_AUTHOR_EMAIL}\n[commit]\n gpgsign = false\n`;
|
||||
const actualConfigContent = await fs.readFile(gitConfigPath, 'utf-8');
|
||||
expect(actualConfigContent).toBe(expectedConfigContent);
|
||||
});
|
||||
@@ -288,6 +291,10 @@ describe('GitService', () => {
|
||||
expect.objectContaining({
|
||||
GIT_CONFIG_GLOBAL: gitConfigPath,
|
||||
GIT_CONFIG_SYSTEM: path.join(repoDir, '.gitconfig_system_empty'),
|
||||
GIT_AUTHOR_NAME: SHADOW_REPO_AUTHOR_NAME,
|
||||
GIT_AUTHOR_EMAIL: SHADOW_REPO_AUTHOR_EMAIL,
|
||||
GIT_COMMITTER_NAME: SHADOW_REPO_AUTHOR_NAME,
|
||||
GIT_COMMITTER_EMAIL: SHADOW_REPO_AUTHOR_EMAIL,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ import { simpleGit, CheckRepoActions, type SimpleGit } from 'simple-git';
|
||||
import type { Storage } from '../config/storage.js';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
|
||||
export const SHADOW_REPO_AUTHOR_NAME = 'Gemini CLI';
|
||||
export const SHADOW_REPO_AUTHOR_EMAIL = 'gemini-cli@google.com';
|
||||
|
||||
export class GitService {
|
||||
private projectRoot: string;
|
||||
private storage: Storage;
|
||||
@@ -58,6 +61,13 @@ export class GitService {
|
||||
// Prevent git from using the user's global git config.
|
||||
GIT_CONFIG_GLOBAL: gitConfigPath,
|
||||
GIT_CONFIG_SYSTEM: systemConfigPath,
|
||||
// Explicitly provide identity to prevent "Author identity unknown" errors
|
||||
// inside sandboxed environments like Docker where the gitconfig might not
|
||||
// be picked up properly.
|
||||
GIT_AUTHOR_NAME: SHADOW_REPO_AUTHOR_NAME,
|
||||
GIT_AUTHOR_EMAIL: SHADOW_REPO_AUTHOR_EMAIL,
|
||||
GIT_COMMITTER_NAME: SHADOW_REPO_AUTHOR_NAME,
|
||||
GIT_COMMITTER_EMAIL: SHADOW_REPO_AUTHOR_EMAIL,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,8 +83,7 @@ export class GitService {
|
||||
|
||||
// We don't want to inherit the user's name, email, or gpg signing
|
||||
// preferences for the shadow repository, so we create a dedicated gitconfig.
|
||||
const gitConfigContent =
|
||||
'[user]\n name = Gemini CLI\n email = gemini-cli@google.com\n[commit]\n gpgsign = false\n';
|
||||
const gitConfigContent = `[user]\n name = ${SHADOW_REPO_AUTHOR_NAME}\n email = ${SHADOW_REPO_AUTHOR_EMAIL}\n[commit]\n gpgsign = false\n`;
|
||||
await fs.writeFile(gitConfigPath, gitConfigContent);
|
||||
|
||||
const shadowRepoEnv = this.getShadowRepoEnv(repoDir);
|
||||
|
||||
Reference in New Issue
Block a user