Skip to content

Commit 5eb8bcf

Browse files
committed
feat(prompt-cli): check stage before prompt conventional-changelog#51
1 parent 0cf1473 commit 5eb8bcf

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

@commitlint/prompt-cli/cli.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
const execa = require('execa');
33
const meow = require('meow');
4-
const prompter = require('@commitlint/prompt').prompter;
4+
const {prompter} = require('@commitlint/prompt');
55

66
const HELP = `
77
Usage
@@ -17,10 +17,22 @@ main(meow(HELP)).catch(err => {
1717
});
1818
});
1919

20-
function main() {
20+
async function main() {
21+
if (await isStageEmpty()) {
22+
console.log(
23+
`Nothing to commit. Stage your changes via "git add" execute "commit" again`
24+
);
25+
process.exit(1);
26+
}
27+
2128
return prompt();
2229
}
2330

31+
async function isStageEmpty() {
32+
const result = await execa('git', ['diff', '--cached']);
33+
return result.stdout === '';
34+
}
35+
2436
function commit(message) {
2537
const c = execa('git', ['commit', '-m', message]);
2638
c.stdout.pipe(process.stdout);

0 commit comments

Comments
 (0)