GitoxideLabs/gitoxide · error

Refusing to read an empty path from

Error message

Refusing to read an empty path from '{}'

What it means

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.

Solutions

  1. Recreate the `.git` file with proper content, e.g. `gitdir: /path/to/repo/.git`.
  2. Check the file's size/contents (`cat .git`) and repair or re-run the command that generated it (e.g. `git worktree repair`).
  3. If the path is expected to be empty, it is not a valid gitdir pointer — discover the repository a different way.

Example fix

// before: .git file is empty -> InvalidData error
// after: write the gitdir pointer
// .git
gitdir: /home/user/repos/main/.git
Defensive patterns

Strategy: validation

Validate before calling

let meta = std::fs::metadata(&git_file)?;
if meta.len() == 0 {
    anyhow::bail!(".git pointer file at {} is empty", git_file.display());
}

Try / catch

match gix_discover::path::from_plain_file(&path) {
    Some(Err(e)) if e.kind() == std::io::ErrorKind::InvalidData => /* repair or skip: empty .git file */,
    other => /* handle normally */,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/8188753c65f17bd1. Report an issue: GitHub.

Appendix: source

Thrown at gix-discover/src/path.rs:63

}

/// Read a plain path file, returning `None` if the file is missing.
///
/// Linked-worktree `gitdir` files are plain path files in Git, not `gitdir:`
/// files. Match Git's `get_linked_worktree()` behavior by trimming trailing
/// whitespace before interpreting the content. Empty or whitespace-only path
/// files are invalid.
fn read_plain_file_content(path: &std::path::Path) -> Option<std::io::Result<Vec<u8>>> {
    use bstr::ByteSlice;
    let mut buf = match read_regular_file_content_with_size_limit(path) {
        Ok(buf) => buf,
        Err(err) if err.kind() == std::io::ErrorKind::NotFound => return None,
        Err(err) => return Some(Err(err)),
    };
    let trimmed_len = buf.trim_end().len();
    buf.truncate(trimmed_len);
    if buf.is_empty() {
        return Some(Err(std::io::Error::new(
            std::io::ErrorKind::InvalidData,
            format!("Refusing to read an empty path from '{}'", path.display()),
        )));
    }
    Some(Ok(buf))
}

/// Guess the kind of repository by looking at its `git_dir` path and return it.
/// Return `None` if `git_dir` isn't called `.git` or isn't within `.git/worktrees` or `.git/modules`, or if it's
/// a `.git` suffix like in `foo.git`.
/// The check for markers is case-sensitive under the assumption that nobody meddles with standard directories.
///
/// As this considers only the path, it cannot recognize linked worktrees of repositories whose Git directory isn't
/// named `.git`, such as natively bare repositories. Inspect the worktree's `commondir` file to identify those.
pub fn repository_kind(git_dir: &Path) -> Option<RepositoryKind> {
    if git_dir.file_name() == Some(OsStr::new(DOT_GIT_DIR)) {
        return Some(RepositoryKind::Common);
    }

View on GitHub (pinned to e73179060b)