From ad7c547b7a8facb92af06a8eabddbbf18dc0f8fe Mon Sep 17 00:00:00 2001 From: James Ives Date: Sun, 29 Sep 2024 11:42:16 -0400 Subject: [PATCH] Squashed commit of the following: commit 6cf6f9c3a23c4e193b5577c5d394f1907917be56 Author: James Ives Date: Sun Sep 29 11:41:55 2024 -0400 fix: update tracking commit 9bb8292089d6689e4c2f1cff06a12062a1253333 Author: James Ives Date: Sun Sep 29 11:38:22 2024 -0400 Update worktree.ts commit 6d0725ee1fda4693075ef3b94894ba2b5b8c67c5 Author: James Ives Date: Sun Sep 29 11:36:04 2024 -0400 Update worktree.ts commit f24119c6ee0d5a1ad456b9a488027ad722ff68ba Author: James Ives Date: Sun Sep 29 11:32:45 2024 -0400 Update worktree.ts commit a93ccc90d20c86e02f03382e8571020277cb975f Author: James Ives Date: Sun Sep 29 11:30:49 2024 -0400 Update worktree.ts commit 422f948045898c857e455d269f4e80bf9cf3f6cb Author: James Ives Date: Sun Sep 29 11:28:54 2024 -0400 Update worktree.ts commit 84c87e3ecaf6ac7f021dd090b9db1eea9ddc395a Author: James Ives Date: Sun Sep 29 11:23:48 2024 -0400 Update worktree.ts commit 3b0b9cbdafb0429708c19982c9e70ce61d79df9f Author: James Ives Date: Sun Sep 29 11:16:43 2024 -0400 Update build.yml commit f1cf93b8e951499d7aa52483ff5ac18837702001 Author: James Ives Date: Sun Sep 29 11:11:58 2024 -0400 Update worktree.ts --- .github/workflows/build.yml | 3 +-- __tests__/git.test.ts | 2 +- src/worktree.ts | 48 +++++++++++++++++++++++-------------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a3398dfa9..aa06d99aa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -113,8 +113,7 @@ jobs: - name: Tweak content to publish to existing branch if: ${{ matrix.branch == 'gh-pages' }} run: | - RANDOM_CHAR=$(echo $RANDOM | tr -dc 'a-zA-Z0-9' | fold -w 1 | head -n 1) - echo "" >> integration/index.html + echo "" >> integration/index.html - name: Deploy with modifications to existing branch id: modified diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index e7b76c1d8..9aba5c36c 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -239,7 +239,7 @@ describe('git', () => { await deploy(action) // Includes the call to generateWorktree - expect(execute).toHaveBeenCalledTimes(13) + expect(execute).toHaveBeenCalledTimes(14) expect(rmRF).toHaveBeenCalledTimes(1) }) diff --git a/src/worktree.ts b/src/worktree.ts index ec94670c6..d5040730a 100644 --- a/src/worktree.ts +++ b/src/worktree.ts @@ -100,14 +100,26 @@ export async function generateWorktree( info( 'Error encountered while checking out branch. Attempting to continue with a new branch name.' ) + branchName = `temp-${Date.now()}` - checkout = new GitCheckout(branchName) - await execute( - checkout.toString(), - `${action.workspace}/${worktreedir}`, - action.silent - ) + try { + checkout = new GitCheckout(branchName, `origin/${action.branch}`) + await execute( + checkout.toString(), + `${action.workspace}/${worktreedir}`, + action.silent + ) + } catch (error) { + info('Unable to track the origin branch…') + + checkout = new GitCheckout(branchName) + await execute( + checkout.toString(), + `${action.workspace}/${worktreedir}`, + action.silent + ) + } } if (!branchExists) { @@ -128,19 +140,19 @@ export async function generateWorktree( action.silent ) } + } - /** - * Ensure that the workspace is a safe directory. - */ - try { - await execute( - `git config --global --add safe.directory "${action.workspace}/${worktreedir}"`, - action.workspace, - action.silent - ) - } catch { - info('Unable to set worktree temp directory as a safe directory…') - } + /** + * Ensure that the workspace is a safe directory. + */ + try { + await execute( + `git config --global --add safe.directory "${action.workspace}/${worktreedir}"`, + action.workspace, + action.silent + ) + } catch { + info('Unable to set worktree temp directory as a safe directory…') } } catch (error) { throw new Error(