From d15eaafe15b85b9eacdf39ff019c9b8f51735f7f Mon Sep 17 00:00:00 2001 From: Davi Rodrigues Date: Tue, 10 Mar 2026 12:23:39 -0300 Subject: [PATCH] fix(MORG-52): avoid checkout to base branch when starting from a worktree When on a worktree branch and running `morg start `, the previous code tried to `git checkout ` which fails because the base is already checked out in the main worktree. Use `fetchAndUpdateBranch(base)` to update the local ref without checking out, then create the new branch explicitly from that ref via `checkout(name, true, base)`. --- src/commands/start.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/commands/start.ts b/src/commands/start.ts index 8781868..d8cd5ef 100644 --- a/src/commands/start.ts +++ b/src/commands/start.ts @@ -106,17 +106,20 @@ export async function runStart( await withSpinner(`Switching to ${branchName}...`, () => checkout(branchName)); } } else { - // Switch to base, pull it, then create the new branch from it if (currentBranch !== base) { await handleDirtyTree(currentBranch, branchName); - await withSpinner(`Switching to ${base}...`, () => checkout(base)); - } - try { - await withSpinner(`Pulling ${base}...`, () => pullBranch(base)); - } catch { - console.log(theme.warning(` ${symbols.warning} Could not pull ${base} — using local`)); + const updated = await fetchAndUpdateBranch(base); + if (!updated) { + console.log(theme.warning(` ${symbols.warning} Could not update ${base} — using local`)); + } + } else { + try { + await withSpinner(`Pulling ${base}...`, () => pullBranch(base)); + } catch { + console.log(theme.warning(` ${symbols.warning} Could not pull ${base} — using local`)); + } } - await withSpinner(`Creating branch ${branchName}...`, () => checkout(branchName, true)); + await withSpinner(`Creating branch ${branchName}...`, () => checkout(branchName, true, base)); } console.log(theme.success(`\n${symbols.success} On branch ${theme.primaryBold(branchName)}`)); }