git_workflow/state/
repo.rs1use crate::error::Result;
4use crate::git;
5
6#[derive(Debug, Clone)]
8pub enum RepoType {
9 MainRepo { home_branch: String },
11 Worktree { home_branch: String },
13}
14
15impl RepoType {
16 pub fn detect() -> Result<Self> {
18 if git::is_worktree()? {
19 let home_branch = git::current_dir_name()?;
20 Ok(RepoType::Worktree { home_branch })
21 } else {
22 let home_branch = git::default_branch_name()?;
24 Ok(RepoType::MainRepo { home_branch })
25 }
26 }
27
28 pub fn home_branch(&self) -> &str {
30 match self {
31 RepoType::MainRepo { home_branch } => home_branch,
32 RepoType::Worktree { home_branch } => home_branch,
33 }
34 }
35
36 pub fn is_protected(&self, branch: &str) -> bool {
38 if branch == "main" || branch == "master" {
40 return true;
41 }
42 branch == self.home_branch()
44 }
45}