{"record":{"id":"ffc8a25bfb110ba4","repo":"gitbutlerapp/gitbutler","slug":"not-currently-on-a-gitbutler-branch","errorCode":null,"errorMessage":"Not currently on a gitbutler/* branch.","messagePattern":"Not currently on a gitbutler/\\* branch\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/setup.rs","lineNumber":553,"sourceCode":"/// If so, returns true\n/// Otherwise, returns an error with a message indicating what is not setup.\n/// It will check:\n/// - if the repository exists\n/// - if the project is registered in GitButler\n/// - if there is a remote\n/// - if there is a default target branch set\n/// - if we're on a gitbutler/* branch\npub fn check_project_setup(ctx: &Context, perm: &RepoShared) -> anyhow::Result<bool> {\n    let (repo, ws, _) = ctx.workspace_and_db_with_perm(perm)?;\n\n    // check if we're on a gitbutler/* branch\n    let head = repo.head()?;\n    let head_name = head\n        .referent_name()\n        .map(|n| n.shorten().to_owned())\n        .unwrap_or_default();\n    if !head_name.starts_with(b\"gitbutler/\") {\n        anyhow::bail!(\"Not currently on a gitbutler/* branch.\");\n    }\n\n    // When on gitbutler/edit, the project was already set up when entering edit mode.\n    // The workspace graph built from gitbutler/edit doesn't expose the target ref or\n    // remote configuration, but both are still configured in virtual_branches.toml\n    // and will be accessible when returning to gitbutler/workspace.\n    if head_name == b\"gitbutler/edit\" {\n        return Ok(true);\n    }\n\n    // TODO(legacy): it's fine to have no target.\n    if ws.graph.project_meta.target_ref.is_none() {\n        anyhow::bail!(\"No default target branch set.\");\n    }\n\n    // check if there is a remote\n    if ws.push_remote_name().is_none()\n        && repo","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/setup.rs#L535-L571","documentation":"`check_project_setup` in the legacy `but` CLI setup path verifies the repository HEAD points at a `gitbutler/*` branch before initializing a context. If HEAD's short name does not start with `gitbutler/`, the setup aborts because the legacy workspace machinery only operates in GitButler-managed states. This is a precondition check, not a Git failure.","triggerScenarios":"Calling `init_ctx`/`check_project_setup` while HEAD is on a normal branch (e.g. `main`), a detached HEAD with a non-gitbutler referent, or any state where the user has left the GitButler workspace (e.g. via `but legacy abandon` or plain `git switch main`).","commonSituations":"Running `but` legacy commands after switching branches with plain git; a teammate cloned a repo without the virtual-branches state; GitButler was exited/paused for the project; automation invoking `but` in a plain git checkout.","solutions":["Switch the repository back to the GitButler workspace branch (`git switch gitbutler/workspace`, or `gitbutler/edit` when editing) or re-enter GitButler mode for the project (`but` app or the setup command that creates the workspace).","Verify HEAD: `git symbolic-ref --short HEAD` must start with `gitbutler/`.","If the project should no longer use GitButler, do not call this legacy setup path; use non-legacy workflows."],"exampleFix":"// before (plain git checkout)\n$ but status\nError: Not currently on a gitbutler/* branch.\n// after\n$ git switch gitbutler/workspace\n$ but status","handlingStrategy":"validation","validationCode":"let head_name = std::fs::read_to_string(\".git/HEAD\").ok()\n    .map(|h| h.trim().trim_start_matches(\"ref: \").to_string())\n    .unwrap_or_default();\nif !head_name.starts_with(\"gitbutler/\") {\n    eprintln!(\"not in gitbutler mode (HEAD={head_name}); re-enter the workspace first\");\n    std::process::exit(1);\n}","typeGuard":"fn is_gitbutler_head(head_name: &str) -> bool {\n    head_name.starts_with(\"gitbutler/\")\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"Not currently on a gitbutler/* branch\") => {\n        // prompt user to re-enter the GitButler workspace\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Check `git symbolic-ref --short HEAD` before invoking `but` legacy commands","Do not plain-`git switch` away from `gitbutler/*` while using the CLI","Automate re-entering the workspace in CI before running `but`"],"tags":["git","cli","precondition","workspace-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}