{"record":{"id":"ad781668a90baf42","repo":"GitoxideLabs/gitoxide","slug":"at-least-one-directory-level","errorCode":null,"errorMessage":"at least one directory level","messagePattern":"at least one directory level","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix/src/worktree/mod.rs","lineNumber":109,"sourceCode":"\n    /// Return the ID of the repository worktree, if it is a linked worktree, or `None` if it's a linked worktree.\n    pub fn id(&self) -> Option<&BStr> {\n        id(self.parent.git_dir(), self.parent.common_dir.is_some())\n    }\n\n    /// Returns true if the `.git` file or directory exists within the worktree.\n    ///\n    /// This is an indicator for the worktree to be checked out particularly if the parent repository is a submodule.\n    pub fn dot_git_exists(&self) -> bool {\n        self.path.join(gix_discover::DOT_GIT_DIR).exists()\n    }\n}\n\npub(crate) fn id(git_dir: &std::path::Path, has_common_dir: bool) -> Option<&BStr> {\n    if !has_common_dir {\n        return None;\n    }\n    let candidate = gix_path::os_str_into_bstr(git_dir.file_name().expect(\"at least one directory level\"))\n        .expect(\"no illformed UTF-8\");\n    let maybe_worktrees = git_dir.parent()?;\n    (maybe_worktrees.file_name()?.to_str()? == \"worktrees\").then_some(candidate)\n}\n\n///\npub mod proxy;\n\n///\n#[cfg(feature = \"index\")]\npub mod open_index {\n    /// The error returned by [`Worktree::open_index()`][crate::Worktree::open_index()].\n    #[derive(Debug, thiserror::Error)]\n    #[expect(missing_docs)]\n    pub enum Error {\n        #[error(transparent)]\n        ConfigIndexThreads(#[from] crate::config::key::GenericErrorWithValue),\n        #[error(transparent)]","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix/src/worktree/mod.rs#L91-L127","documentation":"In `gix/src/worktree/mod.rs`, the internal `id()` helper derives a worktree name from `git_dir.file_name()` and expects the git dir to have at least one path component. If the git dir is the filesystem root (e.g. `/`) or otherwise has no file name, the expect panics. This helper only runs when a common dir exists and the parent looks like a `worktrees` directory, so a root-level git dir breaks the assumption.","triggerScenarios":"Opening a linked worktree whose git dir resolves to a path with no final component (root path), e.g. exotic setups mounting `.git/worktrees/<name>` content at `/`; calling `repo.worktrees()`/`worktree::Proxy::id()` paths on such a layout.","commonSituations":"Container/chroot layouts where the git dir is `/`; corrupted `.git/worktrees` metadata; deeply custom CI setups linking worktrees at unusual paths.","solutions":["Ensure the worktree git dir (`.git/worktrees/<name>` per the common dir) is a normal named directory, not a mount root.","Check `git_dir.file_name()` is `Some` before calling APIs that derive the worktree id, or use `try_id`-style logic upstream.","Report a bug to gitoxide if a standard `git worktree add` layout triggers this."],"exampleFix":"// before\nlet name = git_dir.file_name().expect(\"at least one directory level\");\n// after (caller-side guard)\nif git_dir.file_name().is_none() { return Ok(None); } // skip: git dir has no name component","handlingStrategy":"validation","validationCode":"let git_dir = proxy.git_dir();\nassert!(git_dir.file_name().is_some(), \"git dir must not be a root path\");\n","typeGuard":"fn has_name(p: &std::path::Path) -> bool { p.file_name().is_some() }\n","tryCatchPattern":null,"preventionTips":["Never locate .git/worktrees content at filesystem roots","Use standard `git worktree add` layouts","Check git_dir has a final path component before worktree APIs"],"tags":["panic","path","worktree","git"],"backgroundTag":"internal-invariant-violation","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}