git clone --shared → --reference --dissociate に変更

--shared は objects/info/alternates で元リポジトリへの参照を残すが、
--dissociate はオブジェクトをコピーして完全独立なクローンを作る。
This commit is contained in:
nrslib 2026-01-29 12:08:47 +09:00
parent ea0d04c4fe
commit 408f8b0184

View File

@ -1,10 +1,10 @@
/** /**
* Git shared clone management * Git clone management
* *
* Creates and removes git shared clones for task isolation. * Creates and removes git clones for task isolation.
* Uses `git clone --shared` instead of worktrees so each clone * Uses `git clone --reference --dissociate` instead of worktrees so
* has an independent .git directory, preventing Claude Code from * each clone has a fully independent .git directory with no alternates
* traversing gitdir back to the main repository. * link, preventing Claude Code from traversing back to the main repository.
*/ */
import * as fs from 'node:fs'; import * as fs from 'node:fs';
@ -131,8 +131,8 @@ export function createSharedClone(projectDir: string, options: WorktreeOptions):
// Ensure parent directory exists // Ensure parent directory exists
fs.mkdirSync(path.dirname(clonePath), { recursive: true }); fs.mkdirSync(path.dirname(clonePath), { recursive: true });
// Create shared clone // Create independent clone (--reference + --dissociate = no alternates link back)
execFileSync('git', ['clone', '--shared', projectDir, clonePath], { execFileSync('git', ['clone', '--reference', projectDir, '--dissociate', projectDir, clonePath], {
cwd: projectDir, cwd: projectDir,
stdio: 'pipe', 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 }; return { path: clonePath, branch };
} }
@ -180,7 +180,7 @@ export function createTempCloneForBranch(projectDir: string, branch: string): Wo
fs.mkdirSync(path.dirname(clonePath), { recursive: true }); fs.mkdirSync(path.dirname(clonePath), { recursive: true });
execFileSync('git', ['clone', '--shared', projectDir, clonePath], { execFileSync('git', ['clone', '--reference', projectDir, '--dissociate', projectDir, clonePath], {
cwd: projectDir, cwd: projectDir,
stdio: 'pipe', stdio: 'pipe',
}); });