diff --git a/src/git/refs/branch.rs b/src/git/refs/branch.rs index d882b7a..a15dd63 100644 --- a/src/git/refs/branch.rs +++ b/src/git/refs/branch.rs @@ -1,5 +1,6 @@ use std::fmt::Display; use std::ops::Deref; +use std::str::FromStr; use miette::miette; @@ -32,6 +33,13 @@ impl BranchRef { BranchRef::Remote(ref_name) => ref_name.branch_name(), } } + + pub fn as_local(&self) -> LocalBranchRef { + match self { + BranchRef::Local(local) => local.clone(), + BranchRef::Remote(remote) => remote.as_local(), + } + } } impl PartialEq for BranchRef { @@ -72,6 +80,14 @@ impl TryFrom for BranchRef { } } +impl FromStr for BranchRef { + type Err = miette::Report; + + fn from_str(s: &str) -> Result { + Ref::from_str(s)?.try_into() + } +} + impl From for BranchRef { fn from(value: LocalBranchRef) -> Self { Self::Local(value) diff --git a/src/git/refs/local_branch.rs b/src/git/refs/local_branch.rs index ae9c2fc..37cfef3 100644 --- a/src/git/refs/local_branch.rs +++ b/src/git/refs/local_branch.rs @@ -1,6 +1,7 @@ use std::fmt::Debug; use std::fmt::Display; use std::ops::Deref; +use std::str::FromStr; use miette::miette; @@ -58,6 +59,14 @@ impl TryFrom for LocalBranchRef { } } +impl FromStr for LocalBranchRef { + type Err = miette::Report; + + fn from_str(s: &str) -> Result { + Ref::from_str(s)?.try_into() + } +} + impl From for LocalBranchRef where S: AsRef,