From 69acfa3f0c270f088566d08b8dede0f04deafbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Thu, 9 Apr 2020 13:01:15 +0300 Subject: [PATCH] fix: run `git add` for staged file chunks serially This prevents race conditions with `git add` locking the repository. This mostly affects Windows users because on other platforms there is typically only one chunk. --- lib/gitWorkflow.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/gitWorkflow.js b/lib/gitWorkflow.js index 2d2822dcd..56f3d2b0d 100644 --- a/lib/gitWorkflow.js +++ b/lib/gitWorkflow.js @@ -235,11 +235,12 @@ class GitWorkflow { */ async applyModifications(ctx) { debug('Adding task modifications to index...') - await Promise.all( - // stagedFileChunks includes staged files that lint-staged originally detected. - // Add only these files so any 3rd-party edits to other files won't be included in the commit. - this.stagedFileChunks.map(stagedFiles => this.execGit(['add', '--', ...stagedFiles])) - ) + // stagedFileChunks includes staged files that lint-staged originally detected. + // Add only these files so any 3rd-party edits to other files won't be included in the commit. + // This is run "serially" to prevent race conditions because `git add` is a locking operation. + for (const stagedFiles of this.stagedFileChunks) { + await this.execGit(['add', '--', ...stagedFiles]) + } debug('Done adding task modifications to index!') const stagedFilesAfterAdd = await this.execGit(['diff', '--name-only', '--cached'])