fix(project): resolve default branch from origin/HEAD, not checked-out branch#289
fix(project): resolve default branch from origin/HEAD, not checked-out branch#289codebanditssss wants to merge 2 commits into
Conversation
…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.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
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 "" |
There was a problem hiding this comment.
If we are not able to fetch a branch make sure we return correct error.
|
Done. I added API-level end-to-end coverage for the branch-not-fetched case. If the requested branch cannot be resolved/fetched, the workspace layer returns Testing run:
|
neversettle17-101
left a comment
There was a problem hiding this comment.
Please test it also E2E once merged.
Closes #286
What
project addwas detecting the default branch withgit 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 ofmain.Fix
resolveDefaultBranchnow reads the remote default first:git symbolic-ref --short refs/remotes/origin/HEAD→ the real default (striporigin/)symbolic-ref --short HEADonly when there's no remote defaultDefaultBranchName(main)This keeps the original behaviour that motivated the detection — repos whose default is
master/developare still recorded correctly — while no longer latching onto the active feature branch.Tests
TestManager_AddPrefersOriginHeadOverCheckedOutBranch— HEAD onfix/pr-attachment, origin/HEAD =main→ recordsmainTestManager_AddPrefersOriginHeadNonMain— origin/HEAD =master, HEAD on feature branch → recordsmasterTestManager_AddDetectsNonMainDefaultBranchstill passesall green via
go test ./internal/service/project/.