From 58922ea1d130b2ae484a795f8e53c7b49b1cfb7b Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 22 Nov 2021 15:14:45 -0700 Subject: [PATCH] fix: only set git config if does not exist --- src/commands/cli/latestrc/build.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/commands/cli/latestrc/build.ts b/src/commands/cli/latestrc/build.ts index 33b985b13..2092e8224 100644 --- a/src/commands/cli/latestrc/build.ts +++ b/src/commands/cli/latestrc/build.ts @@ -63,11 +63,7 @@ export default class build extends SfdxCommand { this.exec('yarn snapshot-generate'); - const user = await octokit.request('GET /user'); - - // required for committing in Circle - this.exec(`git config user.email "${user.data.email}"`); - this.exec(`git config user.name "${user.data.name}"`); + await this.maybeSetGitConfig(octokit); // commit package.json/yarn.lock and potentially command-snapshot changes this.exec('git add .'); @@ -91,4 +87,14 @@ export default class build extends SfdxCommand { this.log(bold(cmd)); exec(cmd, options); } + + private async maybeSetGitConfig(octokit: Octokit): Promise { + const username = exec('git config user.name', { silent: true }).stdout.trim(); + const email = exec('git config user.email', { silent: true }).stdout.trim(); + if (!username || !email) { + const user = await octokit.request('GET /user'); + if (!username) this.exec(`git config user.name "${user.data.name}"`); + if (!email) this.exec(`git config user.email "${user.data.email}"`); + } + } }