diff --git a/lib/git.js b/lib/git.js index ad6b4b30..474af2ee 100644 --- a/lib/git.js +++ b/lib/git.js @@ -36,9 +36,15 @@ async function gitTags() { */ async function isRefInHistory(ref) { try { - return (await execa('git', ['merge-base', '--is-ancestor', ref, 'HEAD'])).code === 0; + await execa('git', ['merge-base', '--is-ancestor', ref, 'HEAD']); + return true; } catch (err) { + if (err.code === 1) { + return false; + } + debug(err); + throw err; } } diff --git a/test/git.test.js b/test/git.test.js index 5ca650f5..849914d0 100644 --- a/test/git.test.js +++ b/test/git.test.js @@ -91,6 +91,7 @@ test.serial('Verify if the commit `sha` is in the direct history of the current t.true(await isRefInHistory(commits[0].hash)); t.falsy(await isRefInHistory(otherCommits[0].hash)); + await t.throws(isRefInHistory('non-existant-sha')); }); test.serial('Get the commit sha for a given tag or falsy if the tag does not exists', async t => {