Skip to content

fix(worktree-cli): forward dev flags to vite and reuse existing branches#23

Merged
rlueder merged 1 commit intomainfrom
fix/worktree-cli-dev-args-and-existing-branch
Apr 23, 2026
Merged

fix(worktree-cli): forward dev flags to vite and reuse existing branches#23
rlueder merged 1 commit intomainfrom
fix/worktree-cli-dev-args-and-existing-branch

Conversation

@rlueder
Copy link
Copy Markdown
Member

@rlueder rlueder commented Apr 23, 2026

Summary

Two small fixes that together make the end-to-end worktree flow —
precisa-worktree setup <branch> && precisa-worktree dev --detach
actually work for the OSS sites (fhir-brasil, medbench-brasil,
datasus-brasil). Both issues surfaced while setting up dev servers to
visually verify the Header / OpenFooter migration.

1. `dev`: drop the `--` separator before script args

Invocation was:

```
pnpm --filter dev -- --port
```

Under pnpm 9 with a plain `"dev": "vite"` script, the `--` separator
is preserved in the spawned argv, so vite receives
`vite -- --port 4333` and silently ignores the port flag, falling back
to its default (4321). Removing the `--` forwards the flags directly
(`vite --port 4333`), which is what all existing service configs
(platform, OSS repos) expect.

Verified locally: `pnpm --filter @fhir-brasil/site dev --port 9998`
binds to 9998; `pnpm --filter @fhir-brasil/site dev -- --port 9998`
falls back to 4321.

2. `setup`: reuse an existing branch instead of erroring

`setup` always ran `git worktree add -b ... origin/main`,
which fails with `fatal: a branch named '' already exists`
whenever the branch was created previously (e.g. in the main worktree,
then pushed, then later promoted to a real feature worktree).

Now: detect the case via `git show-ref` against local +
`refs/remotes/origin/`, and fall back to
`git worktree add ` (without `-b`) to check out the
existing branch.

Test plan

  • `pnpm turbo run build typecheck --filter=@precisa-saude/worktree-cli` passes
  • Manually verified the flag-forwarding behavior with pnpm 9
  • After merge + release, rerun `setup`/`dev` in fhir-brasil and medbench-brasil for the `feat/shared-header-footer` branches

Two small fixes that together make `precisa-worktree setup <branch> &&
precisa-worktree dev --detach` actually work end-to-end for OSS repos:

1. `dev` was invoking the service script as
   `pnpm --filter <x> dev -- --port <n>`. Under pnpm 9 + a plain
   `"dev": "vite"` script, the `--` separator is preserved in the
   spawned argv, so vite saw `vite -- --port 4333` and silently fell
   back to its default port (4321). Removing the `--` forwards the
   flags directly (`vite --port 4333`).

2. `setup` always ran `git worktree add -b <branch>`, which fatal-errors
   if the branch already exists locally or on origin (common when
   bringing up a worktree for a branch that was created in the main
   worktree and pushed to origin). Detect that case via `git show-ref`
   and fall back to `git worktree add <path> <branch>` to check out the
   existing branch.
@github-actions
Copy link
Copy Markdown

Automated Review — Round 1

Summary

The PR introduces a new utility function for checking branch existence and modifies the logic for adding git worktrees. While the changes improve functionality, there are performance considerations and potential issues with error handling.

Changes

  • Modified arguments in spawnService function in dev.ts
  • Added branch existence checking in setup.ts
  • Adjusted logic for adding git worktrees in setup.ts

🔍 Found 2 suggestions (see inline comments)

Reviewed by OpenAI gpt-4o-mini (fallback) | 1,160 in / 184 out | $0.0003 — Round 1 of 2

Comment thread packages/worktree-cli/src/commands/setup.ts
Comment thread packages/worktree-cli/src/commands/setup.ts
@rlueder rlueder merged commit 0cab460 into main Apr 23, 2026
8 checks passed
@rlueder rlueder deleted the fix/worktree-cli-dev-args-and-existing-branch branch April 23, 2026 13:10
github-actions Bot pushed a commit that referenced this pull request Apr 23, 2026
## [1.5.1](v1.5.0...v1.5.1) (2026-04-23)

### Bug Fixes

* **worktree-cli:** forward dev flags to vite and reuse existing branches ([#23](#23)) ([0cab460](0cab460))
rlueder added a commit that referenced this pull request Apr 24, 2026
…hes (#23)

Two small fixes that together make `precisa-worktree setup <branch> &&
precisa-worktree dev --detach` actually work end-to-end for OSS repos:

1. `dev` was invoking the service script as
   `pnpm --filter <x> dev -- --port <n>`. Under pnpm 9 + a plain
   `"dev": "vite"` script, the `--` separator is preserved in the
   spawned argv, so vite saw `vite -- --port 4333` and silently fell
   back to its default port (4321). Removing the `--` forwards the
   flags directly (`vite --port 4333`).

2. `setup` always ran `git worktree add -b <branch>`, which fatal-errors
   if the branch already exists locally or on origin (common when
   bringing up a worktree for a branch that was created in the main
   worktree and pushed to origin). Detect that case via `git show-ref`
   and fall back to `git worktree add <path> <branch>` to check out the
   existing branch.
rlueder pushed a commit that referenced this pull request Apr 24, 2026
## [1.5.1](v1.5.0...v1.5.1) (2026-04-23)

### Bug Fixes

* **worktree-cli:** forward dev flags to vite and reuse existing branches ([#23](#23)) ([935df8a](935df8a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant