From c283ad3fac13eaf00a899b49da474c7608a61708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Gra=C3=A7a?= Date: Sun, 24 May 2020 22:05:02 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20check=20for=20staged=20f?= =?UTF-8?q?iles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/cli.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index 15e91372..d9be30ad 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,4 +1,4 @@ -const {spawn} = require('child_process'); +const {spawn, execSync} = require('child_process'); const fs = require('fs'); const {join} = require('path'); const shellescape = require('any-shell-escape'); @@ -27,6 +27,20 @@ const executeCommand = (command, args = [], env = process.env) => { const main = async () => { try { + try { + /** + * @author https://github.com/rodrigograca31 + * @see https://github.com/streamich/git-cz/issues/177 + * + * It exits with 1 if there were differences and 0 means no differences. + * Because of that we negate it to only throw an error if there's no files staged + * https://stackoverflow.com/questions/367069/how-can-i-negate-the-return-value-of-a-process + */ + execSync('! git diff HEAD --staged --quiet --exit-code'); + } catch (error) { + throw new Error('No files staged.'); + } + const {cliAnswers, cliOptions, passThroughParams} = parseArgs(); if (cliOptions.dryRun) {