Skip to content

Commit

Permalink
fix: run git add for staged file chunks serially
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iiroj committed Apr 9, 2020
1 parent 630cd3c commit 69acfa3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/gitWorkflow.js
Expand Up @@ -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'])
Expand Down

0 comments on commit 69acfa3

Please sign in to comment.