@@ -80,28 +80,36 @@ function gitLsTree(path: string): Map<string, string> {
80
80
return parseGitLsTree ( spawnProcess ( 'git' , [ 'ls-tree' , 'HEAD' , '-r' ] , path ) ) ;
81
81
}
82
82
83
- function gitStatus ( path : string ) : Map < string , string > {
83
+ function gitStatus (
84
+ path : string
85
+ ) : { status : Map < string , string > ; deletedFiles : string [ ] } {
86
+ const deletedFiles : string [ ] = [ ] ;
84
87
const filesToHash : string [ ] = [ ] ;
85
88
parseGitStatus (
86
89
spawnProcess ( 'git' , [ 'status' , '-s' , '-u' , '.' ] , path )
87
90
) . forEach ( ( changeType : string , filename : string ) => {
88
91
if ( changeType !== 'D' ) {
89
92
filesToHash . push ( filename ) ;
93
+ } else {
94
+ deletedFiles . push ( filename ) ;
90
95
}
91
96
} ) ;
92
- return getGitHashForFiles ( filesToHash , path ) ;
97
+ const status = getGitHashForFiles ( filesToHash , path ) ;
98
+ return { deletedFiles, status } ;
93
99
}
94
100
95
101
export function getFileHashes ( path : string ) : Map < string , string > {
96
102
const res = new Map < string , string > ( ) ;
97
103
98
104
try {
105
+ const { deletedFiles, status } = gitStatus ( path ) ;
99
106
const m1 = gitLsTree ( path ) ;
100
107
m1 . forEach ( ( hash : string , filename : string ) => {
101
- res . set ( `${ path } /${ filename } ` , hash ) ;
108
+ if ( deletedFiles . indexOf ( filename ) === - 1 ) {
109
+ res . set ( `${ path } /${ filename } ` , hash ) ;
110
+ }
102
111
} ) ;
103
- const m2 = gitStatus ( path ) ;
104
- m2 . forEach ( ( hash : string , filename : string ) => {
112
+ status . forEach ( ( hash : string , filename : string ) => {
105
113
res . set ( `${ path } /${ filename } ` , hash ) ;
106
114
} ) ;
107
115
return res ;
0 commit comments