@@ -296,4 +296,72 @@ suite('TerminalCompletionModel', function () {
296
296
297
297
298
298
} ) ;
299
+
300
+ suite ( 'git branch priority sorting' , ( ) => {
301
+ test ( 'should prioritize main and master branches for git commands' , ( ) => {
302
+ const items = [
303
+ createItem ( { label : 'feature-branch' , provider : 'terminal-suggest' } ) ,
304
+ createItem ( { label : 'master' , provider : 'terminal-suggest' } ) ,
305
+ createItem ( { label : 'development' , provider : 'terminal-suggest' } ) ,
306
+ createItem ( { label : 'main' , provider : 'terminal-suggest' } )
307
+ ] ;
308
+ const model = new TerminalCompletionModel ( items , new LineContext ( 'git checkout ' , 0 ) ) ;
309
+ assertItems ( model , [ 'main' , 'master' , 'development' , 'feature-branch' ] ) ;
310
+ } ) ;
311
+
312
+ test ( 'should prioritize main and master branches for git switch command' , ( ) => {
313
+ const items = [
314
+ createItem ( { label : 'feature-branch' , provider : 'terminal-suggest' } ) ,
315
+ createItem ( { label : 'main' , provider : 'terminal-suggest' } ) ,
316
+ createItem ( { label : 'another-feature' , provider : 'terminal-suggest' } ) ,
317
+ createItem ( { label : 'master' , provider : 'terminal-suggest' } )
318
+ ] ;
319
+ const model = new TerminalCompletionModel ( items , new LineContext ( 'git switch ' , 0 ) ) ;
320
+ assertItems ( model , [ 'main' , 'master' , 'another-feature' , 'feature-branch' ] ) ;
321
+ } ) ;
322
+
323
+ test ( 'should not prioritize main and master for non-git commands' , ( ) => {
324
+ const items = [
325
+ createItem ( { label : 'feature-branch' , provider : 'terminal-suggest' } ) ,
326
+ createItem ( { label : 'master' , provider : 'terminal-suggest' } ) ,
327
+ createItem ( { label : 'main' , provider : 'terminal-suggest' } )
328
+ ] ;
329
+ const model = new TerminalCompletionModel ( items , new LineContext ( 'ls ' , 0 ) ) ;
330
+ assertItems ( model , [ 'feature-branch' , 'main' , 'master' ] ) ;
331
+ } ) ;
332
+
333
+ test ( 'should only apply to terminal-suggest provider' , ( ) => {
334
+ const items = [
335
+ createItem ( { label : 'feature-branch' , provider : 'other-provider' } ) ,
336
+ createItem ( { label : 'master' , provider : 'other-provider' } ) ,
337
+ createItem ( { label : 'main' , provider : 'other-provider' } )
338
+ ] ;
339
+ const model = new TerminalCompletionModel ( items , new LineContext ( 'git checkout ' , 0 ) ) ;
340
+ assertItems ( model , [ 'feature-branch' , 'main' , 'master' ] ) ;
341
+ } ) ;
342
+
343
+ test ( 'should handle git commands with leading whitespace' , ( ) => {
344
+ const items = [
345
+ createItem ( { label : 'feature-branch' , provider : 'terminal-suggest' } ) ,
346
+ createItem ( { label : 'master' , provider : 'terminal-suggest' } ) ,
347
+ createItem ( { label : 'main' , provider : 'terminal-suggest' } )
348
+ ] ;
349
+ const model = new TerminalCompletionModel ( items , new LineContext ( ' git checkout ' , 0 ) ) ;
350
+ assertItems ( model , [ 'main' , 'master' , 'feature-branch' ] ) ;
351
+ } ) ;
352
+
353
+ test ( 'should work with complex label objects' , ( ) => {
354
+ const items = [
355
+ createItem ( { label : { label : 'feature-branch' , description : 'Feature branch' } , provider : 'terminal-suggest' } ) ,
356
+ createItem ( { label : { label : 'master' , description : 'Master branch' } , provider : 'terminal-suggest' } ) ,
357
+ createItem ( { label : { label : 'main' , description : 'Main branch' } , provider : 'terminal-suggest' } )
358
+ ] ;
359
+ const model = new TerminalCompletionModel ( items , new LineContext ( 'git checkout ' , 0 ) ) ;
360
+ assertItems ( model , [
361
+ { label : 'main' , description : 'Main branch' } ,
362
+ { label : 'master' , description : 'Master branch' } ,
363
+ { label : 'feature-branch' , description : 'Feature branch' }
364
+ ] ) ;
365
+ } ) ;
366
+ } ) ;
299
367
} ) ;
0 commit comments