Skip to content

Commit 2e9cf53

Browse files
CopilotTyriar
andcommitted
Boost main and master branches in terminal suggest completions
Co-authored-by: Tyriar <[email protected]>
1 parent 2ffd593 commit 2e9cf53

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

extensions/terminal-suggest/src/completions/upstream/git.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,15 @@ const postProcessBranches =
100100
name = name.slice(0, space);
101101
}
102102

103+
// Boost main and master branches to the top
104+
const isMainOrMaster = name === "main" || name === "master";
105+
const priority = isMainOrMaster ? 76 : 75;
106+
103107
return {
104108
name,
105109
description,
106110
icon: "fig://icon?type=git",
107-
priority: 75,
111+
priority,
108112
};
109113
})
110114
.filter((suggestion) => {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)