@@ -86,7 +86,7 @@ export class GitWorkflow {
8686 failOnChanges,
8787 gitConfigDir,
8888 logger,
89- matchedFileChunks ,
89+ matchedFiles ,
9090 topLevelDir,
9191 } ) {
9292 this . execGit = ( args , options = { } ) => execGit ( args , { ...options , cwd : topLevelDir } )
@@ -96,8 +96,8 @@ export class GitWorkflow {
9696 this . gitConfigDir = gitConfigDir
9797 this . failOnChanges = ! ! failOnChanges
9898 this . logger = logger
99- /** @type {import('./getStagedFiles.js').StagedFile[][] } */
100- this . matchedFileChunks = matchedFileChunks
99+ /** @type {Set< import('./getStagedFiles.js').StagedFile> } */
100+ this . matchedFiles = matchedFiles
101101 this . topLevelDir = topLevelDir
102102
103103 /**
@@ -369,46 +369,43 @@ export class GitWorkflow {
369369 ? normalizePath ( process . env . GIT_INDEX_FILE )
370370 : process . env . GIT_INDEX_FILE
371371
372- /** Needs to be run serially because of locking Git operation */
373- for ( const files of this . matchedFileChunks ) {
374- const accessCheckedFiles = await Promise . allSettled (
375- files . map ( async ( f ) => {
376- if ( f . status === 'D' ) {
377- await fs . access ( f . filepath )
378- return f . filepath // File is no longer deleted and can be added
379- } else {
380- return f . filepath
381- }
382- } )
383- )
372+ const accessCheckedFiles = await Promise . allSettled (
373+ Array . from ( this . matchedFiles ) . map ( async ( f ) => {
374+ if ( f . status === 'D' ) {
375+ await fs . access ( f . filepath )
376+ return f . filepath // File is no longer deleted and can be added
377+ } else {
378+ return f . filepath
379+ }
380+ } )
381+ )
384382
385- const addableFiles = accessCheckedFiles . flatMap ( ( r ) =>
386- r . status === 'fulfilled' ? [ r . value ] : [ ]
387- )
383+ const addableFiles = accessCheckedFiles . flatMap ( ( r ) =>
384+ r . status === 'fulfilled' ? [ r . value ] : [ ]
385+ )
388386
389- debugLog ( 'Updating active Git index: %s' , activeIndexFile )
390- await this . execGit ( [ 'add' , '--' , ...addableFiles ] )
391- debugLog ( 'Done updating Git index: %s' , activeIndexFile )
387+ debugLog ( 'Updating active Git index: %s' , activeIndexFile )
388+ await this . execGit ( [ 'add' , '--' , ...addableFiles ] )
389+ debugLog ( 'Done updating Git index: %s' , activeIndexFile )
392390
393- if ( activeIndexFile ?. endsWith ( '.lock' ) ) {
394- const defaultIndexLock = normalizePath (
395- await this . execGit ( [ 'rev-parse' , '--path-format=absolute' , '--git-path' , 'index.lock' ] )
396- )
391+ if ( activeIndexFile ?. endsWith ( '.lock' ) ) {
392+ const defaultIndexLock = normalizePath (
393+ await this . execGit ( [ 'rev-parse' , '--path-format=absolute' , '--git-path' , 'index.lock' ] )
394+ )
397395
398- /**
399- * If the active index file is a non-default lockfile, we are committing with a pathspec
400- * without having explicitly run `git add`. In this case we need to also update the
401- * default index, otherwise there will be leftover diff after committing
402- */
403- if ( activeIndexFile !== defaultIndexLock ) {
404- debugLog ( 'Updating default Git index again: %s' , defaultIndexLock )
405- await this . execGit ( [ 'add' , '--' , ...addableFiles ] , {
406- env : {
407- GIT_INDEX_FILE : defaultIndexLock ,
408- } ,
409- } )
410- debugLog ( 'Done updating default Git index lock: %s' , defaultIndexLock )
411- }
396+ /**
397+ * If the active index file is a non-default lockfile, we are committing with a pathspec
398+ * without having explicitly run `git add`. In this case we need to also update the
399+ * default index, otherwise there will be leftover diff after committing
400+ */
401+ if ( activeIndexFile !== defaultIndexLock ) {
402+ debugLog ( 'Updating default Git index again: %s' , defaultIndexLock )
403+ await this . execGit ( [ 'add' , '--' , ...addableFiles ] , {
404+ env : {
405+ GIT_INDEX_FILE : defaultIndexLock ,
406+ } ,
407+ } )
408+ debugLog ( 'Done updating default Git index lock: %s' , defaultIndexLock )
412409 }
413410 }
414411
0 commit comments