fix(project): resolve default branch from origin/HEAD, not checked-out branch#289
Open
codebanditssss wants to merge 1 commit into
Open
fix(project): resolve default branch from origin/HEAD, not checked-out branch#289codebanditssss wants to merge 1 commit into
codebanditssss wants to merge 1 commit 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.
Contributor
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.
Collaborator
|
Can you also test it end to end apart from unit tests & add the testing details here? |
neversettle17-101
requested changes
Jun 18, 2026
| } | ||
| out, err := exec.Command("git", "-C", path, "symbolic-ref", "--short", "HEAD").Output() | ||
| if err != nil { | ||
| return "" |
Collaborator
There was a problem hiding this comment.
If we are not able to fetch a branch make sure we return correct error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/.