From 15e706b72e0060aff6ceac288c97dc3c493e5617 Mon Sep 17 00:00:00 2001 From: James Ives Date: Fri, 17 May 2024 16:12:21 +0000 Subject: [PATCH] =?UTF-8?q?Deploy=20Production=20Code=20for=20Commit=208a3?= =?UTF-8?q?08cc68c116ab6cb71c54636b866f23569ce81=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/worktree.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/worktree.js b/lib/worktree.js index c89d1577e..a5f0468cb 100644 --- a/lib/worktree.js +++ b/lib/worktree.js @@ -50,7 +50,16 @@ function generateWorktree(action, worktreedir, branchExists) { if (branchExists) { yield (0, execute_1.execute)(`git fetch --no-recurse-submodules --depth=1 origin ${action.branch}`, action.workspace, action.silent); } - yield (0, execute_1.execute)(`git worktree add --no-checkout --detach ${worktreedir}`, action.workspace, action.silent); + // Check if the branch is already checked out in another worktree + try { + (0, child_process_1.execSync)(`git rev-parse --verify --quiet ${action.branch}`); + // If the command succeeds, the branch is already checked out + (0, core_1.info)(`Branch ${action.branch} is already checked out. Using existing worktree.`); + } + catch (error) { + // If the command fails, the branch is not checked out + yield (0, execute_1.execute)(`git worktree add --no-checkout --detach ${worktreedir}`, action.workspace, action.silent); + } const checkout = new GitCheckout(action.branch); if (branchExists) { // There's existing data on the branch to check out