Skip to content

fix(#1405): a fresh machine starts a PR branch worktree from origin/<branch> - #1468

Merged
admarble merged 3 commits into
mainfrom
feature/1405-fix-worktree-first-creation-on-a-fresh-machine-ign
Oct 16, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/1405-fix-worktree-first-creation-on-a-fresh-machine-ign

Conversation

@admarble

@admarble admarble commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With no local <branch>, ensureWorktree used to cut a new branch from the base even when origin/<branch> already held the PR's commits. So the first run on a fresh machine, a fresh clone, or a cloud session started over. Also, a worktree recreated from origin/<branch> (#1380) was still behind the base, so every later run deleted it and recreated it.

Runner fix after QA (AC_MET_BUT_NOT_A_PLUS)

QA found that the deleted-remote-branch check matched git's English couldn't find remote ref. Reproduced on macOS: under LC_ALL=de_DE.UTF-8, git prints Schwerwiegend: Konnte Remote-Referenz … nicht finden., so a stale tracking ref for a branch deleted unmerged would be used again. 7c7b7d6 runs that fetch with LC_ALL=C and adds a German-locale test. The test is vacuous on a git with no translations installed, but it is real on this machine (see the mutation below).

AC mapping

AC Status Evidence
AC-1 Met 1405 AC-1 first creation on a fresh machine starts from origin/<branch>: HEAD contains all of origin/<branch>, and the upstream and sequantBaseRef are set. Mutation below
AC-2 Met 1405 AC-2 a worktree recreated from origin/<branch> is reused by the next call: the second call reuses the same path and HEAD while still more than 5 commits behind main
AC-3 Met Squash-merged, merge-commit-merged and deleted-remote cases each start from origin/main. the reuse path makes no gh call puts a gh stub on PATH and asserts it is never invoked

Runner check: npx vitest run src/lib/workflow/worktree-manager.test.ts -t "1405|1380" gave 12/12 passed. Full-suite evidence is CI's.

Mutation verification

  • Mutation-verified: AC-1 — on the first-creation path, dropped recreateFrom = startRef so the branch is cut from the base again; only 1405 AC-1 first creation on a fresh machine starts from origin/<branch> failed; restored.
  • Locale fix: removed LC_ALL: "C" from the fetch's env; only 1405 AC-3 a deleted remote branch is detected under a non-English locale failed; restored.

Runner note: on the stale-recreate path, the recreateFrom = startRef assignment (worktree-manager.ts:1056) is now redundant. Dropping it fails no test, because once the stale worktree is removed, the first-creation block resolves origin/<branch> again. The behaviour is the same, at the cost of a second git fetch on a recreate.

Follow-ups

  • templates/scripts/new-feature.sh (the shell worktree path) has the same first-creation defect: it checks only refs/heads/<branch> and cuts -b <branch> origin/<base>. Raised with the owner; not in this issue's file scope.

Fixes #1405


🤖 Generated with Claude Code

… one already at it

First creation with no local branch now resolves its start ref through resolveBranchStartRef (the #1380 resolver, generalized), so a pushed PR branch keeps its commits and upstream. A remote branch already merged into the base (merge commit or squash) or deleted from the remote is not resurrected. A stale, clean worktree whose HEAD equals origin/<branch> is reused rather than recreated on every run. Local git only; no gh call on the reuse path. ADR-0014.

Entire-Checkpoint: b604f8946770
QA: resolveBranchStartRef matched git's English 'couldn't find remote ref'; under a German locale git prints 'Konnte Remote-Referenz … nicht finden', so a stale tracking ref for a deleted unmerged branch was reused. Run that fetch with LC_ALL=C.
Entire-Checkpoint: 301cb7bc9394
admarble added a commit that referenced this pull request Oct 16, 2026
#1405's PR (#1468) also adds an ADR-0014; it is on the graph's critical path and keeps the number.

Entire-Checkpoint: 49f1b32b29bc
@admarble admarble changed the title fix(#1405): first creation on a fresh machine ignores origin/<branch>, and a recreated PR worktree is recreated again on every run (#1380 follow-up) fix(#1405): a fresh machine starts a PR branch worktree from origin/<branch> Oct 16, 2026
@admarble
admarble merged commit 43a0abc into main Oct 16, 2026
8 checks passed
@admarble
admarble deleted the feature/1405-fix-worktree-first-creation-on-a-fresh-machine-ign branch October 16, 2026 13:31
admarble added a commit that referenced this pull request Oct 16, 2026
…rifting (#1467)

* fix(#1409): scope content drift and its remedy to the recorded install scope

A skills-only install (init --manifest-only + sync --only skills) counted every hook, agent, scripts/dev file and settings.json it never installed as drift, and its remedy (sync --force) overwrote the constitution. The manifest now records the install scope in an optional groups field owned by src/lib/manifest.ts; drift and the remedy (sync --only skills --force) are scoped to it. A manifest without the field is a full install. ADR-0014.

Entire-Checkpoint: afbcf3d7b9ec

* docs(#1409): renumber the install-scope ADR to 0015

#1405's PR (#1468) also adds an ADR-0014; it is on the graph's critical path and keeps the number.

Entire-Checkpoint: 49f1b32b29bc
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.

fix(worktree): first creation on a fresh machine ignores origin/<branch>, and a recreated PR worktree is recreated again on every run (#1380 follow-up)

1 participant