From bbaccba5e4e463aaa11181bd602ad2eaceb98c19 Mon Sep 17 00:00:00 2001 From: James Ives Date: Fri, 17 May 2024 22:07:12 -0400 Subject: [PATCH] Update worktree.ts --- src/worktree.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/worktree.ts b/src/worktree.ts index 62d27f154..deaa5d8e0 100644 --- a/src/worktree.ts +++ b/src/worktree.ts @@ -40,12 +40,22 @@ export async function generateWorktree( ) } - await execute( - `git worktree remove ${worktreedir}`, + // Check if the worktree already exists + const {stdout: worktreeList} = await execute( + `git worktree list`, action.workspace, action.silent ) + // If the worktree exists, remove it + if (worktreeList.includes(worktreedir)) { + await execute( + `git worktree remove ${worktreedir}`, + action.workspace, + action.silent + ) + } + await execute( `git worktree add --no-checkout --detach ${worktreedir}`, action.workspace,