use crate::error::Result;
use crate::git;
#[derive(Debug, Clone)]
pub enum RepoType {
MainRepo,
Worktree { home_branch: String },
}
impl RepoType {
pub fn detect() -> Result<Self> {
if git::is_worktree()? {
let home_branch = git::current_dir_name()?;
Ok(RepoType::Worktree { home_branch })
} else {
Ok(RepoType::MainRepo)
}
}
pub fn home_branch(&self) -> &str {
match self {
RepoType::MainRepo => "main",
RepoType::Worktree { home_branch } => home_branch,
}
}
pub fn is_protected(&self, branch: &str) -> bool {
if branch == "main" || branch == "master" {
return true;
}
branch == self.home_branch()
}
}