use std::{borrow::Cow, convert::TryInto}; use git_ref::FullNameRef; use git_validate::reference::name::Error as ValidateNameError; use crate::bstr::BStr; impl crate::Repository { /// Returns a reference to the remote associated with the given `short_branch_name`, typically `main` instead of `refs/heads/main`. /// Returns `None` if the remote reference was not found. /// May return an error if the reference is invalid. pub fn remote_ref(&self, short_branch_name: &str) -> Option, ValidateNameError>> { self.config .resolved .string("branch", Some(short_branch_name), "merge") .map(|v| match v { Cow::Borrowed(v) => v.try_into().map(Cow::Borrowed), Cow::Owned(v) => v.try_into().map(Cow::Owned), }) } /// Returns the name of the remote associated with the given `short_branch_name`, typically `main` instead of `refs/heads/main`. /// In some cases, the returned name will be an URL. /// Returns `None` if the remote was not found. pub fn branch_remote_name(&self, short_branch_name: &str) -> Option> { self.config.resolved.string("branch", Some(short_branch_name), "remote") } }