{"record":{"id":"7868e4d620c82f03","repo":"nikivdev/code","slug":"no-branches-available-for-ai-matching","errorCode":null,"errorMessage":"No branches available for AI matching","messagePattern":"No branches available for AI matching","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/branches.rs","lineNumber":90,"sourceCode":"            .first()\n            .map(|(_, entry)| (*entry).clone())\n            .context(\"No match available to switch\")?;\n        println!(\"\\nSwitching to {}...\", best.name);\n        switch_to_entry(&best)?;\n    }\n\n    Ok(())\n}\n\nfn run_ai(opts: BranchAiOpts) -> Result<()> {\n    let query = opts.query.trim().to_string();\n    if query.is_empty() {\n        bail!(\"Query cannot be empty\");\n    }\n\n    let branches = collect_branches(opts.remote)?;\n    if branches.is_empty() {\n        bail!(\"No branches available for AI matching\");\n    }\n\n    let candidates = top_candidates_for_ai(&query, &branches, opts.limit.max(1));\n    let prompt = build_ai_prompt(&query, &candidates);\n    let response =\n        ai_server::quick_prompt(&prompt, opts.model.as_deref(), opts.url.as_deref(), None)?;\n    let cleaned_response = response.trim().trim_matches('`').trim();\n    if cleaned_response.eq_ignore_ascii_case(\"none\") {\n        println!(\"AI selected no matching branch.\");\n        return Ok(());\n    }\n    let selected_name = parse_ai_branch_response(&response, &candidates)\n        .with_context(|| format!(\"Could not parse AI branch response: {}\", response.trim()))?;\n\n    let selected = candidates\n        .iter()\n        .find(|e| e.name == selected_name)\n        .cloned()","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/branches.rs#L72-L108","documentation":"`run_ai` (src/branches.rs:90) collects candidate branches (local or remote) and bails when the list is empty, since there is nothing for the AI to match against. Validation happens before building the prompt and calling `ai_server::quick_prompt`.","triggerScenarios":"`collect_branches(opts.remote)` returns empty — command run outside a git repo, in an empty repo with no commits, or with --remote when no remote refs exist locally.","commonSituations":"Fresh `git init` with no commits; CI checkout with `--depth 1` and no remote refs fetched; wrong working directory in a script.","solutions":["Run the command inside a repository with at least one branch","Fetch remote refs before using --remote: `git fetch --all`","Verify the repo state with `git branch -a`","Omit --remote if you only intend to match local branches"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let out = std::process::Command::new(\"git\").args([\"branch\", \"--list\"]).output()?;\nif String::from_utf8_lossy(&out.stdout).trim().is_empty() {\n    anyhow::bail!(\"no branches in this repo; make a commit or fetch remotes first\");\n}","typeGuard":"fn branches_available(b: &[Branch]) -> bool { !b.is_empty() }","tryCatchPattern":"match run_ai(opts) {\n    Err(e) if e.to_string().contains(\"No branches available for AI matching\") => {\n        eprintln!(\"cd into the repo and/or `git fetch --all`, then retry\");\n    }\n    other => other?,\n}","preventionTips":["Confirm the repo has commits (`git log -1`) before AI matching","Fetch remote refs before using --remote","Set the correct working directory in scripts and CI jobs"],"tags":["git","branches","ai","empty-state"],"backgroundTag":"no-branches-found","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}