* Rebase an array of commits one-by-one, starting from a given base SHA
(baseCommit: GitHubCompareCommit, commits: GitHubCompareCommits)
| 1138 | * Rebase an array of commits one-by-one, starting from a given base SHA |
| 1139 | */ |
| 1140 | async rebaseCommits(baseCommit: GitHubCompareCommit, commits: GitHubCompareCommits) { |
| 1141 | /** |
| 1142 | * If the parent of the first commit already matches the target base, |
| 1143 | * return commits as is. |
| 1144 | */ |
| 1145 | if (commits.length === 0 || commits[0].parents[0].sha === baseCommit.sha) { |
| 1146 | const head = last(commits) as GitHubCompareCommit; |
| 1147 | return head; |
| 1148 | } else { |
| 1149 | /** |
| 1150 | * Re-create each commit over the new base, applying each to the previous, |
| 1151 | * changing only the parent SHA and tree for each, but retaining all other |
| 1152 | * info, such as the author/committer data. |
| 1153 | */ |
| 1154 | const newHeadPromise = commits.reduce((lastCommitPromise, commit) => { |
| 1155 | return lastCommitPromise.then(newParent => { |
| 1156 | const parent = newParent; |
| 1157 | const commitToRebase = commit; |
| 1158 | return this.rebaseSingleCommit(parent, commitToRebase); |
| 1159 | }); |
| 1160 | }, Promise.resolve(baseCommit)); |
| 1161 | return newHeadPromise; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | async rebaseBranch(branch: string) { |
| 1166 | try { |
no test coverage detected