Skip to content

Commit

Permalink
feat(prompt-cli): check stage before prompt conventional-changelog#51
Browse files Browse the repository at this point in the history
  • Loading branch information
escapedcat committed Oct 5, 2018
1 parent 0cf1473 commit 5eb8bcf
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions @commitlint/prompt-cli/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
const execa = require('execa');
const meow = require('meow');
const prompter = require('@commitlint/prompt').prompter;
const {prompter} = require('@commitlint/prompt');

const HELP = `
Usage
Expand All @@ -17,10 +17,22 @@ main(meow(HELP)).catch(err => {
});
});

function main() {
async function main() {
if (await isStageEmpty()) {
console.log(
`Nothing to commit. Stage your changes via "git add" execute "commit" again`
);
process.exit(1);
}

return prompt();
}

async function isStageEmpty() {
const result = await execa('git', ['diff', '--cached']);
return result.stdout === '';
}

function commit(message) {
const c = execa('git', ['commit', '-m', message]);
c.stdout.pipe(process.stdout);
Expand Down

0 comments on commit 5eb8bcf

Please sign in to comment.