Skip to main content

file_at

Function file_at 

Source
pub fn file_at(commit: &str, path: &str) -> Result<Option<String>>
Expand description

The contents of path, relative to the repository root, in commit’s tree, or None when that tree has no such file.

Absent and unreadable are told apart, which is why this asks ls-tree before reading: cat-file fails the same way for a path the commit does not have and for a tree this clone never fetched. A caller that falls back on absence must not fall back on the second, or a checkout missing the objects would quietly get a different answer from one that has them.

cat-file blob rather than git show: plumbing, so no pager, no textconv and nothing a user’s config can put between the bytes and the parser. --literal-pathspecs because a directory name is data here, not a glob.

A symlink is followed, as the search on disk follows one, but only within commit’s own tree: its blob holds the target path, which is resolved and looked up in the same tree. A target that is absolute or climbs out of the repository is refused rather than read from the disk, because the disk is the working tree, and the working tree is what this read exists to avoid. A link that leads nowhere is an error, not an absent file: the tree says a file is there, and falling back would ignore it.