diff --git a/packages/worktree-cli/src/commands/dev.ts b/packages/worktree-cli/src/commands/dev.ts index 0819767..d996f37 100644 --- a/packages/worktree-cli/src/commands/dev.ts +++ b/packages/worktree-cli/src/commands/dev.ts @@ -113,7 +113,10 @@ function spawnService( }; const rawArgs = devArgs(svc); - const args = ['--filter', svc.pnpmFilter, 'dev', '--', ...rawArgs.map(interpolate)]; + // No `--` separator: with pnpm 9 + `"dev": "vite"`, inserting `--` + // causes vite to receive it as a literal argv entry (`vite -- --port NNN`) + // and silently ignore the port flag, falling back to its default. + const args = ['--filter', svc.pnpmFilter, 'dev', ...rawArgs.map(interpolate)]; const env = { ...process.env }; for (const [k, v] of Object.entries(svc.env ?? {})) { diff --git a/packages/worktree-cli/src/commands/setup.ts b/packages/worktree-cli/src/commands/setup.ts index 7a1c666..fb04af9 100644 --- a/packages/worktree-cli/src/commands/setup.ts +++ b/packages/worktree-cli/src/commands/setup.ts @@ -1,4 +1,4 @@ -import { execFileSync } from 'node:child_process'; +import { execFileSync, spawnSync } from 'node:child_process'; import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; import { dirname, resolve } from 'node:path'; @@ -25,11 +25,17 @@ export async function setup({ branch, cfg, repoRoot }: SetupOptions): Promise Creating worktree for '${branch}' at ${wtPath}...`)); - // Fetch origin/main from the main worktree; the new worktree branches from it. + // Fetch origin/main from the main worktree; a fresh worktree branches from it. execFileSync('git', ['-C', repoRoot, 'fetch', 'origin', 'main'], { stdio: 'inherit' }); - execFileSync('git', ['-C', repoRoot, 'worktree', 'add', '-b', branch, wtPath, 'origin/main'], { - stdio: 'inherit', - }); + + // If the branch already exists (local or remote-tracking), check it out + // into the new worktree instead of creating a fresh branch — otherwise + // `git worktree add -b` errors out on the duplicate. + const reuseExisting = branchExists(repoRoot, branch); + const addArgs = reuseExisting + ? ['-C', repoRoot, 'worktree', 'add', wtPath, branch] + : ['-C', repoRoot, 'worktree', 'add', '-b', branch, wtPath, 'origin/main']; + execFileSync('git', addArgs, { stdio: 'inherit' }); const entry = await allocate(cfg, branch); @@ -75,3 +81,18 @@ export async function setup({ branch, cfg, repoRoot }: SetupOptions): Promise