{"record":{"id":"8188753c65f17bd1","repo":"GitoxideLabs/gitoxide","slug":"refusing-to-read-an-empty-path-from","errorCode":null,"errorMessage":"Refusing to read an empty path from '{}'","messagePattern":"Refusing to read an empty path from '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-discover/src/path.rs","lineNumber":63,"sourceCode":"}\n\n/// Read a plain path file, returning `None` if the file is missing.\n///\n/// Linked-worktree `gitdir` files are plain path files in Git, not `gitdir:`\n/// files. Match Git's `get_linked_worktree()` behavior by trimming trailing\n/// whitespace before interpreting the content. Empty or whitespace-only path\n/// files are invalid.\nfn read_plain_file_content(path: &std::path::Path) -> Option<std::io::Result<Vec<u8>>> {\n    use bstr::ByteSlice;\n    let mut buf = match read_regular_file_content_with_size_limit(path) {\n        Ok(buf) => buf,\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => return None,\n        Err(err) => return Some(Err(err)),\n    };\n    let trimmed_len = buf.trim_end().len();\n    buf.truncate(trimmed_len);\n    if buf.is_empty() {\n        return Some(Err(std::io::Error::new(\n            std::io::ErrorKind::InvalidData,\n            format!(\"Refusing to read an empty path from '{}'\", path.display()),\n        )));\n    }\n    Some(Ok(buf))\n}\n\n/// Guess the kind of repository by looking at its `git_dir` path and return it.\n/// Return `None` if `git_dir` isn't called `.git` or isn't within `.git/worktrees` or `.git/modules`, or if it's\n/// a `.git` suffix like in `foo.git`.\n/// The check for markers is case-sensitive under the assumption that nobody meddles with standard directories.\n///\n/// As this considers only the path, it cannot recognize linked worktrees of repositories whose Git directory isn't\n/// named `.git`, such as natively bare repositories. Inspect the worktree's `commondir` file to identify those.\npub fn repository_kind(git_dir: &Path) -> Option<RepositoryKind> {\n    if git_dir.file_name() == Some(OsStr::new(DOT_GIT_DIR)) {\n        return Some(RepositoryKind::Common);\n    }","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-discover/src/path.rs#L45-L81","documentation":"gix-discover reads `.git` pointer files (`from_plain_file`) whose content must name a git directory. `read_plain_file_content` refuses files that are empty after trailing-whitespace trimming, because an empty file cannot contain a usable gitdir path, and returns an `InvalidData` io error naming the path.","triggerScenarios":"Calling `gix_discover::path::from_plain_file` / `from_plain_file_relative_to_file` on a `.git` file (gitdir pointer file) that is zero-length or contains only whitespace/newlines.","commonSituations":"A `.git` file created by `git worktree add` or submodule setup was truncated, an editor saved it empty, or a fixture repo in CI contains a placeholder empty `.git` file.","solutions":["Recreate the `.git` file with proper content, e.g. `gitdir: /path/to/repo/.git`.","Check the file's size/contents (`cat .git`) and repair or re-run the command that generated it (e.g. `git worktree repair`).","If the path is expected to be empty, it is not a valid gitdir pointer — discover the repository a different way."],"exampleFix":"// before: .git file is empty -> InvalidData error\n// after: write the gitdir pointer\n// .git\ngitdir: /home/user/repos/main/.git","handlingStrategy":"validation","validationCode":"let meta = std::fs::metadata(&git_file)?;\nif meta.len() == 0 {\n    anyhow::bail!(\".git pointer file at {} is empty\", git_file.display());\n}","typeGuard":null,"tryCatchPattern":"match gix_discover::path::from_plain_file(&path) {\n    Some(Err(e)) if e.kind() == std::io::ErrorKind::InvalidData => /* repair or skip: empty .git file */,\n    other => /* handle normally */,\n}","preventionTips":["After generating worktrees/submodules, sanity-check `.git` files are non-empty.","Exclude empty placeholder files from repo-discovery inputs.","Regenerate damaged worktree pointers with `git worktree repair`."],"tags":["git","filesystem","validation","rust"],"backgroundTag":"empty-required-field","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"}