@@ -10,6 +10,14 @@ import { normalize_path } from './normalize-path'
1010export namespace CommitMessageDetails {
1111 const COMMIT_MESSAGE_DETAILS_FILENAME = 'commit-message-details.json'
1212
13+ const is_existing_file = ( abs_path : string ) : boolean => {
14+ try {
15+ return fs . statSync ( abs_path ) . isFile ( )
16+ } catch {
17+ return false
18+ }
19+ }
20+
1321 export type Prompt = {
1422 prompt : string
1523 files : string [ ]
@@ -189,7 +197,10 @@ export namespace CommitMessageDetails {
189197
190198 const filtered_files = p . files . filter ( filter_fn )
191199 const filtered_selected_files = ( p . selected_files || [ ] ) . filter (
192- filter_fn
200+ ( f ) => {
201+ const abs_path = path . isAbsolute ( f ) ? f : path . join ( root , f )
202+ return is_existing_file ( abs_path )
203+ }
193204 )
194205
195206 if (
@@ -266,17 +277,17 @@ export namespace CommitMessageDetails {
266277
267278 all_prompts [ workspace_root ] = all_prompts [ workspace_root ]
268279 . map ( ( p ) => {
269- const filter_fn = ( f : string ) => {
280+ const filtered_files = p . files . filter ( ( f ) => {
270281 const rel_path = path . isAbsolute ( f )
271282 ? normalize_path ( path . relative ( workspace_root , f ) )
272283 : normalize_path ( f )
273284 return current_changes . has ( rel_path )
274- }
285+ } )
275286
276- const filtered_files = p . files . filter ( filter_fn )
277- const filtered_selected_files = ( p . selected_files || [ ] ) . filter (
278- filter_fn
279- )
287+ const filtered_selected_files = ( p . selected_files || [ ] ) . filter ( ( f ) => {
288+ const abs_path = path . isAbsolute ( f ) ? f : path . join ( workspace_root , f )
289+ return is_existing_file ( abs_path )
290+ } )
280291
281292 if (
282293 filtered_files . length !== p . files . length ||
@@ -331,19 +342,21 @@ export namespace CommitMessageDetails {
331342
332343 all_prompts [ params . workspace_root ] = all_prompts [ params . workspace_root ]
333344 . map ( ( p ) => {
334- if ( ! prompt_set . has ( p . prompt ) ) return p
335-
336- const filter_fn = ( f : string ) => {
337- const rel_path = path . isAbsolute ( f )
338- ? normalize_path ( path . relative ( params . workspace_root , f ) )
339- : normalize_path ( f )
340- return ! committed_set . has ( rel_path )
341- }
342-
343- const filtered_files = p . files . filter ( filter_fn )
344- const filtered_selected_files = ( p . selected_files || [ ] ) . filter (
345- filter_fn
346- )
345+ const filtered_files = prompt_set . has ( p . prompt )
346+ ? p . files . filter ( ( f ) => {
347+ const rel_path = path . isAbsolute ( f )
348+ ? normalize_path ( path . relative ( params . workspace_root , f ) )
349+ : normalize_path ( f )
350+ return ! committed_set . has ( rel_path )
351+ } )
352+ : p . files
353+
354+ const filtered_selected_files = ( p . selected_files || [ ] ) . filter ( ( f ) => {
355+ const abs_path = path . isAbsolute ( f )
356+ ? f
357+ : path . join ( params . workspace_root , f )
358+ return is_existing_file ( abs_path )
359+ } )
347360
348361 if (
349362 filtered_files . length !== p . files . length ||
0 commit comments