Update packages/core/src/services/worktreeService.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Adib234
2026-05-04 15:47:39 -04:00
committed by GitHub
parent d4bd0e0f61
commit 333344c5f0
+12 -5
View File
@@ -121,12 +121,19 @@ export async function createWorktree(
): Promise<string> {
const worktreePath = getWorktreePath(projectRoot, name);
const worktreesBaseDir = path.join(projectRoot, '.gemini', 'worktrees');
const relative = path.relative(worktreesBaseDir, worktreePath);
if (relative.startsWith('..') || path.isAbsolute(relative)) {
throw new Error('Invalid worktree name');
}
try {
await fs.access(worktreePath);
// Worktree path already exists, reuse it
return worktreePath;
} catch {
// Does not exist, proceed to create
const stats = await fs.promises.stat(worktreePath);
if (stats.isDirectory() && await isGeminiWorktree(worktreePath)) {
return worktreePath;
}
} catch (err) {
if (err.code !== 'ENOENT') throw err;
}
const branchName = `worktree-${name}`;