Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BranchRef helpers #29

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/git/refs/branch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::fmt::Display;
use std::ops::Deref;
use std::str::FromStr;

use miette::miette;

Expand Down Expand Up @@ -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<Ref> for BranchRef {
Expand Down Expand Up @@ -72,6 +80,14 @@ impl TryFrom<Ref> for BranchRef {
}
}

impl FromStr for BranchRef {
type Err = miette::Report;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ref::from_str(s)?.try_into()
}
}

impl From<LocalBranchRef> for BranchRef {
fn from(value: LocalBranchRef) -> Self {
Self::Local(value)
Expand Down
9 changes: 9 additions & 0 deletions src/git/refs/local_branch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Debug;
use std::fmt::Display;
use std::ops::Deref;
use std::str::FromStr;

use miette::miette;

Expand Down Expand Up @@ -58,6 +59,14 @@ impl TryFrom<Ref> for LocalBranchRef {
}
}

impl FromStr for LocalBranchRef {
type Err = miette::Report;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ref::from_str(s)?.try_into()
}
}

impl<S> From<S> for LocalBranchRef
where
S: AsRef<str>,
Expand Down
Loading