ice.fo.utils
Version:
35 lines (30 loc) • 875 B
JavaScript
module.exports = function cherryPickToBranches({ id, branches }) {
if (!id) {
console.log('Commit ID cannot be empty');
return;
}
const currentBranch = exports.getCurrentBrannch();
let success = false;
try {
for (const branchName of branches) {
console.log('[Chery Pick]', id, branchName);
exports.checkoutToBranch(branchName);
exports.pullLatest();
exports.cherryPickCommit(id);
console.log('[Cherry Pick] Succeeded', branchName);
}
success = true;
} catch (error) {
console.error(error);
// revert all cherry-picked
for (const branchName of branches) {
exports.checkoutToBranch(branchName);
exports.removeAllUnpushedCommits();
}
console.log('Reverted all cherry-pick');
success = false;
} finally {
exports.checkoutToBranch(currentBranch);
}
return success;
};