(
git_chain: &GitChain,
chain_name: &str,
before_branch: Option<&str>,
after_branch: Option<&str>,
)
| 10 | use crate::{Branch, Chain}; |
| 11 | |
| 12 | pub fn parse_sort_option( |
| 13 | git_chain: &GitChain, |
| 14 | chain_name: &str, |
| 15 | before_branch: Option<&str>, |
| 16 | after_branch: Option<&str>, |
| 17 | ) -> Result<SortBranch, Error> { |
| 18 | if let Some(before_branch) = before_branch { |
| 19 | if !git_chain.git_local_branch_exists(before_branch)? { |
| 20 | return Err(Error::from_str(&format!( |
| 21 | "Branch does not exist: {}", |
| 22 | before_branch.bold() |
| 23 | ))); |
| 24 | } |
| 25 | |
| 26 | let before_branch = match Branch::get_branch_with_chain(git_chain, before_branch)? { |
| 27 | BranchSearchResult::NotPartOfAnyChain => { |
| 28 | git_chain.display_branch_not_part_of_chain_error(before_branch); |
| 29 | process::exit(1); |
| 30 | } |
| 31 | BranchSearchResult::Branch(before_branch) => { |
| 32 | if before_branch.chain_name != chain_name { |
| 33 | return Err(Error::from_str(&format!( |
| 34 | "Branch {} is not part of chain {}", |
| 35 | before_branch.branch_name.bold(), |
| 36 | chain_name.bold() |
| 37 | ))); |
| 38 | } |
| 39 | before_branch |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | Ok(SortBranch::Before(before_branch)) |
| 44 | } else if let Some(after_branch) = after_branch { |
| 45 | if !git_chain.git_local_branch_exists(after_branch)? { |
| 46 | return Err(Error::from_str(&format!( |
| 47 | "Branch does not exist: {}", |
| 48 | after_branch.bold() |
| 49 | ))); |
| 50 | } |
| 51 | |
| 52 | let after_branch = match Branch::get_branch_with_chain(git_chain, after_branch)? { |
| 53 | BranchSearchResult::NotPartOfAnyChain => { |
| 54 | git_chain.display_branch_not_part_of_chain_error(after_branch); |
| 55 | process::exit(1); |
| 56 | } |
| 57 | BranchSearchResult::Branch(after_branch) => { |
| 58 | if after_branch.chain_name != chain_name { |
| 59 | return Err(Error::from_str(&format!( |
| 60 | "Branch {} is not part of chain {}", |
| 61 | after_branch.branch_name.bold(), |
| 62 | chain_name.bold() |
| 63 | ))); |
| 64 | } |
| 65 | after_branch |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | Ok(SortBranch::After(after_branch)) |
no test coverage detected