fix(worktree): disable destructive orphaned-worktree removal by default
This commit is contained in:
@@ -49,8 +49,8 @@ describe('pruneOrphanedWorktrees', () => {
|
||||
cleanup(tmpBase);
|
||||
});
|
||||
|
||||
// Test 1: removes a worktree whose branch is merged into main
|
||||
test('removes a worktree whose branch is merged into main', () => {
|
||||
// Test 1: keeps a merged worktree (destructive removal disabled by default)
|
||||
test('keeps a worktree whose branch is merged into main', () => {
|
||||
const repoDir = path.join(tmpBase, 'repo');
|
||||
const worktreeDir = path.join(tmpBase, 'wt-merged');
|
||||
|
||||
@@ -72,17 +72,17 @@ describe('pruneOrphanedWorktrees', () => {
|
||||
const pruneOrphanedWorktrees = getPruneOrphanedWorktrees();
|
||||
pruneOrphanedWorktrees(repoDir);
|
||||
|
||||
// Assert: worktree directory no longer exists
|
||||
// Assert: worktree directory still exists
|
||||
assert.ok(
|
||||
!fs.existsSync(worktreeDir),
|
||||
'worktree directory should have been removed but still exists: ' + worktreeDir
|
||||
fs.existsSync(worktreeDir),
|
||||
'merged worktree should not be removed by default: ' + worktreeDir
|
||||
);
|
||||
|
||||
// Assert: git worktree list no longer shows it
|
||||
// Assert: git worktree list still shows it
|
||||
const listOut = execSync('git worktree list', { cwd: repoDir, encoding: 'utf8' });
|
||||
assert.ok(
|
||||
!listOut.includes(worktreeDir),
|
||||
'git worktree list still references removed worktree:\n' + listOut
|
||||
listOut.includes(worktreeDir),
|
||||
'git worktree list should still reference merged worktree:\n' + listOut
|
||||
);
|
||||
});
|
||||
|
||||
@@ -132,11 +132,8 @@ describe('pruneOrphanedWorktrees', () => {
|
||||
const pruneOrphanedWorktrees = getPruneOrphanedWorktrees();
|
||||
const pruned = pruneOrphanedWorktrees(repoDir);
|
||||
|
||||
// process.cwd() must not appear in pruned paths
|
||||
assert.ok(
|
||||
!pruned.includes(process.cwd()),
|
||||
'process.cwd() should never be pruned, but found in: ' + JSON.stringify(pruned)
|
||||
);
|
||||
// No destructive removals are performed by default
|
||||
assert.deepStrictEqual(pruned, []);
|
||||
|
||||
// The main worktree (repoDir) itself must still exist
|
||||
assert.ok(
|
||||
|
||||
Reference in New Issue
Block a user