gitbutlerapp/gitbutler · error

no workdir found for repository

Error message

no workdir found for repository

What it means

try_project maps AddProjectOutcome::NoWorkdir to this error. A repository was found at the path, but git reports no working directory (workdir) for it, so GitButler cannot operate on checked-out files. This typically coincides with bare or oddly configured repositories.

Solutions

  1. Re-clone the repository into a fresh working directory and add that instead.
  2. Inspect `.git/config`: ensure `bare = false` and `core.worktree` is unset or correct for a normal clone.
  3. Verify with `git -C <path> rev-parse --show-toplevel` that a toplevel exists before adding.
  4. Restore .git/config from a backup if it was manually modified.

Example fix

// before
let project = add_project(repo_path)?.try_project()?;
// after
let toplevel = Command::new("git")
    .args(["rev-parse", "--show-toplevel"])
    .current_dir(&repo_path)
    .output()?;
if !toplevel.status.success() {
    return Err("repository has no working directory; re-clone it".into());
}
let project = add_project(repo_path)?.try_project()?;
Defensive patterns

Strategy: validation

Validate before calling

let out = std::process::Command::new("git")
    .args(["rev-parse", "--show-toplevel"])
    .current_dir(path)
    .output()?;
if !out.status.success() {
    return Err("repository has no working directory".into());
}

Try / catch

match outcome.try_project() {
    Err(e) if e.to_string() == "no workdir found for repository" => {
        // guide user to re-clone the repo with a working tree
        offer_reclone_flow(&path)?;
    }
    other => other,
}

Prevention

When it happens

Trigger: Adding a repo whose repository handle opens but `Repository::workdir()` returns None — bare repos, or repos with a corrupted `core.worktree`/missing core.bare configuration after manual .git manipulation.

Common situations: Hand-edited .git/config removing worktree settings; repos converted to/from bare; .git directories copied out of context; container or CI artifacts with incomplete checkouts.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/70dbd62a6bb0e8bd. Report an issue: GitHub.

Appendix: source

Thrown at crates/gitbutler-project/src/project.rs:329

        }
    }

    /// Try to get the `Project`, returning an error if it was not added.
    pub fn try_project(self) -> anyhow::Result<Project> {
        match self {
            AddProjectOutcome::Added(p) => Ok(p),
            AddProjectOutcome::AlreadyExists(_) => Err(anyhow::anyhow!("project already exists")),
            AddProjectOutcome::PathNotFound => Err(anyhow::anyhow!("project path not found")),
            AddProjectOutcome::NotADirectory => {
                Err(anyhow::anyhow!("project path is not a directory"))
            }
            AddProjectOutcome::BareRepository => {
                Err(anyhow::anyhow!("bare repositories are not supported"))
            }
            AddProjectOutcome::NonMainWorktree => {
                Err(anyhow::anyhow!("non-main worktrees are not supported"))
            }
            AddProjectOutcome::NoWorkdir => Err(anyhow::anyhow!("no workdir found for repository")),
            AddProjectOutcome::NoDotGitDirectory => {
                Err(anyhow::anyhow!("no .git directory found in repository"))
            }
            AddProjectOutcome::ReftableRefFormatUnsupported => Err(anyhow::anyhow!(
                "unsupported repository reference format: reftable"
            )),
            AddProjectOutcome::NotAGitRepository(msg) => {
                Err(anyhow::anyhow!("not a git repository: {msg}"))
            }
        }
    }
}

View on GitHub (pinned to 58e5313667)