* Rebase an array of commits one-by-one, starting from a given base SHA
(baseCommit: GitHubCompareCommit, commits: GitHubCompareCommits)
| 1113 | * Rebase an array of commits one-by-one, starting from a given base SHA |
| 1114 | */ |
| 1115 | async rebaseCommits(baseCommit: GitHubCompareCommit, commits: GitHubCompareCommits) { |
| 1116 | /** |
| 1117 | * If the parent of the first commit already matches the target base, |
| 1118 | * return commits as is. |
| 1119 | */ |
| 1120 | if (commits.length === 0 || commits[0].parents[0].sha === baseCommit.sha) { |
| 1121 | const head = last(commits) as GitHubCompareCommit; |
| 1122 | return head; |
| 1123 | } else { |
| 1124 | /** |
| 1125 | * Re-create each commit over the new base, applying each to the previous, |
| 1126 | * changing only the parent SHA and tree for each, but retaining all other |
| 1127 | * info, such as the author/committer data. |
| 1128 | */ |
| 1129 | const newHeadPromise = commits.reduce((lastCommitPromise, commit) => { |
| 1130 | return lastCommitPromise.then(newParent => { |
| 1131 | const parent = newParent; |
| 1132 | const commitToRebase = commit; |
| 1133 | return this.rebaseSingleCommit(parent, commitToRebase); |
| 1134 | }); |
| 1135 | }, Promise.resolve(baseCommit)); |
| 1136 | return newHeadPromise; |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | async rebaseBranch(branch: string) { |
| 1141 | try { |
no test coverage detected