Skip to content

Commit fed34f0

Browse files
committed
✨ Feat: just run sgc if files are really added
1 parent ab20d9a commit fed34f0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/cli.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import execa from 'execa';
44
import yargs from 'yargs';
55
import inquirer from 'inquirer';
66
import isGit from 'is-git-repository';
7+
import isAdded from 'is-git-added';
78
import updateNotifier from 'update-notifier';
89

910
import pkg from '../package.json';
@@ -27,6 +28,8 @@ if (argv.v) {
2728
console.log(`v${pkg.version}`);
2829
} else if (!isGit()) {
2930
console.error('fatal: Not a git repository (or any of the parent directories): .git');
31+
} else if (!isAdded()) {
32+
console.error(chalk.red('Please', chalk.bold('git add'), 'some files first before you commit.'));
3033
} else {
3134
inquirer.prompt(questionsList).then((answers) => {
3235
const message = answers.moreInfo ? `${answers.editor}` : `${answers.type} ${answers.description}`;

test/cli.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ test('should print the right version', async (t) => {
1313
t.is(stdout, `v${pkg.version}`);
1414
});
1515

16-
test('should fail on non git repository', async (t) => {
16+
// make serial due to dynamic process.chdir switching
17+
test.serial('should fail on non git repository', async (t) => {
1718
// assume that the homedir is not a git repo
1819
process.chdir(homedir());
1920

@@ -24,3 +25,9 @@ test('should fail on non git repository', async (t) => {
2425
t.is(stderr, 'fatal: Not a git repository (or any of the parent directories): .git');
2526
});
2627

28+
test('should fail on git repos where nothing is added', async (t) => {
29+
// assume that the homedir is not a git repo
30+
const { stderr } = await execa(cli);
31+
32+
t.is(stderr, 'Please git add some files first before you commit.');
33+
});

0 commit comments

Comments
 (0)