@@ -11,14 +11,31 @@ import * as log from './logger';
11
11
import { Configuration , InputType , DiffyType } from './types' ;
12
12
import * as utils from './utils' ;
13
13
14
- function 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 } "` ) ;
14
+ const defaultArgs = [ '-M' , '-C' , 'HEAD' ] ;
15
+
16
+ function generateGitDiffArgs ( gitArgsArr : string [ ] , ignore : string [ ] ) : string [ ] {
17
+ const gitDiffArgs : string [ ] = [ 'diff' ] ;
18
+
19
+ if ( ! gitArgsArr . includes ( '--no-color' ) ) gitDiffArgs . push ( '--no-color' ) ;
18
20
19
- const diffCommand = `git diff ${ baseArgs . join ( ' ' ) } ${ colorArgs . join ( ' ' ) } ${ ignoreArgs . join ( ' ' ) } ` ;
21
+ if ( gitArgsArr . length === 0 ) Array . prototype . push . apply ( gitDiffArgs , defaultArgs ) ;
20
22
21
- return utils . execute ( diffCommand ) ;
23
+ Array . prototype . push . apply ( gitDiffArgs , gitArgsArr ) ;
24
+
25
+ if ( ignore . length > 0 ) {
26
+ if ( ! gitArgsArr . includes ( '--' ) ) gitDiffArgs . push ( '--' ) ;
27
+ Array . prototype . push . apply (
28
+ gitDiffArgs ,
29
+ ignore . map ( path => `:(exclude)${ path } ` ) ,
30
+ ) ;
31
+ }
32
+
33
+ return gitDiffArgs ;
34
+ }
35
+
36
+ function runGitDiff ( gitArgsArr : string [ ] , ignore : string [ ] ) : string {
37
+ const gitDiffArgs = generateGitDiffArgs ( gitArgsArr , ignore ) ;
38
+ return utils . execute ( 'git' , gitDiffArgs ) ;
22
39
}
23
40
24
41
function prepareHTML ( diffHTMLContent : string , config : Configuration ) : string {
0 commit comments