Skip to content

Commit

Permalink
feat: 🎸 check for staged files
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigograca31 committed May 24, 2020
1 parent 193f022 commit c283ad3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c283ad3

Please sign in to comment.