(
&self,
chain_name: &str,
step_rebase: bool,
ignore_root: bool,
)
| 20 | } |
| 21 | impl GitChain { |
| 22 | pub fn rebase( |
| 23 | &self, |
| 24 | chain_name: &str, |
| 25 | step_rebase: bool, |
| 26 | ignore_root: bool, |
| 27 | ) -> Result<(), Error> { |
| 28 | match self.preliminary_checks(chain_name) { |
| 29 | Ok(_) => {} |
| 30 | Err(e) => { |
| 31 | return Err(Error::from_str(&format!( |
| 32 | "🛑 Unable to rebase chain {}: {}", |
| 33 | chain_name, e |
| 34 | ))); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | let chain = Chain::get_chain(self, chain_name)?; |
| 39 | let orig_branch = self.get_current_branch_name()?; |
| 40 | let root_branch = chain.root_branch; |
| 41 | |
| 42 | // List of common ancestors between each branch and its parent branch. |
| 43 | // For the first branch, a common ancestor is generated between it and the root branch. |
| 44 | // |
| 45 | // The following command is used to generate the common ancestors: |
| 46 | // git merge-base --fork-point <ancestor_branch> <descendant_branch> |
| 47 | let mut common_ancestors = vec![]; |
| 48 | |
| 49 | for (index, branch) in chain.branches.iter().enumerate() { |
| 50 | if index == 0 { |
| 51 | let common_point = self.smart_merge_base(&root_branch, &branch.branch_name)?; |
| 52 | common_ancestors.push(common_point); |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | let prev_branch = &chain.branches[index - 1]; |
| 57 | |
| 58 | let common_point = |
| 59 | self.smart_merge_base(&prev_branch.branch_name, &branch.branch_name)?; |
| 60 | common_ancestors.push(common_point); |
| 61 | } |
| 62 | |
| 63 | assert_eq!(chain.branches.len(), common_ancestors.len()); |
| 64 | |
| 65 | let mut num_of_rebase_operations = 0; |
| 66 | let mut num_of_branches_visited = 0; |
| 67 | |
| 68 | for (index, branch) in chain.branches.iter().enumerate() { |
| 69 | if step_rebase && num_of_rebase_operations == 1 { |
| 70 | // performed at most one rebase. |
| 71 | break; |
| 72 | } |
| 73 | |
| 74 | num_of_branches_visited += 1; |
| 75 | |
| 76 | let prev_branch_name = if index == 0 { |
| 77 | &root_branch |
| 78 | } else { |
| 79 | &chain.branches[index - 1].branch_name |
no test coverage detected