Skip to content

Commit

Permalink
fix: execute git config commands synchronously
Browse files Browse the repository at this point in the history
this fixes the following error I was running into:

error: could not lock config file .git/config: File exists
  • Loading branch information
iloveitaly committed May 18, 2023
1 parent acd95e2 commit 1607ac7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/helpers/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ module.exports = new (class Git {
}
}

// Set config
this.config('user.name', gitUserName)
this.config('user.email', gitUserEmail)

// Update the origin
if (githubToken) {
this.updateOrigin(`https://x-access-token:${githubToken}@${gitUrl}/${GITHUB_REPOSITORY}.git`)
}
// 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) {
await this.updateOrigin(`https://x-access-token:${githubToken}@${gitUrl}/${GITHUB_REPOSITORY}.git`)
}
})()
}

/**
Expand Down

0 comments on commit 1607ac7

Please sign in to comment.