Skip to content

feat(source-control): worktree-create fresh base should resolve the default branch of non-origin remotes #904

Description

@kyle-sexton

Summary

The shared worktree helper (plugins/source-control/scripts/worktree-create.sh, added in #399) resolves the fresh base ref by probing refs/remotes/origin/HEAD only. In a repo cloned with a non-origin default remote (e.g. git clone -o upstream), upstream/HEAD may be correctly cached but origin/HEAD is absent, so --base-ref fresh falls back to local HEAD (with a warning) and a worktree created from a feature branch carries unpushed/local commits into a supposedly-fresh worktree.

Not a regression (context)

This is a pre-existing, shared limitation, not something #399 introduced: Claude Code's own native fresh resolution is also origin-centric (per https://code.claude.com/docs/en/worktrees it keeps origin/HEAD current). #399 preserved that same origin-centric behavior for the interactive path and added a loud stderr warning on the HEAD fallback, so the failure is visible rather than silent. This issue tracks closing the gap properly.

Proposed fix

Before falling back to HEAD, resolve the repo's effective default remote generically:

  1. the current branch's configured remote (git config branch.<name>.remote), then
  2. origin if it exists, then
  3. the sole remote if there is exactly one.

Probe refs/remotes/<remote>/HEAD for that remote. Keep the HEAD fallback + warning only when no remote default can be resolved.

Acceptance

  • --base-ref fresh in a -o upstream clone bases the worktree on upstream's default branch, not local HEAD.
  • Test fixture: a fixture whose only remote is named something other than origin.
  • The HEAD fallback + warning remains for the genuinely-remoteless case.

Source

Raised by a Codex review thread on #898 (PR for #399, Phase A).

Metadata

Metadata

Assignees

Labels

agent-readyFully specified and briefed; eligible for autonomous pickup from the frontier.priority: lowNice-to-have, cosmetic, or speculative; opportunistic.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions