gitbutlerapp/gitbutler · error

no workdir found for repository

Error message

no workdir found for repository

What it means

AddProjectOutcome::NoWorkdir mapped through try_project: a git repository was detected but git reports no working directory for it (gix could not resolve a work_dir). Distinct from BareRepository — this happens when the repository layout is unusual (e.g. detached GIT_DIR setups, GIT_WORK_TREE not set where needed) so no workdir path can be determined.

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 caf1f223d3)

Solutions

  1. Onboard a standard clone where the worktree and .git sit together
  2. Unset GIT_DIR/GIT_WORK_TREE overrides when invoking the app so the repository layout resolves normally
  3. Inspect the repo with `git rev-parse --git-dir --show-toplevel` — if show-toplevel is empty, the layout is the problem

Example fix

// before
let project = add_project(&path, ...).try_project()?; // 'no workdir found'

// after: verify the repo reports a workdir before onboarding
let out = std::process::Command::new("git")
    .args(["-C", path.to_str().unwrap(), "rev-parse", "--show-toplevel"])
    .output()?;
if out.stdout.is_empty() {
    anyhow::bail!("repository at {} has no workdir — use a standard clone", path.display());
}
let project = add_project(&path, ...).try_project()?;
Defensive patterns

Strategy: validation

Validate before calling

let out = std::process::Command::new("git")
    .args(["-C", &path.to_string_lossy(), "rev-parse", "--show-toplevel"])
    .output()?;
if !out.status.success() || out.stdout.trim().is_empty() {
    anyhow::bail!("repository reports no workdir — use a standard clone");
}

Try / catch

match add_project(&path, ...) {
    AddProjectOutcome::NoWorkdir => suggest_standard_clone(&path),
    outcome => outcome.try_project(),
}

Prevention

When it happens

Trigger: add_project where the repo was opened with only a gitdir (GIT_DIR set, no work tree); unusual layouts like .git files pointing to relocated gitdirs without a worktree config; repos on filesystems where the workdir lookup fails.

Common situations: Environments exporting GIT_DIR/GIT_WORK_TREE inconsistently; repos managed by wrappers that move .git elsewhere; edge-case repository layouts produced by other tools.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/70dbd62a6bb0e8bd. Report an issue: GitHub.