t3code
t3code copied to clipboard
[Bug]: listRefs marks every branch isDefault: false when the primary remote is not named origin
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:
listRefsdoes 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_listreportsisDefault: falseon 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):
- Queries
refs/remotes/origin/HEADdirectly viarev-parse(even though thefor-each-refcall in the same function already emits%(symref)for allrefs/remotes/*/HEADentries). - Calls
parseDefaultBranchFromRemoteHeadRef(defaultRefResult.stdout, "origin"). - Marks remote branches with
parsedRemoteRef?.remoteName === "origin" && parsedRemoteRef.branchName === defaultBranch.
Steps to reproduce
- Create a repo with a bare remote added as
upstream(noorigin), default branchtrunk, andrefs/remotes/upstream/HEAD -> refs/remotes/upstream/trunk. - Create a newer branch
other, switch tofeature, and calllistRefs({ cwd, includeMatchingRemoteRefs: true }). - Actual:
defaultBranchisnull; bothtrunkandupstream/trunkhaveisDefault: false, andothersorts ahead oftrunk. - Expected:
trunkandupstream/trunkhaveisDefault: true, andtrunksorts ahead ofother(matchingstatusDetailsLocal/statusDetailsRemote). Whenoriginis configured withoutrefs/remotes/origin/HEAD,defaultBranchshould remainnull(matchingresolvePrimaryDefaultBranchName).