From ab0bf07fae45bc3ca7abe4cee602d4e4c54422e4 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Mon, 11 Jan 2016 13:52:45 -0500 Subject: [PATCH] add --apply to cherry-pick the result rather than logging it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit also adds --bail to stop if a commit doesn’t apply rather than skipping it --- branch-diff.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/branch-diff.js b/branch-diff.js index 9bcef15..08abda7 100755 --- a/branch-diff.js +++ b/branch-diff.js @@ -100,6 +100,30 @@ function diffCollected (options, branchCommits, callback) { } +function applyCommits (list, bail) { + const cp = require('child_process') + + let i = list.length + while (i--) { + const commit = list[i] + const out = cp.spawnSync('git', ['cherry-pick', commit.sha]) + + if (out.status === 0) { + continue + } + + const cleanup = cp.spawnSync('git', ['cherry-pick', '--abort']) + if (cleanup.status !== 0) { + console.error('Error resetting git, bailing.') + return + } + + console.log(`${bail ? 'Bailing' : 'Skipping'}: Could not apply ${commit.sha.slice(0, 7)}... ${commit.summary}`) + if (bail) return + } +} + + function printCommits (list, simple) { list = list.map((commit) => commitToOutput(commit, simple, ghId)) @@ -134,6 +158,7 @@ if (require.main === module) { , endRef = argv['end-ref'] , excludeLabels = [] , options + , bail = argv.bail if (argv['patch-only']) excludeLabels = [ 'semver-minor', 'semver-major' ] @@ -149,6 +174,11 @@ if (require.main === module) { if (err) throw err + if (argv.apply) { + applyCommits(list, bail) + return + } + printCommits(list, simple) }) }