use crate::api;
use crate::constants::DEFAULT_BRANCH_NAME;
use crate::error::OxenError;
use crate::model::RemoteRepository;
pub async fn remote_commit_id(
repo: &RemoteRepository,
commit_id: &Option<String>,
branch_name: &Option<String>,
) -> Result<String, OxenError> {
if let Some(commit_id) = commit_id {
if api::remote::commits::get_by_id(repo, commit_id)
.await?
.is_some()
{
return Ok(commit_id.to_string());
}
}
if let Some(branch_name) = branch_name {
if let Some(branch) = api::remote::branches::get_by_name(repo, branch_name).await? {
return Ok(branch.commit_id);
}
}
let main_branch = api::remote::branches::get_by_name(repo, DEFAULT_BRANCH_NAME).await?;
if main_branch.is_none() {
return Err(OxenError::basic_str("No main branch found on remote."));
}
Ok(main_branch.unwrap().commit_id)
}