Skip to content

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

Done

Description

@AymanKhan9

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions