@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
33import {
44 dedupeRemoteBranchesWithLocalMatches ,
55 deriveLocalBranchNameFromRemoteRef ,
6+ filterSelectableBranches ,
67 resolveBranchSelectionTarget ,
78 resolveDraftEnvModeAfterBranchChange ,
89 resolveBranchToolbarValue ,
@@ -92,6 +93,46 @@ describe("deriveLocalBranchNameFromRemoteRef", () => {
9293 } ) ;
9394} ) ;
9495
96+ describe ( "filterSelectableBranches" , ( ) => {
97+ it ( "shows only local branches in the branch selector" , ( ) => {
98+ const input : GitBranch [ ] = [
99+ {
100+ name : "main" ,
101+ current : true ,
102+ isDefault : true ,
103+ worktreePath : null ,
104+ } ,
105+ {
106+ name : "feature/demo" ,
107+ current : false ,
108+ isDefault : false ,
109+ worktreePath : null ,
110+ } ,
111+ {
112+ name : "origin/feature/demo" ,
113+ isRemote : true ,
114+ remoteName : "origin" ,
115+ current : false ,
116+ isDefault : false ,
117+ worktreePath : null ,
118+ } ,
119+ {
120+ name : "jason/feature/old-fork" ,
121+ isRemote : true ,
122+ remoteName : "jason" ,
123+ current : false ,
124+ isDefault : false ,
125+ worktreePath : null ,
126+ } ,
127+ ] ;
128+
129+ expect ( filterSelectableBranches ( input ) . map ( ( branch ) => branch . name ) ) . toEqual ( [
130+ "main" ,
131+ "feature/demo" ,
132+ ] ) ;
133+ } ) ;
134+ } ) ;
135+
95136describe ( "dedupeRemoteBranchesWithLocalMatches" , ( ) => {
96137 it ( "hides remote refs when the matching local branch exists" , ( ) => {
97138 const input : GitBranch [ ] = [
@@ -149,7 +190,7 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => {
149190 ] ) ;
150191 } ) ;
151192
152- it ( "keeps non-origin remote refs visible even when a matching local branch exists" , ( ) => {
193+ it ( "hides non-origin remote refs too when a matching local branch exists" , ( ) => {
153194 const input : GitBranch [ ] = [
154195 {
155196 name : "feature/demo" ,
@@ -169,11 +210,43 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => {
169210
170211 expect ( dedupeRemoteBranchesWithLocalMatches ( input ) . map ( ( branch ) => branch . name ) ) . toEqual ( [
171212 "feature/demo" ,
172- "my-org/upstream/feature/demo" ,
173213 ] ) ;
174214 } ) ;
175215
176- it ( "keeps non-origin remote refs visible when git tracks with first-slash local naming" , ( ) => {
216+ it ( "hides non-preferred remote refs when a preferred remote is configured" , ( ) => {
217+ const input : GitBranch [ ] = [
218+ {
219+ name : "feature/demo" ,
220+ current : false ,
221+ isDefault : false ,
222+ worktreePath : null ,
223+ } ,
224+ {
225+ name : "origin/feature/remote-only" ,
226+ isRemote : true ,
227+ remoteName : "origin" ,
228+ current : false ,
229+ isDefault : false ,
230+ worktreePath : null ,
231+ } ,
232+ {
233+ name : "my-org/upstream/feature/demo" ,
234+ isRemote : true ,
235+ remoteName : "my-org/upstream" ,
236+ current : false ,
237+ isDefault : false ,
238+ worktreePath : null ,
239+ } ,
240+ ] ;
241+
242+ expect (
243+ dedupeRemoteBranchesWithLocalMatches ( input , { preferredRemoteName : "origin" } ) . map (
244+ ( branch ) => branch . name ,
245+ ) ,
246+ ) . toEqual ( [ "feature/demo" , "origin/feature/remote-only" ] ) ;
247+ } ) ;
248+
249+ it ( "hides preferred-remote refs too when a matching local branch exists" , ( ) => {
177250 const input : GitBranch [ ] = [
178251 {
179252 name : "upstream/feature" ,
@@ -191,10 +264,11 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => {
191264 } ,
192265 ] ;
193266
194- expect ( dedupeRemoteBranchesWithLocalMatches ( input ) . map ( ( branch ) => branch . name ) ) . toEqual ( [
195- "upstream/feature" ,
196- "my-org/upstream/feature" ,
197- ] ) ;
267+ expect (
268+ dedupeRemoteBranchesWithLocalMatches ( input , {
269+ preferredRemoteName : "my-org/upstream" ,
270+ } ) . map ( ( branch ) => branch . name ) ,
271+ ) . toEqual ( [ "upstream/feature" ] ) ;
198272 } ) ;
199273} ) ;
200274
0 commit comments