| 41 | } |
| 42 | |
| 43 | fn get_branches_for_chain( |
| 44 | git_chain: &GitChain, |
| 45 | chain_name: &str, |
| 46 | ) -> Result<Vec<Branch>, Error> { |
| 47 | let key_regex = Regex::new(r"^branch\.(?P<branch_name>.+)\.chain-name$".trim()).unwrap(); |
| 48 | let mut branches: Vec<Branch> = vec![]; |
| 49 | |
| 50 | let entries = Chain::get_all_branch_configs(git_chain)?; |
| 51 | for (key, value) in entries { |
| 52 | if value != chain_name { |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | let captures = key_regex.captures(&key).unwrap(); |
| 57 | let branch_name = &captures["branch_name"]; |
| 58 | |
| 59 | let results = Branch::get_branch_with_chain(git_chain, branch_name)?; |
| 60 | |
| 61 | match results { |
| 62 | BranchSearchResult::NotPartOfAnyChain => { |
| 63 | // TODO: could this fail silently? |
| 64 | eprintln!( |
| 65 | "Branch not correctly set up as part of a chain: {}", |
| 66 | branch_name.bold() |
| 67 | ); |
| 68 | process::exit(1); |
| 69 | } |
| 70 | BranchSearchResult::Branch(branch) => { |
| 71 | branches.push(branch); |
| 72 | } |
| 73 | }; |
| 74 | } |
| 75 | |
| 76 | Ok(branches) |
| 77 | } |
| 78 | |
| 79 | pub fn chain_exists(git_chain: &GitChain, chain_name: &str) -> Result<bool, Error> { |
| 80 | let branches = Chain::get_branches_for_chain(git_chain, chain_name)?; |