From 772494e7730f839daf7696b7b918e5eda24945ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Wed, 16 Sep 2015 09:52:09 +0200 Subject: [PATCH] fix(commits): handle failing git command correctly and show meaningful error Closes #83 --- src/lib/commits.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/lib/commits.js b/src/lib/commits.js index ae5a6fe0..b5034be7 100644 --- a/src/lib/commits.js +++ b/src/lib/commits.js @@ -12,27 +12,27 @@ module.exports = function ({lastRelease, options}, cb) { if (!from) return extract() exec(`git branch --contains ${from}`, (err, stdout) => { - if (err) return cb(err) let inHistory = false + let branches - const branches = stdout.split('\n') - .map((result) => { - if (branch === result.replace('*', '').trim()) { - inHistory = true - return null - } - return result.trim() - }) - .filter(branch => !!branch) + if (!err && stdout) { + branches = stdout.split('\n') + .map((result) => { + if (branch === result.replace('*', '').trim()) { + inHistory = true + return null + } + return result.trim() + }) + .filter(branch => !!branch) + } if (!inHistory) { log.error('commits', -`The commit the last release of this package was derived from is no longer -in the direct history of the "${branch}" branch. +`The commit the last release of this package was derived from is not in the direct history of the "${branch}" branch. 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. -You can recover from this error by publishing manually or restoring -the commit "${from}".` + (branches.length ? +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 the commit "${from}".` + (branches && branches.length ? `\nHere is a list of branches that still contain the commit in question: \n * ${branches.join('\n * ')}` : '' ))