git_workflow/state/
repo.rs1use crate::error::Result;
4use crate::git;
5
6#[derive(Debug, Clone)]
8pub enum RepoType {
9 MainRepo,
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 Ok(RepoType::MainRepo)
23 }
24 }
25
26 pub fn home_branch(&self) -> &str {
28 match self {
29 RepoType::MainRepo => "main",
30 RepoType::Worktree { home_branch } => home_branch,
31 }
32 }
33
34 pub fn is_protected(&self, branch: &str) -> bool {
36 if branch == "main" || branch == "master" {
38 return true;
39 }
40 branch == self.home_branch()
42 }
43}