Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions branch-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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' ]
Expand All @@ -149,6 +174,11 @@ if (require.main === module) {
if (err)
throw err

if (argv.apply) {
applyCommits(list, bail)
return
}

printCommits(list, simple)
})
}