From 1607ac70d5942487fb67e1d412d57868d8decca9 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Wed, 17 May 2023 19:33:16 -0600 Subject: [PATCH] fix: execute git config commands synchronously this fixes the following error I was running into: error: could not lock config file .git/config: File exists --- src/helpers/git.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/helpers/git.js b/src/helpers/git.js index 743c804..a3bd130 100644 --- a/src/helpers/git.js +++ b/src/helpers/git.js @@ -31,14 +31,18 @@ module.exports = new (class Git { } } - // Set config - this.config('user.name', gitUserName) - this.config('user.email', gitUserEmail) + // use a self-invoking async function to await promises inside a constructor + // this avoids git config lock errors which are triggered when multiple `git config` commands are run + (async () => { + // Set config + await this.config('user.name', gitUserName) + await this.config('user.email', gitUserEmail) - // Update the origin - if (githubToken) { - this.updateOrigin(`https://x-access-token:${githubToken}@${gitUrl}/${GITHUB_REPOSITORY}.git`) - } + // Update the origin + if (githubToken) { + await this.updateOrigin(`https://x-access-token:${githubToken}@${gitUrl}/${GITHUB_REPOSITORY}.git`) + } + })() } /**