File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 22import chalk from 'chalk' ;
33import execa from 'execa' ;
44import yargs from 'yargs' ;
5+ import git from 'git-utils' ;
56import inquirer from 'inquirer' ;
67import updateNotifier from 'update-notifier' ;
78
89import pkg from '../package.json' ;
910import getConfig from './getConfig' ;
1011import { choices , questions } from './promptConfig' ;
1112
13+ const repository = git . open ( process . cwd ( ) ) ;
1214const configuration = getConfig ( ) ;
1315const choicesList = choices ( configuration ) ;
1416const questionsList = questions ( choicesList ) ;
@@ -24,6 +26,8 @@ updateNotifier({ pkg }).notify();
2426
2527if ( argv . v ) {
2628 console . log ( `v${ pkg . version } ` ) ;
29+ } else if ( ! repository ) {
30+ console . error ( 'fatal: Not a git repository (or any of the parent directories): .git' ) ;
2731} else {
2832 inquirer . prompt ( questionsList ) . then ( ( answers ) => {
2933 const message = answers . moreInfo ? `${ answers . editor } ` : `${ answers . type } ${ answers . description } ` ;
Original file line number Diff line number Diff line change 1+ import path from 'path' ;
2+ import test from 'ava' ;
3+ import execa from 'execa' ;
4+ import { homedir } from 'os' ;
5+
6+ import pkg from '../package.json' ;
7+
8+ const cli = 'dest/cli.js' ;
9+
10+ test ( 'should print the right version' , async ( t ) => {
11+ const { stdout } = await execa ( cli , [ '--version' ] ) ;
12+
13+ t . is ( stdout , `v${ pkg . version } ` ) ;
14+ } ) ;
15+
16+ test ( 'should fail on non git repository' , async ( t ) => {
17+ // assume that the homedir is not a git repo
18+ process . chdir ( homedir ( ) ) ;
19+
20+ const { stderr } = await execa ( path . join ( __dirname , '..' , cli ) ) ;
21+
22+ process . chdir ( path . join ( __dirname , '..' ) ) ;
23+
24+ t . is ( stderr , 'fatal: Not a git repository (or any of the parent directories): .git' ) ;
25+ } ) ;
26+
You can’t perform that action at this time.
0 commit comments