mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 18:14:29 -07:00
This commit is contained in:
@@ -283,6 +283,25 @@ describe('GitService', () => {
|
||||
expect.stringContaining('checkIsRepo failed'),
|
||||
);
|
||||
});
|
||||
|
||||
it('should configure git environment to use local gitconfig', async () => {
|
||||
hoistedMockCheckIsRepo.mockResolvedValue(false);
|
||||
const service = new GitService(projectRoot, storage);
|
||||
await service.setupShadowGitRepository();
|
||||
|
||||
expect(hoistedMockEnv).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
GIT_CONFIG_GLOBAL: gitConfigPath,
|
||||
GIT_CONFIG_SYSTEM: path.join(repoDir, '.gitconfig_system_empty'),
|
||||
}),
|
||||
);
|
||||
|
||||
const systemConfigContent = await fs.readFile(
|
||||
path.join(repoDir, '.gitconfig_system_empty'),
|
||||
'utf-8',
|
||||
);
|
||||
expect(systemConfigContent).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('createFileSnapshot', () => {
|
||||
|
||||
@@ -51,6 +51,16 @@ export class GitService {
|
||||
}
|
||||
}
|
||||
|
||||
private getShadowRepoEnv(repoDir: string) {
|
||||
const gitConfigPath = path.join(repoDir, '.gitconfig');
|
||||
const systemConfigPath = path.join(repoDir, '.gitconfig_system_empty');
|
||||
return {
|
||||
// Prevent git from using the user's global git config.
|
||||
GIT_CONFIG_GLOBAL: gitConfigPath,
|
||||
GIT_CONFIG_SYSTEM: systemConfigPath,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a hidden git repository in the project root.
|
||||
* The Git repository is used to support checkpointing.
|
||||
@@ -67,7 +77,9 @@ export class GitService {
|
||||
'[user]\n name = Gemini CLI\n email = gemini-cli@google.com\n[commit]\n gpgsign = false\n';
|
||||
await fs.writeFile(gitConfigPath, gitConfigContent);
|
||||
|
||||
const repo = simpleGit(repoDir);
|
||||
const shadowRepoEnv = this.getShadowRepoEnv(repoDir);
|
||||
await fs.writeFile(shadowRepoEnv.GIT_CONFIG_SYSTEM, '');
|
||||
const repo = simpleGit(repoDir).env(shadowRepoEnv);
|
||||
let isRepoDefined = false;
|
||||
try {
|
||||
isRepoDefined = await repo.checkIsRepo(CheckRepoActions.IS_REPO_ROOT);
|
||||
@@ -107,9 +119,7 @@ export class GitService {
|
||||
return simpleGit(this.projectRoot).env({
|
||||
GIT_DIR: path.join(repoDir, '.git'),
|
||||
GIT_WORK_TREE: this.projectRoot,
|
||||
// Prevent git from using the user's global git config.
|
||||
HOME: repoDir,
|
||||
XDG_CONFIG_HOME: repoDir,
|
||||
...this.getShadowRepoEnv(repoDir),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user