@@ -11,14 +11,28 @@ import * as log from './logger';
11
11
import { Configuration , InputType , DiffyType } from './types' ;
12
12
import * as utils from './utils' ;
13
13
14
+ const defaultArgs = [ '-M' , '-C' , 'HEAD' ] ;
15
+
14
16
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 } "` ) ;
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 ) ;
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
+ ) ;
20
34
21
- return utils . execute ( diffCommand ) ;
35
+ return utils . execute ( 'git' , gitDiffArgs ) ;
22
36
}
23
37
24
38
function prepareHTML ( diffHTMLContent : string , config : Configuration ) : string {
0 commit comments