use super::Repository;
use crate::{Error, ErrorKind};
use std::path::Path;
#[cfg_attr(docsrs, doc(cfg(feature = "osv-export")))]
pub struct GitPath<'a> {
repo: &'a Repository,
path: &'a Path,
}
impl<'a> GitPath<'a> {
pub fn new(repo: &'a Repository, path: &'a Path) -> Result<Self, Error> {
if path.has_root() {
fail!(
ErrorKind::BadParam,
"{} is not a relative path",
path.display()
);
}
if !repo.has_relative_path(path) {
Err(format_err!(
ErrorKind::Repo,
"HEAD commit does not contain path '{}'",
path.display()
))
} else {
Ok(GitPath { repo, path })
}
}
pub fn path(&self) -> &'a Path {
self.path
}
pub fn repository(&self) -> &'a Repository {
self.repo
}
}