{"record":{"id":"6f8e8c56ae9179c9","repo":"gitbutlerapp/gitbutler","slug":"repository-has-no-workdir","errorCode":null,"errorMessage":"Repository has no workdir","messagePattern":"Repository has no workdir","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/teardown.rs","lineNumber":200,"sourceCode":"            }\n        }\n    }\n\n    // Check out the target branch using Git directly\n    if let Some(out) = out.for_human() {\n        writeln!(\n            out,\n            \"{}\",\n            t.hint\n                .paint(format!(\"→ Checking out {target_branch_name}...\"))\n        )?;\n    }\n\n    // Use git checkout via command\n    let repo = ctx.repo.get()?;\n    let workdir = repo\n        .workdir()\n        .ok_or_else(|| anyhow::anyhow!(\"Repository has no workdir\"))?;\n\n    let output = std::process::Command::new(gix::path::env::exe_invocation())\n        .arg(\"-C\")\n        .arg(workdir)\n        .arg(\"checkout\")\n        .arg(&target_branch_name)\n        .output()\n        .context(\"Failed to execute git checkout\")?;\n\n    if !output.status.success() {\n        // Checkout failed (likely due to local changes), try soft reset instead\n        if let Some(out) = out.for_human() {\n            writeln!(\n                out,\n                \"  {}\",\n                t.attention.paint(\"⚠ Checkout failed, trying soft reset...\\n  ⚠ This will leave changes from multiple branches in your working directory.\\n  ⚠ You will have to manually remove, stash or re-commit the changes.\")\n            )?;\n        }","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/teardown.rs#L182-L218","documentation":"The teardown command shells out to the real `git checkout` binary, which requires a working directory to operate in. `git2::Repository::workdir()` returns `None` for bare repositories, so this error is thrown because a bare repo cannot have branches checked out.","triggerScenarios":"Running `but teardown` (with a target branch to check out) inside a bare repository, or when the repository handle resolves to a bare repo object (e.g., pointing at `.git` directly).","commonSituations":"Executing the CLI with the repo root set to a bare clone (servers, CI check-out-less clones); misconfigured context where `ctx.repo.get()` yields a bare repository instead of a working tree.","solutions":["Run `but teardown` from a non-bare clone that has a working tree.","If the target is a bare repo, clone it to a working copy first and run teardown there.","Verify repo configuration: `git rev-parse --is-bare-repository` should return false."],"exampleFix":"// before\ngit clone --bare https://example.com/repo.git && cd repo.git && but teardown\n\n// after\ngit clone https://example.com/repo.git && cd repo && but teardown","handlingStrategy":"validation","validationCode":"let repo = ctx.repo.get()?;\nif repo.is_bare() {\n    anyhow::bail!(\"teardown requires a non-bare repository with a working tree\");\n}","typeGuard":"fn has_workdir(repo: &gix::Repository) -> bool { repo.workdir().is_some() }","tryCatchPattern":"match teardown(ctx, args) {\n    Err(e) if e.to_string().contains(\"Repository has no workdir\") =>\n        eprintln!(\"Run this in a non-bare clone\"),\n    other => other?,\n}","preventionTips":["Check `git rev-parse --is-bare-repository` in setup scripts before invoking the CLI.","Never run the CLI directly inside bare server repos; clone first.","Ensure ctx.repo points at the worktree, not the `.git` dir."],"tags":["git","bare-repository","workdir"],"backgroundTag":"unsupported-operation","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"}