t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: listRefs marks every branch isDefault: false when the primary remote is not named origin

Open AymanKhan9 opened this issue 1 week ago • 0 comments

Problem

In a Git repository whose primary remote is not named origin (for example, cloned with git clone -o upstream ..., renamed via git remote rename origin upstream, or using a nested remote name like team/origin), GitVcsDriver.listRefs returns isDefault: false for every local and remote branch.

As a result:

  • listRefs does not pin the default branch ahead of newer non-default branches.
  • The branch picker (web, desktop, and mobile) fails to badge or pick the default branch for new threads/worktrees (BranchToolbar.logic.ts, BranchPicker.tsx, GitBranchesSheet.tsx, NewTaskDraftScreen.tsx).
  • t3_worktree_list reports isDefault: false on every branch.

Meanwhile, statusDetailsLocal / statusDetailsRemote in the same file already detect the default branch correctly via resolvePrimaryDefaultBranchName.

Root cause

In apps/server/src/vcs/GitVcsDriverCore.ts (readGitRefsSnapshot), default-branch detection hardcodes "origin" in three places instead of using the primary remote ("origin" when present, otherwise the first remote in Git order):

  1. Queries refs/remotes/origin/HEAD directly via rev-parse (even though the for-each-ref call in the same function already emits %(symref) for all refs/remotes/*/HEAD entries).
  2. Calls parseDefaultBranchFromRemoteHeadRef(defaultRefResult.stdout, "origin").
  3. Marks remote branches with parsedRemoteRef?.remoteName === "origin" && parsedRemoteRef.branchName === defaultBranch.

Steps to reproduce

  1. Create a repo with a bare remote added as upstream (no origin), default branch trunk, and refs/remotes/upstream/HEAD -> refs/remotes/upstream/trunk.
  2. Create a newer branch other, switch to feature, and call listRefs({ cwd, includeMatchingRemoteRefs: true }).
  3. Actual: defaultBranch is null; both trunk and upstream/trunk have isDefault: false, and other sorts ahead of trunk.
  4. Expected: trunk and upstream/trunk have isDefault: true, and trunk sorts ahead of other (matching statusDetailsLocal / statusDetailsRemote). When origin is configured without refs/remotes/origin/HEAD, defaultBranch should remain null (matching resolvePrimaryDefaultBranchName).

AymanKhan9 avatar Nov 24 '26 13:11 AymanKhan9