pub mod next_action;
pub mod repo;
pub mod sync;
pub mod working_dir;
pub use next_action::NextAction;
pub use repo::RepoType;
pub use sync::SyncState;
pub use working_dir::WorkingDirState;
use std::marker::PhantomData;
use crate::error::{GwError, Result};
use crate::git;
pub struct Protected;
pub struct Deletable;
#[derive(Debug)]
pub struct Branch<Status> {
name: String,
_status: PhantomData<Status>,
}
impl<S> Branch<S> {
pub fn name(&self) -> &str {
&self.name
}
}
impl Branch<Protected> {
pub fn protected(name: String) -> Self {
Branch {
name,
_status: PhantomData,
}
}
}
impl Branch<Deletable> {
pub fn deletable(name: String) -> Self {
Branch {
name,
_status: PhantomData,
}
}
pub fn delete(self, verbose: bool) -> Result<()> {
git::delete_branch(&self.name, verbose)
}
}
pub fn classify_branch(branch: &str, repo_type: &RepoType) -> BranchClassification {
if repo_type.is_protected(branch) {
BranchClassification::Protected(Branch::protected(branch.to_string()))
} else {
BranchClassification::Deletable(Branch::deletable(branch.to_string()))
}
}
pub enum BranchClassification {
Protected(Branch<Protected>),
Deletable(Branch<Deletable>),
}
impl BranchClassification {
pub fn name(&self) -> &str {
match self {
BranchClassification::Protected(b) => b.name(),
BranchClassification::Deletable(b) => b.name(),
}
}
pub fn try_deletable(self) -> Result<Branch<Deletable>> {
match self {
BranchClassification::Protected(b) => {
Err(GwError::ProtectedBranch(b.name().to_string()))
}
BranchClassification::Deletable(b) => Ok(b),
}
}
}