From 4352144a98e81ce271c97ec7aebcace93f29508d Mon Sep 17 00:00:00 2001 From: Cory Reed Date: Mon, 2 Apr 2018 15:30:03 -0700 Subject: [PATCH] fix: correct `git merge-base` error code handling --- lib/git.js | 8 +++++++- test/git.test.js | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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 => {