File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed
Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change 1- import { platform } from 'os' ;
21import execa from 'execa' ;
2+ import isGit from 'is-git-repository' ;
3+ import { platform } from 'os' ;
4+ import path from 'path' ;
5+ import pathIsAbsolute from 'path-is-absolute' ;
6+
37
48const cwd = process . cwd ( ) ;
59
610const commitCount = ( altPath = cwd ) => {
711 let count = 0 ;
812 let obj = { } ;
913
14+ const thisPath = pathIsAbsolute ( altPath ) ? altPath : path . join ( cwd , altPath ) ;
15+
16+ if ( ! isGit ( thisPath ) ) {
17+ return - 1 ;
18+ }
19+
1020 try {
1121 if ( platform ( ) === 'win32' ) {
12- obj = execa . shellSync ( `pushd ${ altPath } & git rev-list --all --count` ) ;
22+ obj = execa . shellSync ( `pushd ${ thisPath } & git rev-list --all --count` ) ;
1323 } else {
14- obj = execa . shellSync ( `(cd ${ altPath } ; git rev-list --all --count)` ) ;
24+ obj = execa . shellSync ( `(cd ${ thisPath } ; git rev-list --all --count)` ) ;
1525 }
1626
1727 count = parseInt ( obj . stdout , 10 ) ;
1828
1929 return count ;
2030 } catch ( e ) {
21- const error = e . toString ( ) . substring ( 0 , 12 ) ;
22-
23- if ( error === 'Error: usage' ) {
24- return count ;
25- }
26-
27- return - 1 ;
31+ return 0 ;
2832 }
2933} ;
3034
You can’t perform that action at this time.
0 commit comments