From b22f2e67d3caa659974348de97e390d55fc81476 Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 27 Apr 2022 06:44:37 -0400 Subject: [PATCH 1/4] Update git.ts --- src/git.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/git.ts b/src/git.ts index cab1061b..9ea6aa04 100644 --- a/src/git.ts +++ b/src/git.ts @@ -31,15 +31,12 @@ export async function init(action: ActionInterface): Promise { attempt++ if (attempt > ATTEMPT_LIMIT) { - throw new Error(); + throw new Error() } if (attempt > 1) { - await execute( - `git init`, - action.workspace, - action.silent - ) + // Handles the 'fatal: not a git directory' error. + await execute(`git init`, action.workspace, action.silent) await execute( `git commit -m "Initial commit" --allow-empty`, @@ -59,20 +56,20 @@ export async function init(action: ActionInterface): Promise { action.workspace, action.silent ) - + await execute( `git config user.email "${action.email}"`, action.workspace, action.silent ) - + await execute( `git config core.ignorecase false`, action.workspace, action.silent ) - } while(rejected) - + } while (rejected) + try { if ((process.env.CI && !action.sshKey) || action.isTest) { /* Ensures that previously set Git configs do not interfere with the deployment. From 47dc1b7ba18c224169a48e435e7267cf3912f0cc Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 27 Apr 2022 06:44:58 -0400 Subject: [PATCH 2/4] Init emp From 27811f4b80f414b5ab4ab589cb584f51591bd386 Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 27 Apr 2022 06:54:42 -0400 Subject: [PATCH 3/4] Update git.ts --- src/git.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/git.ts b/src/git.ts index 9ea6aa04..3a4cf1cb 100644 --- a/src/git.ts +++ b/src/git.ts @@ -25,7 +25,6 @@ export async function init(action: ActionInterface): Promise { const ATTEMPT_LIMIT = 2 let attempt = 0 - let rejected = false do { attempt++ @@ -68,7 +67,7 @@ export async function init(action: ActionInterface): Promise { action.workspace, action.silent ) - } while (rejected) + } while (attempt < ATTEMPT_LIMIT) try { if ((process.env.CI && !action.sshKey) || action.isTest) { From afcfd7b3a1d9051aeb11760a5a68cabb395ad56b Mon Sep 17 00:00:00 2001 From: James Ives Date: Wed, 27 Apr 2022 07:00:20 -0400 Subject: [PATCH 4/4] Update git.ts --- src/git.ts | 73 +++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/src/git.ts b/src/git.ts index 3a4cf1cb..8f689d4e 100644 --- a/src/git.ts +++ b/src/git.ts @@ -21,53 +21,52 @@ export async function init(action: ActionInterface): Promise { info(`Deploying using ${action.tokenType}… 🔑`) info('Configuring git…') - // Keep trying to configure Git with various different methods until it works with a maximum of 2 attempts. - const ATTEMPT_LIMIT = 2 - - let attempt = 0 - - do { - attempt++ - - if (attempt > ATTEMPT_LIMIT) { - throw new Error() - } - - if (attempt > 1) { - // Handles the 'fatal: not a git directory' error. - await execute(`git init`, action.workspace, action.silent) - + async function configureGit(throwOnError: boolean) { + try { await execute( - `git commit -m "Initial commit" --allow-empty`, + `git config --global --add safe.directory "${action.workspace}"`, action.workspace, action.silent ) + + await execute( + `git config user.name "${action.name}"`, + action.workspace, + action.silent + ) + + await execute( + `git config user.email "${action.email}"`, + action.workspace, + action.silent + ) + + await execute( + `git config core.ignorecase false`, + action.workspace, + action.silent + ) + } catch { + if (throwOnError) { + throw new Error() + } } + } + + try { + await configureGit(false) + } catch { + // Attempt to re-run if initial configuration failed using git init. + await execute(`git init`, action.workspace, action.silent) await execute( - `git config --global --add safe.directory "${action.workspace}"`, + `git commit -m "Initial commit" --allow-empty`, action.workspace, action.silent ) - - await execute( - `git config user.name "${action.name}"`, - action.workspace, - action.silent - ) - - await execute( - `git config user.email "${action.email}"`, - action.workspace, - action.silent - ) - - await execute( - `git config core.ignorecase false`, - action.workspace, - action.silent - ) - } while (attempt < ATTEMPT_LIMIT) + + await configureGit(true) + } try { if ((process.env.CI && !action.sshKey) || action.isTest) {