1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+
6
+ import 'mocha' ;
7
+ import * as assert from 'assert' ;
8
+ import { gitGenerators } from '../../../completions/upstream/git' ;
9
+
10
+ suite ( 'Git Branch Priority Tests' , ( ) => {
11
+ test ( 'postProcessBranches should boost main and master branches' , ( ) => {
12
+ const mockBranchOutput = ` feature-branch
13
+ main
14
+ master
15
+ development
16
+ another-feature` ;
17
+
18
+ const result = gitGenerators . remoteLocalBranches . postProcess ! ( mockBranchOutput , [ ] ) ;
19
+
20
+ // Find main and master branches
21
+ const mainBranch = result . find ( ( suggestion : any ) => suggestion . name === 'main' ) ;
22
+ const masterBranch = result . find ( ( suggestion : any ) => suggestion . name === 'master' ) ;
23
+ const otherBranches = result . filter ( ( suggestion : any ) =>
24
+ suggestion . name !== 'main' && suggestion . name !== 'master'
25
+ ) ;
26
+
27
+ // Verify main and master have higher priority (76)
28
+ assert . strictEqual ( mainBranch ?. priority , 76 , 'main branch should have priority 76' ) ;
29
+ assert . strictEqual ( masterBranch ?. priority , 76 , 'master branch should have priority 76' ) ;
30
+
31
+ // Verify other branches have default priority (75)
32
+ otherBranches . forEach ( ( branch : any ) => {
33
+ assert . strictEqual ( branch . priority , 75 , `${ branch . name } should have priority 75` ) ;
34
+ } ) ;
35
+ } ) ;
36
+
37
+ test ( 'postProcessBranches should handle remote branches with main/master' , ( ) => {
38
+ const mockRemoteBranchOutput = ` remotes/origin/feature-branch
39
+ remotes/origin/main
40
+ remotes/origin/master
41
+ remotes/origin/development` ;
42
+
43
+ const result = gitGenerators . remoteLocalBranches . postProcess ! ( mockRemoteBranchOutput , [ ] ) ;
44
+
45
+ // Find main and master branches (names should be stripped of remotes/ prefix)
46
+ const mainBranch = result . find ( ( suggestion : any ) => suggestion . name === 'main' ) ;
47
+ const masterBranch = result . find ( ( suggestion : any ) => suggestion . name === 'master' ) ;
48
+
49
+ // Verify main and master have higher priority (76)
50
+ assert . strictEqual ( mainBranch ?. priority , 76 , 'remote main branch should have priority 76' ) ;
51
+ assert . strictEqual ( masterBranch ?. priority , 76 , 'remote master branch should have priority 76' ) ;
52
+
53
+ // Verify they have remote branch description
54
+ assert . strictEqual ( mainBranch ?. description , 'Remote branch' , 'main should be marked as remote branch' ) ;
55
+ assert . strictEqual ( masterBranch ?. description , 'Remote branch' , 'master should be marked as remote branch' ) ;
56
+ } ) ;
57
+
58
+ test ( 'postProcessBranches should still prioritize current branch above main/master' , ( ) => {
59
+ const mockBranchOutputWithCurrent = `* current-branch
60
+ main
61
+ master
62
+ feature-branch` ;
63
+
64
+ const result = gitGenerators . remoteLocalBranches . postProcess ! ( mockBranchOutputWithCurrent , [ ] ) ;
65
+
66
+ // Find current, main and master branches
67
+ const currentBranch = result . find ( ( suggestion : any ) => suggestion . name === 'current-branch' ) ;
68
+ const mainBranch = result . find ( ( suggestion : any ) => suggestion . name === 'main' ) ;
69
+ const masterBranch = result . find ( ( suggestion : any ) => suggestion . name === 'master' ) ;
70
+
71
+ // Verify current branch has highest priority (100)
72
+ assert . strictEqual ( currentBranch ?. priority , 100 , 'current branch should have priority 100' ) ;
73
+
74
+ // Verify main and master have medium priority (76)
75
+ assert . strictEqual ( mainBranch ?. priority , 76 , 'main branch should have priority 76' ) ;
76
+ assert . strictEqual ( masterBranch ?. priority , 76 , 'master branch should have priority 76' ) ;
77
+ } ) ;
78
+ } ) ;
0 commit comments