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(