@@ -11,14 +11,28 @@ import * as log from './logger';
1111import { Configuration , InputType , DiffyType } from './types' ;
1212import * as utils from './utils' ;
1313
14+ const defaultArgs = [ '-M' , '-C' , 'HEAD' ] ;
15+
1416function runGitDiff ( gitArgsArr : string [ ] , ignore : string [ ] ) : string {
15- const baseArgs = gitArgsArr . length > 0 ? gitArgsArr . map ( arg => `" ${ arg } "` ) : [ '-M' , '-C' , 'HEAD '] ;
16- const colorArgs = gitArgsArr . indexOf ( '--no-color' ) < 0 ? [ '--no-color' ] : [ ] ;
17- const ignoreArgs = ignore . map ( file => `":(exclude) ${ file } "` ) ;
17+ const gitDiffArgs : string [ ] = [ 'diff '] ;
18+
19+ if ( ! gitArgsArr . includes ( '--no-color' ) ) gitDiffArgs . push ( '--no-color' ) ;
1820
19- const diffCommand = `git diff ${ baseArgs . join ( ' ' ) } ${ colorArgs . join ( ' ' ) } ${ ignoreArgs . join ( ' ' ) } ` ;
21+ if ( gitArgsArr . length === 0 ) Array . prototype . push . apply ( gitDiffArgs , defaultArgs ) ;
22+
23+ Array . prototype . push . apply (
24+ gitDiffArgs ,
25+ gitArgsArr . map ( arg => `"${ arg } "` ) ,
26+ ) ;
27+
28+ if ( ! gitArgsArr . includes ( '--' ) ) gitDiffArgs . push ( '--' ) ;
29+
30+ Array . prototype . push . apply (
31+ gitDiffArgs ,
32+ ignore . map ( file => `":(exclude)${ file } "` ) ,
33+ ) ;
2034
21- return utils . execute ( diffCommand ) ;
35+ return utils . execute ( 'git' , gitDiffArgs ) ;
2236}
2337
2438function prepareHTML ( diffHTMLContent : string , config : Configuration ) : string {
0 commit comments