{"record":{"id":"84ac090f1fbc681d","repo":"zed-industries/zed","slug":"git-worktree-directory-must-be-a-relative-path-go","errorCode":null,"errorMessage":"git.worktree_directory must be a relative path, got: {worktree_directory_setting:?}","messagePattern":"git\\.worktree_directory must be a relative path, got: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/project/src/git_store.rs","lineNumber":10492,"sourceCode":"/// - The setting must not be an absolute path.\n/// - The resolved path must be either a subdirectory of the working\n///   directory or a subdirectory of its parent (i.e., a sibling).\n///\n/// Returns `Ok(resolved_path)` or an error with a user-facing message.\npub fn worktrees_directory_for_repo(\n    repository_anchor_path: &Path,\n    worktree_directory_setting: &str,\n    path_style: PathStyle,\n) -> Result<PathBuf> {\n    // Check the original setting before trimming, since a path like \"///\"\n    // is absolute but becomes \"\" after stripping trailing separators.\n    // Also check for leading `/` or `\\` explicitly, because on Windows\n    // `Path::is_absolute()` requires a drive letter — so `/tmp/worktrees`\n    // would slip through even though it's clearly not a relative path.\n    if path_style.is_absolute(worktree_directory_setting)\n        || worktree_directory_setting.starts_with('\\\\')\n    {\n        anyhow::bail!(\n            \"git.worktree_directory must be a relative path, got: {worktree_directory_setting:?}\"\n        );\n    }\n\n    if worktree_directory_setting.is_empty() {\n        anyhow::bail!(\"git.worktree_directory must not be empty\");\n    }\n\n    let trimmed = worktree_directory_setting.trim_end_matches(['/', '\\\\']);\n    if trimmed == \"..\" {\n        anyhow::bail!(\"git.worktree_directory must not be \\\"..\\\" (use \\\"../some-name\\\" instead)\");\n    }\n\n    let joined = path_style.join_path(repository_anchor_path, trimmed)?;\n    let resolved = if path_style.is_posix() {\n        joined\n    } else {\n        path::normalize_path(&joined)","sourceCodeStart":10474,"sourceCodeEnd":10510,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/project/src/git_store.rs#L10474-L10510","documentation":"Zed validates the git.worktree_directory setting before creating a managed git worktree (crates/project/src/git_store.rs:10492). The value must be relative because it is joined onto the repository anchor path; absolute POSIX paths, Windows drive-letter paths, and values starting with a backslash are rejected up front (an explicit leading-slash check compensates for Windows Path::is_absolute() requiring a drive letter).","triggerScenarios":"Setting \"git\": { \"worktree_directory\": \"/tmp/worktrees\" } (or \"C:\\\\worktrees\", \"\\\\worktrees\") in settings.json, then creating a worktree. A value like \"///\" also lands here because it is absolute before trailing separators are trimmed.","commonSituations":"Users copying an absolute path they previously passed to git worktree add into settings; Windows drive-letter paths; leading-backslash values.","solutions":["Use a relative path such as \".zed-worktrees\" (resolved inside the repository)","To place worktrees next to the repository, use \"../my-repo-worktrees\"","Remove the setting entirely to fall back to the default location"],"exampleFix":"// settings.json - before\n{ \"git\": { \"worktree_directory\": \"/tmp/worktrees\" } }\n\n// settings.json - after\n{ \"git\": { \"worktree_directory\": \"../my-repo-worktrees\" } }","handlingStrategy":"validation","validationCode":"fn assert_relative_worktree_directory(setting: &str) -> Result<(), String> {\n    if setting.starts_with('/')\n        || setting.starts_with('\\\\')\n        || Path::new(setting).is_absolute()\n    {\n        return Err(format!(\"git.worktree_directory must be a relative path, got: {setting:?}\"));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep git.worktree_directory relative; use \"../name\" for sibling locations","Validate user-supplied path settings in CI or editor linting before shipping configs"],"tags":["git","worktree","settings","configuration","path-validation"],"backgroundTag":"invalid-config-value","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}