Skip to content

Create worktrees in repositories that have no origin - #524

Merged
powerfooI merged 2 commits into
powerfooI:mainfrom
thiblahute:upstream/worktree-no-origin
Oct 31, 2026
Merged

powerfooI merged 2 commits into
powerfooI:mainfrom
thiblahute:upstream/worktree-no-origin

Conversation

@thiblahute

Copy link
Copy Markdown
Collaborator

Creating a worktree first refreshes the repository's origin default branch to pick the base commit. A local repository with no origin remote failed there, so no worktree could be created from it at all.

When the refresh fails with an error naming 'origin' (git quotes the remote's name in every language it speaks, so this works with a translated git too), and git remote get-url origin confirms the repository has no origin remote, the new worktree now branches from the commit that is checked out (HEAD). Any other failure, including an unreachable or misconfigured origin, still surfaces as before.

Changes

  • server/src/worktree/create.ts: syncWorktreeBase falls back to HEAD^{commit} for repositories without an origin remote.
  • server/src/workspace/default-branch.test.ts: real-git test that a repository without origin gets base: "HEAD" and the checked-out commit.
  • server/src/worktree/create.test.ts: the same with git answering in French; it fails without the change.

Verification

  • bun test server/src/worktree/create.test.ts server/src/workspace/default-branch.test.ts: 55 pass, 0 fail. The existing "does not fall back to another base when ..." cases still pass, so failures with an origin are not masked.
  • bun run format:check on the changed files: clean.
  • bun run lint: clean apart from the existing TerminalView.tsx exhaustive-deps warning.
  • bun run typecheck: passes, including the web build and asset budget check (initial JS 805.0/805 KiB).
  • bun run test:quick with an isolated HOME, on main plus this change and the other small fixes I am sending alongside: 3965 pass, 4 skip, 2 fail. Both failures (useMobileControlsDrag.keyboard.test.ts and the SSH paths test) fail the same way on main on macOS.

Manual check, not repeated on this branch:

  • In a workspace whose repository has no origin, create a worktree from the workspace menu: it is created from the current commit.

Compatibility

No API or settings changes.

Creating a worktree first refreshes the repository's origin default branch to
pick the base commit. A local repository with no origin remote failed there,
so no worktree could be created from it at all. When git reports that origin
is missing, and the repository really has no origin remote, branch from the
commit that is checked out instead; any other fetch failure still surfaces.
Git translates its messages, so the English text of the missing-origin
error is not there on a machine set to French, say. Git quotes the remote's
name in every language, so look for 'origin' and let the remote lookup
decide; a repository that has an origin still reports its fetch failure.
@github-actions github-actions Bot added the enhancement New feature or request label Oct 31, 2026
@powerfooI
powerfooI merged commit e124a04 into powerfooI:main Oct 31, 2026
5 checks passed

Copy link
Copy Markdown
Owner

Reviewed and merged. Re-ran bun test server/src/worktree/create.test.ts server/src/workspace/default-branch.test.ts: 55 pass, 0 fail, including the real-Git repository without origin and the existing failure-preservation cases. CI and CodeQL passed on the merged head.

@powerfooI powerfooI added the bug Something isn't working label Oct 31, 2026 — with ChatGPT Codex Connector
@powerfooI powerfooI removed the enhancement New feature or request label Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants