@@ -66,6 +66,46 @@ describe("getDiffForFile", () => {
66
66
expect ( diffFromFile ) . toContain ( "diff --git" ) ;
67
67
expect ( diffFromFile ) . toContain ( "@@" ) ;
68
68
} ) ;
69
+
70
+ it ( "should work when using staged = false" , ( ) => {
71
+ mockedChildProcess . execFileSync . mockReturnValueOnce ( Buffer . from ( hunks ) ) ;
72
+ process . env . ESLINT_PLUGIN_DIFF_COMMIT = "1234567" ;
73
+
74
+ const diffFromFile = getDiffForFile ( "./mockfile.js" , false ) ;
75
+
76
+ const expectedCommand = "git" ;
77
+ const expectedArgs =
78
+ "diff --diff-algorithm=histogram --diff-filter=ACM --find-renames=100% --no-ext-diff --relative --unified=0 1234567" ;
79
+
80
+ const lastCall = mockedChildProcess . execFileSync . mock . calls . at ( - 1 ) ;
81
+ const [ command , argsIncludingFile = [ ] ] = lastCall ?? [ "" ] ;
82
+ const args = argsIncludingFile . slice ( 0 , - 2 ) ;
83
+
84
+ expect ( command ) . toBe ( expectedCommand ) ;
85
+ expect ( args . join ( " " ) ) . toEqual ( expectedArgs ) ;
86
+ expect ( diffFromFile ) . toContain ( "diff --git" ) ;
87
+ expect ( diffFromFile ) . toContain ( "@@" ) ;
88
+ } ) ;
89
+
90
+ it ( "should use HEAD when no commit was defined" , ( ) => {
91
+ mockedChildProcess . execFileSync . mockReturnValueOnce ( Buffer . from ( hunks ) ) ;
92
+ process . env . ESLINT_PLUGIN_DIFF_COMMIT = undefined ;
93
+
94
+ const diffFromFile = getDiffForFile ( "./mockfile.js" , false ) ;
95
+
96
+ const expectedCommand = "git" ;
97
+ const expectedArgs =
98
+ "diff --diff-algorithm=histogram --diff-filter=ACM --find-renames=100% --no-ext-diff --relative --unified=0 HEAD" ;
99
+
100
+ const lastCall = mockedChildProcess . execFileSync . mock . calls . at ( - 1 ) ;
101
+ const [ command , argsIncludingFile = [ ] ] = lastCall ?? [ "" ] ;
102
+ const args = argsIncludingFile . slice ( 0 , - 2 ) ;
103
+
104
+ expect ( command ) . toBe ( expectedCommand ) ;
105
+ expect ( args . join ( " " ) ) . toEqual ( expectedArgs ) ;
106
+ expect ( diffFromFile ) . toContain ( "diff --git" ) ;
107
+ expect ( diffFromFile ) . toContain ( "@@" ) ;
108
+ } ) ;
69
109
} ) ;
70
110
71
111
describe ( "hasCleanIndex" , ( ) => {
@@ -93,7 +133,7 @@ describe("getDiffFileList", () => {
93
133
Buffer . from ( diffFileList )
94
134
) ;
95
135
expect ( mockedChildProcess . execFileSync ) . toHaveBeenCalledTimes ( 0 ) ;
96
- const fileListA = getDiffFileList ( ) ;
136
+ const fileListA = getDiffFileList ( false ) ;
97
137
98
138
expect ( mockedChildProcess . execFileSync ) . toHaveBeenCalledTimes ( 1 ) ;
99
139
expect ( fileListA ) . toEqual (
@@ -109,7 +149,7 @@ describe("getUntrackedFileList", () => {
109
149
Buffer . from ( diffFileList )
110
150
) ;
111
151
expect ( mockedChildProcess . execFileSync ) . toHaveBeenCalledTimes ( 0 ) ;
112
- const fileListA = getUntrackedFileList ( ) ;
152
+ const fileListA = getUntrackedFileList ( false ) ;
113
153
expect ( mockedChildProcess . execFileSync ) . toHaveBeenCalledTimes ( 1 ) ;
114
154
115
155
mockedChildProcess . execFileSync . mockReturnValueOnce (
0 commit comments