File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -106,10 +106,11 @@ describe("getDiffFileList", () => {
106
106
jest . mock ( "child_process" ) . resetAllMocks ( ) ;
107
107
mockedChildProcess . execSync . mockReturnValueOnce ( Buffer . from ( diffFileList ) ) ;
108
108
const staged = false ;
109
+ expect ( mockedChildProcess . execSync ) . toHaveBeenCalledTimes ( 0 ) ;
109
110
const fileListA = getDiffFileList ( staged ) ;
110
111
const fileListB = getDiffFileList ( staged ) ;
111
112
112
- expect ( mockedChildProcess . execSync ) . toHaveBeenCalled ( ) ;
113
+ expect ( mockedChildProcess . execSync ) . toHaveBeenCalledTimes ( 1 ) ;
113
114
expect ( fileListA ) . toEqual (
114
115
[ "file1" , "file2" , "file3" ] . map ( ( p ) => path . resolve ( p ) )
115
116
) ;
@@ -119,6 +120,7 @@ describe("getDiffFileList", () => {
119
120
120
121
describe ( "getGitFileList" , ( ) => {
121
122
it ( "should get the list of committed files" , ( ) => {
123
+ mockedChildProcess . execSync . mockReturnValueOnce ( Buffer . from ( diffFileList ) ) ;
122
124
expect ( getGitFileList ( ) ) . toEqual (
123
125
[ "file1" , "file2" , "file3" ] . map ( ( p ) => path . resolve ( p ) )
124
126
) ;
Original file line number Diff line number Diff line change @@ -102,6 +102,27 @@ const hasCleanIndex = (filePath: string): boolean => {
102
102
return result ;
103
103
} ;
104
104
105
+ let untrackedFileListCache : string [ ] | undefined ;
106
+ const getUntrackedFileList = ( staged = false ) : string [ ] => {
107
+ if ( untrackedFileListCache === undefined ) {
108
+ const command = [ "git" , "ls-files" , "--exclude-standard" , "--others" ]
109
+ . filter ( Boolean )
110
+ . join ( " " ) ;
111
+
112
+ if ( staged === false ) {
113
+ untrackedFileListCache = child_process
114
+ . execSync ( command )
115
+ . toString ( )
116
+ . trim ( )
117
+ . split ( "\n" )
118
+ . map ( ( filePath ) => path . resolve ( filePath ) ) ;
119
+ } else {
120
+ untrackedFileListCache = [ ] ;
121
+ }
122
+ }
123
+ return untrackedFileListCache ;
124
+ } ;
125
+
105
126
const isHunkHeader = ( input : string ) => {
106
127
const hunkHeaderRE = / ^ @ @ [ ^ @ ] * @ @ / u;
107
128
return hunkHeaderRE . exec ( input ) ;
@@ -157,10 +178,11 @@ const getRangesForDiff = (diff: string): Range[] =>
157
178
} , [ ] ) ;
158
179
159
180
export {
181
+ getDiffFileList ,
160
182
getDiffForFile ,
161
183
getRangesForDiff ,
162
- getDiffFileList ,
163
184
getGitFileList ,
185
+ getUntrackedFileList ,
164
186
hasCleanIndex ,
165
187
} ;
166
188
export type { Range } ;
You can’t perform that action at this time.
0 commit comments