use crate::{
    bare::GitBare,
    cmd::oid::ObjectId,
    errors::{GitError, GitResult},
};

impl GitBare {
    pub fn commit_oid_from_prefix(&self, prefix: &str) -> GitResult<ObjectId> {
        let repo = self.gix_repo()?;
        let id = repo
            .rev_parse_single(prefix)
            .map_err(|_| GitError::ObjectNotFound(prefix.to_string()))?;

        let obj_id = id.detach();
        Ok(ObjectId::new(obj_id.to_hex().to_string()))
    }

    pub fn commit_info_from_prefix(
        &self,
        prefix: &str,
    ) -> GitResult<crate::cmd::commit::CommitMeta> {
        let oid = self.commit_oid_from_prefix(prefix)?;
        self.commit_info(oid)
    }
}
