From 408f8b0184c8ce327ec1b589c54b699ed595141c Mon Sep 17 00:00:00 2001 From: nrslib <38722970+nrslib@users.noreply.github.com> Date: Thu, 29 Jan 2026 12:08:47 +0900 Subject: [PATCH] =?UTF-8?q?git=20clone=20--shared=20=E2=86=92=20--referenc?= =?UTF-8?q?e=20--dissociate=20=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --shared は objects/info/alternates で元リポジトリへの参照を残すが、 --dissociate はオブジェクトをコピーして完全独立なクローンを作る。 --- src/task/worktree.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/task/worktree.ts b/src/task/worktree.ts index ef2b648..ce39595 100644 --- a/src/task/worktree.ts +++ b/src/task/worktree.ts @@ -1,10 +1,10 @@ /** - * Git shared clone management + * Git clone management * - * Creates and removes git shared clones for task isolation. - * Uses `git clone --shared` instead of worktrees so each clone - * has an independent .git directory, preventing Claude Code from - * traversing gitdir back to the main repository. + * Creates and removes git clones for task isolation. + * Uses `git clone --reference --dissociate` instead of worktrees so + * each clone has a fully independent .git directory with no alternates + * link, preventing Claude Code from traversing back to the main repository. */ import * as fs from 'node:fs'; @@ -131,8 +131,8 @@ export function createSharedClone(projectDir: string, options: WorktreeOptions): // Ensure parent directory exists fs.mkdirSync(path.dirname(clonePath), { recursive: true }); - // Create shared clone - execFileSync('git', ['clone', '--shared', projectDir, clonePath], { + // Create independent clone (--reference + --dissociate = no alternates link back) + execFileSync('git', ['clone', '--reference', projectDir, '--dissociate', projectDir, clonePath], { cwd: projectDir, stdio: 'pipe', }); @@ -150,7 +150,7 @@ export function createSharedClone(projectDir: string, options: WorktreeOptions): }); } - log.info('Shared clone created', { path: clonePath, branch }); + log.info('Clone created', { path: clonePath, branch }); return { path: clonePath, branch }; } @@ -180,7 +180,7 @@ export function createTempCloneForBranch(projectDir: string, branch: string): Wo fs.mkdirSync(path.dirname(clonePath), { recursive: true }); - execFileSync('git', ['clone', '--shared', projectDir, clonePath], { + execFileSync('git', ['clone', '--reference', projectDir, '--dissociate', projectDir, clonePath], { cwd: projectDir, stdio: 'pipe', });