Skip to content

ao project add records main as default branch for non-main repos, breaking ao spawn #208

@codebanditssss

Description

@codebanditssss

Bug

ao project add never inspects the repo's checked-out branch. The project's Config.DefaultBranch is left empty and WithDefaults() forces it to "main" (backend/internal/domain/projectconfig.go:48). For any repo whose default branch isn't literally main (e.g. master, develop, trunk), every subsequent ao spawn fails because the worktree base ref doesn't exist.

Analyzed against: 3e64c15 | Confidence: High

Reproduction

  1. git init a repo (no -b, so on a host without init.defaultBranch it lands on master), add one commit.
  2. ao project add --path <repo> --id xao project get x reports default branch: main. ❌ (the repo is on master)
  3. ao spawn --project x --prompt hi
    BRANCH_NOT_FETCHED: "ao/x-1" has no local head, no remote, and no tag — run `git fetch` then retry
    
  4. The identical repo on main spawns fine. ao project add exposes no --branch flag, so there is no CLI workaround.

Root Cause

  • backend/internal/service/project/service.go Add (single-repo path) registers the project without detecting the repo's branch, so Config.DefaultBranch stays empty → defaults to main.
  • At spawn, resolveBaseRef (backend/internal/adapters/workspace/gitworktree/workspace.go:253) tries origin/main, refs/heads/main, and tags; none exist on a master repo → errNoBaseRefErrBranchNotFetched.
  • The surfaced message ("run git fetch") is misleading: there is no remote, and the base branch name is simply wrong.

Fix

Detect the repo's current branch with git symbolic-ref --short HEAD at registration and store it as DefaultBranch when the user didn't configure one and it diverges from main. Best-effort: a detached HEAD or git error falls back to the existing main default, so add never fails on this account.

Impact

Breaks the README quickstart (project addspawn) for every master / non-main repo — a large fraction of older and real-world repositories. No workaround via the CLI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions