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';
44import yargs from 'yargs' ;
55import inquirer from 'inquirer' ;
66import isGit from 'is-git-repository' ;
7+ import isAdded from 'is-git-added' ;
78import updateNotifier from 'update-notifier' ;
89
910import 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 } ` ;
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff 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+ } ) ;
Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments