gitbutlerapp/gitbutler · error
failed to discover GitButler branch with 'but --json status'
Error message
failed to discover GitButler branch with 'but --json status': {stderr} What it means
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.
Source
Thrown at crates/but-agentlog/src/skim.rs:355
}
#[derive(Deserialize)]
struct StatusBranch {
name: String,
}
fn applied_gitbutler_branch(workdir: &Path) -> anyhow::Result<String> {
let but_path = std::env::current_exe().context("failed to locate current executable")?;
let output = ProcessCommand::new(&but_path)
.arg("-C")
.arg(workdir)
.args(["--json", "status"])
.stdin(Stdio::null())
.output()
.context("failed to run 'but --json status' for agentlog skim target discovery")?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
anyhow::bail!("failed to discover GitButler branch with 'but --json status': {stderr}");
}
let status: StatusReport =
serde_json::from_slice(&output.stdout).context("failed to parse 'but --json status'")?;
status
.stacks
.into_iter()
.flat_map(|stack| stack.branches)
.map(|branch| branch.name)
.next()
.context("no applied GitButler branch found; pass an explicit skim target")
}
View on GitHub (pinned to 2497b8007a)
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.
Example fix
# before but agentlog skim # after (skip auto-discovery) but agentlog skim branch feat/auth
Defensive patterns
Strategy: fallback
Validate before calling
use std::process::Command as Pc;
fn skim_discovery_will_succeed(dir: &std::path::Path) -> bool {
Pc::new(std::env::current_exe().unwrap())
.arg("-C").arg(dir)
.args(["--json", "status"])
.output()
.map(|o| o.status.success())
.unwrap_or(false)
} Try / catch
match skim::resolve_default_branch_target(&repo_path) {
Err(_) => skim_with_explicit_branch("main"), // skip auto-discovery entirely
ok => ok?,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- {} target value is required
- target kind is required when target value is provided
- unknown publish target '{other}'. Use `but agentlog publish
AI-assisted analysis of gitbutlerapp/gitbutler@2497b8007a (2026-08-17).
Data as JSON: /api/errors/53f8b73a85a59d00.
Report an issue: GitHub.