From 62f671dcd0ba1c86e4e765aa9b1e323aa77c354d Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Mon, 25 Jun 2018 09:55:51 +0800 Subject: [PATCH] fix: output error messages if git commands failed (#102) --- src/util/git.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/util/git.js b/src/util/git.js index d91d996..6d6f730 100644 --- a/src/util/git.js +++ b/src/util/git.js @@ -37,8 +37,16 @@ function getRepoInfo() { const spawnGitCommand = pify((args, cb) => { const git = spawn('git', args) - git.stderr.on('data', cb) - git.on('close', cb) + const bufs = []; + git.stderr.on('data', (buf) => bufs.push(buf)); + git.on('close', (code) => { + if (code) { + const msg = Buffer.concat(bufs).toString() || `git ${args.join('')} - exit code: ${code}`; + cb(new Error(msg)); + } else { + cb(null); + } + }); }) function commit(options, data) {