Skip to content

Commit ab0bf07

Browse files
committed
add --apply to cherry-pick the result rather than logging it
also adds --bail to stop if a commit doesn’t apply rather than skipping it
1 parent 1fa5e2f commit ab0bf07

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

branch-diff.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,30 @@ function diffCollected (options, branchCommits, callback) {
100100
}
101101

102102

103+
function applyCommits (list, bail) {
104+
const cp = require('child_process')
105+
106+
let i = list.length
107+
while (i--) {
108+
const commit = list[i]
109+
const out = cp.spawnSync('git', ['cherry-pick', commit.sha])
110+
111+
if (out.status === 0) {
112+
continue
113+
}
114+
115+
const cleanup = cp.spawnSync('git', ['cherry-pick', '--abort'])
116+
if (cleanup.status !== 0) {
117+
console.error('Error resetting git, bailing.')
118+
return
119+
}
120+
121+
console.log(`${bail ? 'Bailing' : 'Skipping'}: Could not apply ${commit.sha.slice(0, 7)}... ${commit.summary}`)
122+
if (bail) return
123+
}
124+
}
125+
126+
103127
function printCommits (list, simple) {
104128
list = list.map((commit) => commitToOutput(commit, simple, ghId))
105129

@@ -134,6 +158,7 @@ if (require.main === module) {
134158
, endRef = argv['end-ref']
135159
, excludeLabels = []
136160
, options
161+
, bail = argv.bail
137162

138163
if (argv['patch-only'])
139164
excludeLabels = [ 'semver-minor', 'semver-major' ]
@@ -149,6 +174,11 @@ if (require.main === module) {
149174
if (err)
150175
throw err
151176

177+
if (argv.apply) {
178+
applyCommits(list, bail)
179+
return
180+
}
181+
152182
printCommits(list, simple)
153183
})
154184
}

0 commit comments

Comments
 (0)