use crate::api;
use crate::error::OxenError;
use crate::model::{Commit, LocalRepository};
pub fn get(repo: &LocalRepository, revision: impl AsRef<str>) -> Result<Option<Commit>, OxenError> {
let revision = revision.as_ref();
if api::local::branches::exists(repo, revision)? {
let branch = api::local::branches::get_by_name(repo, revision)?;
let branch = branch.ok_or(OxenError::local_branch_not_found(revision))?;
let commit = api::local::commits::get_by_id(repo, &branch.commit_id)?;
Ok(commit)
} else {
let commit = api::local::commits::get_by_id(repo, revision)?;
Ok(commit)
}
}