zed-industries/zed · error · anyhow::Error

git.worktree_directory must not be ".." (use "../some-name"

Error message

git.worktree_directory must not be ".." (use "../some-name" instead)

What it means

After trimming trailing separators, a worktree_directory value equal to exactly ".." would resolve the worktree directory to the repository's parent directory itself, colliding with the repo's own directory (crates/project/src/git_store.rs:10503). Zed rejects it and asks for a named sibling like "../some-name" instead.

Source

Thrown at crates/project/src/git_store.rs:10503

    // is absolute but becomes "" after stripping trailing separators.
    // Also check for leading `/` or `\` explicitly, because on Windows
    // `Path::is_absolute()` requires a drive letter — so `/tmp/worktrees`
    // would slip through even though it's clearly not a relative path.
    if path_style.is_absolute(worktree_directory_setting)
        || worktree_directory_setting.starts_with('\\')
    {
        anyhow::bail!(
            "git.worktree_directory must be a relative path, got: {worktree_directory_setting:?}"
        );
    }

    if worktree_directory_setting.is_empty() {
        anyhow::bail!("git.worktree_directory must not be empty");
    }

    let trimmed = worktree_directory_setting.trim_end_matches(['/', '\\']);
    if trimmed == ".." {
        anyhow::bail!("git.worktree_directory must not be \"..\" (use \"../some-name\" instead)");
    }

    let joined = path_style.join_path(repository_anchor_path, trimmed)?;
    let resolved = if path_style.is_posix() {
        joined
    } else {
        path::normalize_path(&joined)
    };
    let resolved = if resolved.starts_with(repository_anchor_path) {
        resolved
    } else if let Some(repo_dir_name) = repository_anchor_path
        .file_name()
        .and_then(|name| name.to_str())
    {
        path_style.join_path(&resolved, repo_dir_name)?
    } else {
        resolved
    };

View on GitHub (pinned to f4178619ac)

Solutions

  1. Use a named sibling directory: "../my-repo-worktrees"
  2. Or keep worktrees inside the repository: ".worktrees"

Example fix

// settings.json - before
{ "git": { "worktree_directory": ".." } }

// settings.json - after
{ "git": { "worktree_directory": "../acme-worktrees" } }
Defensive patterns

Strategy: validation

Validate before calling

let trimmed = setting.trim_end_matches(['/', '\\']);
if trimmed == ".." {
    return Err("git.worktree_directory must not be \"..\" (use \"../some-name\" instead)".into());
}

Prevention

When it happens

Trigger: Setting git.worktree_directory to "..", or values that reduce to it after trimming trailing separators, such as "../" or "..\\".

Common situations: Users trying to scatter worktrees directly in the folder that contains their repos, without a naming prefix.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/6e06cb28cddb3c63. Report an issue: GitHub.