Skip to content

Commit 3326e5c

Browse files
authored
Merge pull request #24 from JPeer264/feature/detectnonadded
Fail non added
2 parents c005eb0 + 5026299 commit 3326e5c

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
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}`;

lib/promptConfig.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ const questions = (choicesList) => {
3333
validate: (input) => {
3434
const warnings = ruleWarningMessages(input);
3535

36-
if (warnings) return warnings;
37-
38-
return true;
36+
return warnings || true;
3937
},
4038
},
4139
{

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"chalk": "^1.1.3",
6666
"execa": "^0.6.1",
6767
"inquirer": "^3.0.6",
68+
"is-git-added": "^1.0.1",
6869
"is-git-repository": "^1.0.1",
6970
"json-extra": "^0.5.0",
7071
"object.entries": "^1.0.4",

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+
});

yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,14 @@ is-generator-fn@^1.0.0:
22172217
version "1.0.0"
22182218
resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-1.0.0.tgz#969d49e1bb3329f6bb7f09089be26578b2ddd46a"
22192219

2220-
is-git-repository@^1.0.1:
2220+
is-git-added@^1.0.1:
2221+
version "1.0.1"
2222+
resolved "https://registry.yarnpkg.com/is-git-added/-/is-git-added-1.0.1.tgz#d4a911f057488dd9c4e1b659c495295f448aec4e"
2223+
dependencies:
2224+
execa "^0.6.1"
2225+
is-git-repository "^1.0.0"
2226+
2227+
is-git-repository@^1.0.0, is-git-repository@^1.0.1:
22212228
version "1.0.1"
22222229
resolved "https://registry.yarnpkg.com/is-git-repository/-/is-git-repository-1.0.1.tgz#db80512b6ce8db3fa90c84292a7b525e427f5746"
22232230
dependencies:

0 commit comments

Comments
 (0)