raw
1use git2::{Branch, BranchType, Reference};
2
3use crate::git::Repository;
4
5impl Repository {
6 #[tracing::instrument(skip_all)]
7 pub(crate) fn branches(&self) -> crate::error::Result<Vec<Reference<'_>>> {
8 let references = self.inner.references()?;
9
10 let branches = references
11 .filter_map(Result::ok)
12 .filter(Reference::is_branch)
13 .collect();
14
15 Ok(branches)
16 }
17
18 #[tracing::instrument(skip_all)]
19 pub(crate) fn branches_of_type(
20 &self,
21 typ: BranchType,
22 ) -> crate::error::Result<Vec<Branch<'_>>> {
23 let branches = self
24 .inner
25 .branches(Some(typ))?
26 .filter_map(|x| if let Ok(x) = x { Some(x.0) } else { None })
27 .collect();
28
29 Ok(branches)
30 }
31}
32