{"record":{"id":"53f8b73a85a59d00","repo":"gitbutlerapp/gitbutler","slug":"failed-to-discover-gitbutler-branch-with-but-js","errorCode":null,"errorMessage":"failed to discover GitButler branch with 'but --json status': {stderr}","messagePattern":"failed to discover GitButler branch with 'but --json status': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-agentlog/src/skim.rs","lineNumber":355,"sourceCode":"}\n\n#[derive(Deserialize)]\nstruct StatusBranch {\n    name: String,\n}\n\nfn applied_gitbutler_branch(workdir: &Path) -> anyhow::Result<String> {\n    let but_path = std::env::current_exe().context(\"failed to locate current executable\")?;\n    let output = ProcessCommand::new(&but_path)\n        .arg(\"-C\")\n        .arg(workdir)\n        .args([\"--json\", \"status\"])\n        .stdin(Stdio::null())\n        .output()\n        .context(\"failed to run 'but --json status' for agentlog skim target discovery\")?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"failed to discover GitButler branch with 'but --json status': {stderr}\");\n    }\n    let status: StatusReport =\n        serde_json::from_slice(&output.stdout).context(\"failed to parse 'but --json status'\")?;\n    status\n        .stacks\n        .into_iter()\n        .flat_map(|stack| stack.branches)\n        .map(|branch| branch.name)\n        .next()\n        .context(\"no applied GitButler branch found; pass an explicit skim target\")\n}\n","sourceCodeStart":337,"sourceCodeEnd":367,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/2497b8007aa4a1922dae9a805b32ffe5b5037785/crates/but-agentlog/src/skim.rs#L337-L367","documentation":"When `but agentlog skim` runs with no explicit target, it re-executes itself as `but --json status` in the workdir (current_exe -C <dir> --json status) to find the first applied GitButler branch. If that subprocess exits non-zero, this error embeds its stderr — typical causes are the workdir not being a GitButler workspace, no target/base branch configured, or an older binary without --json status support.","triggerScenarios":"skim::resolve_default_branch_target -> applied_gitbutler_branch: the spawned `but --json status` fails. Happens when -C <dir> is outside any GitButler-managed repo, the project has no target branch or applied stacks, status itself errors (auth, corrupt repo), or current_exe is an old build.","commonSituations":"Running skim in a plain git clone; pointing --dir at the wrong folder; PATH resolution landing on a stale but binary; workspaces discarded from the project.","solutions":["Pass an explicit target so discovery is skipped: but agentlog skim branch <name>.","Run `but --json status` manually in the same directory and fix whatever it reports (set a target branch, reopen the workspace).","Ensure the executing binary (std::env::current_exe) is a recent but/tauri build that supports --json status.","Verify the workdir is inside the GitButler project you intended."],"exampleFix":"# before\nbut agentlog skim\n# after (skip auto-discovery)\nbut agentlog skim branch feat/auth","handlingStrategy":"fallback","validationCode":"use std::process::Command as Pc;\n\nfn skim_discovery_will_succeed(dir: &std::path::Path) -> bool {\n    Pc::new(std::env::current_exe().unwrap())\n        .arg(\"-C\").arg(dir)\n        .args([\"--json\", \"status\"])\n        .output()\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match skim::resolve_default_branch_target(&repo_path) {\n    Err(_) => skim_with_explicit_branch(\"main\"), // skip auto-discovery entirely\n    ok => ok?,\n}","preventionTips":["Prefer explicit skim targets in scripts and CI.","Keep the but binary current so --json status is supported.","Confirm `but status` succeeds in the workdir before relying on auto-discovery."],"tags":["agentlog","skim","subprocess","workspace-detection","gitbutler-status"],"backgroundTag":"external-command-failed","analyzedSha":"2497b8007aa4a1922dae9a805b32ffe5b5037785","analyzedAt":"2026-08-17T00:30:25.648Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}