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

impl GitBare {
    pub fn tree_entry_by_path_from_commit(
        &self,
        commit: ObjectId,
        path: String,
    ) -> GitResult<TreeEntry> {
        let repo = self.gix_repo()?;
        let gix_id: gix::hash::ObjectId = (&commit).try_into()?;

        let gix_commit = repo.find_commit(gix_id)?;
        let tree_id = gix_commit.tree_id()?.detach();
        let tree_oid = ObjectId::new(tree_id.to_hex().to_string());

        self.tree_entry_by_path(tree_oid, path)
    }
}
