// engine/git/branch-detector.ts — SPEC-467: Detect git branches for branch-aware operations
import { execSync } from 'node:child_process';
/** Detect all local branches in the project. Returns null if not a git repo. */
export function detectBranches(projectPath) {
    try {
        const stdout = execSync('git branch --no-color', {
            cwd: projectPath,
            encoding: 'utf-8',
            stdio: ['pipe', 'pipe', 'pipe'],
        });
        const branches = stdout
            .split('\n')
            .map((b) => b.trim())
            .filter((b) => b.length > 0);
        const current = branches.find((b) => b.startsWith('* '))?.replace('* ', '') ?? 'unknown';
        const all = branches.map((b) => b.replace('* ', ''));
        return { current, all, count: all.length };
    }
    catch {
        return null;
    }
}
/** Generate an InteractiveQuestion asking the user about branch scope. Only returns a question if >1 branch exists. */
export function buildBranchScopeQuestion(branchInfo, operation) {
    if (branchInfo.count <= 1) {
        return null;
    }
    const branchList = branchInfo.all.join(', ');
    return {
        question: `This project has ${String(branchInfo.count)} branches (${branchList}). Where should ${operation} be applied?`,
        header: 'Branches',
        options: [
            {
                label: `Current branch only (Recommended)`,
                description: `Safe — only affects "${branchInfo.current}", the branch you're on right now.`,
            },
            {
                label: 'All branches',
                description: `Apply to all ${String(branchInfo.count)} branches. Each branch will be checked out, updated, and committed independently.`,
            },
        ],
        multiSelect: false,
    };
}
//# sourceMappingURL=branch-detector.js.map