fix: prefer exact match over suffix match when auto-selecting tracking branch for worktree#2569
Conversation
|
I suggest refactor it to: |
… tracking branch Signed-off-by: weiningwei <weiningwei09@gmail.com>
Signed-off-by: weiningwei <weiningwei09@gmail.com>
0dc0de5 to
9de1c1b
Compare
|
Thank you for the explanation. That makes sense — EndsWith("/" + name) prevents the fix ↔ hotfix issue while still handling path-component names like feature/fix. I've updated the PR to use your suggested condition: Also, would you prefer the two conditions to be split into separate Find calls so that an exact match always takes priority over a suffix match regardless of list order? Currently as a single Find the first match in the list wins. |
|
Good idea. ‘Equal’ first and then ‘EndsWith’
|
Signed-off-by: weiningwei <weiningwei09@gmail.com>
|
Updated as suggested — split into two Finds so exact match takes priority: |
When adding a worktree with an existing local branch and enabling "Set Upstream Tracking Branch", the
AutoSelectTrackingBranch()method usedEndsWithto match remote branches against the local branch name. This caused unintended matches — for example, local branchsmart_buildwould matchfix_smart_buildinstead of the exact matchsmart_build.This commit fixes the logic by:
Equals) against remote branch namesEndsWith) only if no exact match is foundRemoteBranches[0]as the final fallback