fix(commits): handle failing git command correctly and show meaningful error
Closes #83
This commit is contained in:
parent
f3c13140d8
commit
772494e773
@ -12,10 +12,11 @@ module.exports = function ({lastRelease, options}, cb) {
|
|||||||
if (!from) return extract()
|
if (!from) return extract()
|
||||||
|
|
||||||
exec(`git branch --contains ${from}`, (err, stdout) => {
|
exec(`git branch --contains ${from}`, (err, stdout) => {
|
||||||
if (err) return cb(err)
|
|
||||||
let inHistory = false
|
let inHistory = false
|
||||||
|
let branches
|
||||||
|
|
||||||
const branches = stdout.split('\n')
|
if (!err && stdout) {
|
||||||
|
branches = stdout.split('\n')
|
||||||
.map((result) => {
|
.map((result) => {
|
||||||
if (branch === result.replace('*', '').trim()) {
|
if (branch === result.replace('*', '').trim()) {
|
||||||
inHistory = true
|
inHistory = true
|
||||||
@ -24,15 +25,14 @@ module.exports = function ({lastRelease, options}, cb) {
|
|||||||
return result.trim()
|
return result.trim()
|
||||||
})
|
})
|
||||||
.filter(branch => !!branch)
|
.filter(branch => !!branch)
|
||||||
|
}
|
||||||
|
|
||||||
if (!inHistory) {
|
if (!inHistory) {
|
||||||
log.error('commits',
|
log.error('commits',
|
||||||
`The commit the last release of this package was derived from is no longer
|
`The commit the last release of this package was derived from is not in the direct history of the "${branch}" branch.
|
||||||
in the direct history of the "${branch}" branch.
|
|
||||||
This means semantic-release can not extract the commits between now and then.
|
This means semantic-release can not extract the commits between now and then.
|
||||||
This is usually caused by force pushing or releasing from an unrelated branch.
|
This is usually caused by force pushing, releasing from an unrelated branch, or using an already existing package name.
|
||||||
You can recover from this error by publishing manually or restoring
|
You can recover from this error by publishing manually or restoring the commit "${from}".` + (branches && branches.length ?
|
||||||
the commit "${from}".` + (branches.length ?
|
|
||||||
`\nHere is a list of branches that still contain the commit in question: \n * ${branches.join('\n * ')}` :
|
`\nHere is a list of branches that still contain the commit in question: \n * ${branches.join('\n * ')}` :
|
||||||
''
|
''
|
||||||
))
|
))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user