Skip to content

fix(project): resolve default branch from origin/HEAD, not checked-out branch#289

Open
codebanditssss wants to merge 1 commit into
mainfrom
fix/default-branch-origin-head
Open

fix(project): resolve default branch from origin/HEAD, not checked-out branch#289
codebanditssss wants to merge 1 commit into
mainfrom
fix/default-branch-origin-head

Conversation

@codebanditssss

@codebanditssss codebanditssss commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Closes #286

What

project add was detecting the default branch with git symbolic-ref --short HEAD, which returns the currently checked-out branch — not the repo's actual default. Adding a project while sitting on a feature branch (e.g. fix/pr-attachment) persisted that feature branch as the project default, so every new session worktree based off it instead of main.

Fix

resolveDefaultBranch now reads the remote default first:

  1. git symbolic-ref --short refs/remotes/origin/HEAD → the real default (strip origin/)
  2. fall back to symbolic-ref --short HEAD only when there's no remote default
  3. empty on error → caller falls back to DefaultBranchName (main)

This keeps the original behaviour that motivated the detection — repos whose default is master/develop are still recorded correctly — while no longer latching onto the active feature branch.

Tests

  • TestManager_AddPrefersOriginHeadOverCheckedOutBranch — HEAD on fix/pr-attachment, origin/HEAD = main → records main
  • TestManager_AddPrefersOriginHeadNonMain — origin/HEAD = master, HEAD on feature branch → records master
  • existing TestManager_AddDetectsNonMainDefaultBranch still passes

all green via go test ./internal/service/project/.

…t branch

Detecting the project default via `symbolic-ref --short HEAD` captured
whatever branch the repo happened to be on at add time. Adding a project
while on a feature branch (e.g. fix/pr-attachment) persisted that branch
as the default, so every session worktree based off it instead of main.

Prefer the remote default (origin/HEAD), falling back to the checked-out
branch only when no remote default is set. This still records a non-main
default like master correctly, while ignoring the active feature branch.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@neversettle17-101 neversettle17-101 self-requested a review June 17, 2026 15:48
@neversettle17-101

Copy link
Copy Markdown
Collaborator

Can you also test it end to end apart from unit tests & add the testing details here?

}
out, err := exec.Command("git", "-C", path, "symbolic-ref", "--short", "HEAD").Output()
if err != nil {
return ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are not able to fetch a branch make sure we return correct error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(project): ao project add permanently adopts whatever branch is checked out at registration time as the project default, diverging from main

2 participants