mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 22:02:59 -07:00
fix(core): resolve build and lint failures in worktreeService
- Fix incorrect 'fs.promises' usage - Provide missing 'projectRoot' to 'isGeminiWorktree' - Replace 'any' with specific types and type guards to satisfy ESLint - Update tests to match implementation changes
This commit is contained in:
@@ -86,7 +86,7 @@ describe('worktree utilities', () => {
|
||||
|
||||
describe('createWorktree', () => {
|
||||
it('should execute git worktree add with correct branch and path if it does not exist', async () => {
|
||||
vi.mocked(fs.promises.stat).mockRejectedValue({ code: 'ENOENT' } as any);
|
||||
vi.mocked(fs.stat).mockRejectedValue({ code: 'ENOENT' });
|
||||
vi.mocked(execa).mockResolvedValue({ stdout: '' } as never);
|
||||
|
||||
const resultPath = await createWorktree(projectRoot, worktreeName);
|
||||
@@ -100,7 +100,9 @@ describe('worktree utilities', () => {
|
||||
});
|
||||
|
||||
it('should return existing path and not call git if it already exists', async () => {
|
||||
vi.mocked(fs.promises.stat).mockResolvedValue({ isDirectory: () => true } as any);
|
||||
vi.mocked(fs.stat).mockResolvedValue({
|
||||
isDirectory: () => true,
|
||||
} as never);
|
||||
|
||||
const resultPath = await createWorktree(projectRoot, worktreeName);
|
||||
|
||||
@@ -109,7 +111,7 @@ describe('worktree utilities', () => {
|
||||
});
|
||||
|
||||
it('should throw an error if git worktree add fails', async () => {
|
||||
vi.mocked(fs.promises.stat).mockRejectedValue({ code: 'ENOENT' } as any);
|
||||
vi.mocked(fs.stat).mockRejectedValue({ code: 'ENOENT' });
|
||||
vi.mocked(execa).mockRejectedValue(new Error('git failed'));
|
||||
|
||||
await expect(createWorktree(projectRoot, worktreeName)).rejects.toThrow(
|
||||
|
||||
@@ -128,12 +128,19 @@ export async function createWorktree(
|
||||
}
|
||||
|
||||
try {
|
||||
const stats = await fs.promises.stat(worktreePath);
|
||||
if (stats.isDirectory() && await isGeminiWorktree(worktreePath)) {
|
||||
const stats = await fs.stat(worktreePath);
|
||||
if (stats.isDirectory() && isGeminiWorktree(worktreePath, projectRoot)) {
|
||||
return worktreePath;
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.code !== 'ENOENT') throw err;
|
||||
} catch (err: unknown) {
|
||||
if (
|
||||
err &&
|
||||
typeof err === 'object' &&
|
||||
'code' in err &&
|
||||
err.code !== 'ENOENT'
|
||||
) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
const branchName = `worktree-${name}`;
|
||||
|
||||
Reference in New Issue
Block a user