import { deriveWorktreePath } from '../../../modules/worktree-management/entities/worktree/worktree.js';
export async function removeWorktree(input, deps) {
    const targetPath = deriveWorktreePath(input.identity);
    const isForced = input.force === true;
    await deps.executor.execute({
        kind: 'worktree-prune',
        args: ['worktree', 'prune'],
        cwd: input.sourceCheckoutPath,
    });
    const exists = await deps.worktreeExists(targetPath);
    if (!exists) {
        return isForced ? { status: 'removed' } : { status: 'absent' };
    }
    const removeResult = await deps.executor.execute({
        kind: 'worktree-remove',
        args: ['worktree', 'remove', '--force', targetPath],
        cwd: input.sourceCheckoutPath,
    });
    if (removeResult.exitCode !== 0) {
        return {
            status: 'failed',
            warning: removeResult.stderr || 'git worktree remove failed',
        };
    }
    return { status: 'removed' };
}
//# sourceMappingURL=removeWorktree.usecase.js.map