File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 2 files changed +11
-1
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 @@ -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+ } ) ;
You can’t perform that action at this time.
0 commit comments