GitoxideLabs/gitoxide · error · anyhow::Error
Input paths need to be relative, but
Error message
Input paths need to be relative, but {path:?} is not. What it means
When constructing an index from a list of paths (entries file, one path per line), every input path must be relative to the repository root. Absolute paths are rejected with this error because index entries are stored as relative paths by design and writing an absolute path would corrupt the index semantics.
Solutions
- Make the path relative in the entries file (strip the repository root prefix)
- Generate the list with a relative-path command (e.g. `git ls-files` or `find .`)
- Pre-process the entries file to remove leading `/` or absolute prefixes before passing it
Example fix
// before (entries file) /home/user/repo/src/main.rs // after (entries file) src/main.rs
Defensive patterns
Strategy: validation
Validate before calling
use std::path::{Path, PathBuf};
fn sanitize_entry(path: &str, root: &Path) -> PathBuf {
let p = Path::new(path);
p.strip_prefix(root).unwrap_or(p).to_path_buf()
}
// apply to every line read from the entries file Type guard
fn is_relative_entry(p: &Path) -> bool { p.is_relative() } Try / catch
match index::from_list(repo, &entries_file, object_hash) {
Err(e) if e.to_string().contains("need to be relative") => {
eprintln!("entries file contains absolute paths; strip the repo root prefix");
}
other => other?,
} Prevention
- Generate entries with relative-path commands (git ls-files, find .)
- Strip the repository root prefix from paths before writing the list
- Validate every line with Path::is_relative() before invoking
- Avoid tools that emit absolute paths by default (e.g. find $(pwd))
When it happens
Trigger: Calling `from_list` in gitoxide-core/src/repository/index/mod.rs (CLI `gix index from-list`) where the entries file contains an absolute path like `/home/user/repo/src/main.rs` or a path with a drive/leading separator.
Common situations: Generating the entries list with a tool that emits absolute paths (e.g. `find $(pwd)`); piping `git ls-files` output through a script that prefixes the workdir; copy-pasting full paths from an IDE.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- File at " " already exists, to overwrite use the '-f' flag
- Cannot use iter_v1() on index of type
- Cannot use iter_v2() on index of type
- invalid mode change: can't flip executable bit of
- visit_non_tree() called us
AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08).
Data as JSON: /api/errors/74c1c19e221afa70.
Report an issue: GitHub.
Appendix: source
Thrown at gitoxide-core/src/repository/index/mod.rs:56
Ok(())
}
pub fn from_list(
entries_file: PathBuf,
index_path: Option<PathBuf>,
force: bool,
skip_hash: bool,
) -> anyhow::Result<()> {
use std::io::BufRead;
let object_hash = gix::hash::Kind::Sha1;
let mut index = gix::index::State::new(object_hash);
for path in std::io::BufReader::new(std::fs::File::open(entries_file)?).lines() {
let path: PathBuf = path?.into();
#[expect(clippy::unnecessary_debug_formatting)]
if !path.is_relative() {
bail!("Input paths need to be relative, but {path:?} is not.")
}
let path = gix::path::into_bstr(path);
index.dangerously_push_entry(
gix::index::entry::Stat::default(),
gix::hash::ObjectId::empty_blob(object_hash),
gix::index::entry::Flags::empty(),
gix::index::entry::Mode::FILE,
gix::path::to_unix_separators_on_windows(path).as_ref(),
);
}
index.sort_entries();
let options = gix::index::write::Options {
skip_hash,
..Default::default()
};
match index_path {
Some(index_path) => {View on GitHub (pinned to e73179060b)