{"record":{"id":"8e3f82b058dcce8a","repo":"gitbutlerapp/gitbutler","slug":"repository-has-no-working-directory","errorCode":null,"errorMessage":"Repository has no working directory","messagePattern":"Repository has no working directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/setup.rs","lineNumber":538,"sourceCode":"    if ws.remote_name().is_none()\n        && repo\n            .remote_default_name(gix::remote::Direction::Push)\n            .is_none()\n    {\n        anyhow::bail!(\n            \"Neither found push remote found in workspace nor unambiguously in the Git repository configuration.\"\n        )\n    };\n\n    Ok(true)\n}\n\n/// Creates a 'gb-local' remote pointing to this repository and creates tracking refs for the default branch.\nfn setup_local_remote(repo: &gix::Repository, out: &mut OutputChannel) -> anyhow::Result<String> {\n    let t = theme::get();\n    let repo_url = repo\n        .workdir()\n        .ok_or_else(|| anyhow::anyhow!(\"Repository has no working directory\"))?\n        .to_str()\n        .ok_or_else(|| anyhow::anyhow!(\"Repository path is not valid UTF-8\"))?;\n\n    if let Some(out) = out.for_human() {\n        writeln!(\n            out,\n            \"  {}\",\n            t.info\n                .paint(\"No push remote found, creating gb-local remote...\")\n        )?;\n    }\n\n    edit_repo_config(repo, gix::config::Source::Local, |config| {\n        let mut section = config.section_mut_or_create_new(\"remote\", Some(\"gb-local\".into()))?;\n        section.push(\"url\", repo_url)?;\n        Ok(())\n    })?;\n","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but/src/command/legacy/setup.rs#L520-L556","documentation":"Thrown by `setup_local_remote` when no push remote is configured anywhere, so setup tries to fabricate a `gb-local` remote pointing at the repository itself. The remote URL is derived from `repo.workdir()`; on a bare repository (or a repo opened without a worktree) `workdir()` is None and this error is returned before any config is written.","triggerScenarios":"Running `but setup` in a bare repository (or worktree-less core) that also has no push remote configured in the workspace or git config — the gb-local fallback path is taken and immediately fails on the missing workdir.","commonSituations":"Setting up tooling inside a bare central repo on a server; CI jobs that check out with unusual git dir layouts; a workspace config that lost its remote entries.","solutions":["Run setup from a non-bare working clone of the repository instead","Configure a real push remote before setup so the gb-local fallback is never needed: `git remote add origin <url> && git push -u origin HEAD`","If you must work where you are, create a worktree-style clone next to the bare repo and register that"],"exampleFix":"# before: bare repo, no push remote\ncd /srv/git/project.git && but setup\n\n# after: give it a remote to use\ngit -C /srv/git/project.git remote add origin git@example.com:project.git\nbut setup /srv/git/project.git","handlingStrategy":"validation","validationCode":"let repo = gix::open(&repo_path)?;\nlet Some(workdir) = repo.workdir() else {\n    anyhow::bail!(\"no working directory; configure a push remote or use a non-bare clone\");\n};\nif workdir.to_str().is_none() {\n    anyhow::bail!(\"workdir path is not valid UTF-8; move the repo\");\n}","typeGuard":null,"tryCatchPattern":"match setup_local_remote(&repo, &mut out) {\n    Ok(remote) => { /* use remote */ }\n    Err(err) if err.to_string().contains(\"no working directory\") => {\n        // add a real push remote instead of the gb-local fallback\n    }\n    Err(err) => return Err(err),\n}","preventionTips":["Configure origin (and a pushurl) before running setup so gb-local is never needed","Always run setup from a non-bare working clone","Check `git rev-parse --is-bare-repository` in provisioning scripts"],"tags":["rust","cli","setup","git","bare-repository","git-remote"],"backgroundTag":"git-bare-repository","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}