File tree Expand file tree Collapse file tree 5 files changed +21
-5
lines changed Expand file tree Collapse file tree 5 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import execa from 'execa';
4
4
import yargs from 'yargs' ;
5
5
import inquirer from 'inquirer' ;
6
6
import isGit from 'is-git-repository' ;
7
+ import isAdded from 'is-git-added' ;
7
8
import updateNotifier from 'update-notifier' ;
8
9
9
10
import pkg from '../package.json' ;
@@ -27,6 +28,8 @@ if (argv.v) {
27
28
console . log ( `v${ pkg . version } ` ) ;
28
29
} else if ( ! isGit ( ) ) {
29
30
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.' ) ) ;
30
33
} else {
31
34
inquirer . prompt ( questionsList ) . then ( ( answers ) => {
32
35
const message = answers . moreInfo ? `${ answers . editor } ` : `${ answers . type } ${ answers . description } ` ;
Original file line number Diff line number Diff line change @@ -33,9 +33,7 @@ const questions = (choicesList) => {
33
33
validate : ( input ) => {
34
34
const warnings = ruleWarningMessages ( input ) ;
35
35
36
- if ( warnings ) return warnings ;
37
-
38
- return true ;
36
+ return warnings || true ;
39
37
} ,
40
38
} ,
41
39
{
Original file line number Diff line number Diff line change 65
65
"chalk" : " ^1.1.3" ,
66
66
"execa" : " ^0.6.1" ,
67
67
"inquirer" : " ^3.0.6" ,
68
+ "is-git-added" : " ^1.0.1" ,
68
69
"is-git-repository" : " ^1.0.1" ,
69
70
"json-extra" : " ^0.5.0" ,
70
71
"object.entries" : " ^1.0.4" ,
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ test('should print the right version', async (t) => {
13
13
t . is ( stdout , `v${ pkg . version } ` ) ;
14
14
} ) ;
15
15
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 ) => {
17
18
// assume that the homedir is not a git repo
18
19
process . chdir ( homedir ( ) ) ;
19
20
@@ -24,3 +25,9 @@ test('should fail on non git repository', async (t) => {
24
25
t . is ( stderr , 'fatal: Not a git repository (or any of the parent directories): .git' ) ;
25
26
} ) ;
26
27
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
+ } ) ;
Original file line number Diff line number Diff line change @@ -2217,7 +2217,14 @@ is-generator-fn@^1.0.0:
2217
2217
version "1.0.0"
2218
2218
resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-1.0.0.tgz#969d49e1bb3329f6bb7f09089be26578b2ddd46a"
2219
2219
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 :
2221
2228
version "1.0.1"
2222
2229
resolved "https://registry.yarnpkg.com/is-git-repository/-/is-git-repository-1.0.1.tgz#db80512b6ce8db3fa90c84292a7b525e427f5746"
2223
2230
dependencies :
You can’t perform that action at this time.
0 commit comments