-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbranch-manager.ts
More file actions
40 lines (35 loc) · 1.4 KB
/
branch-manager.ts
File metadata and controls
40 lines (35 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import WindowAdaptor from './adaptors/window';
import { Ref } from './types/git.d';
import GitAdaptor from './adaptors/git';
import { QuickPickItem } from 'vscode';
export default class BranchManager {
constructor(private readonly gitAdaptor: GitAdaptor,
private readonly windowAdaptor: WindowAdaptor) {}
private toQuickPickItems(list: string[]): QuickPickItem[] {
return list.map((name, i)=> ({
label: name,
picked: false,
ruleIndex: i,
description: ''
}));
}
async getFileContent(branchName: string, fileUri: string): Promise<string> {
try {
return await this.gitAdaptor.show(branchName, fileUri);
} catch(e) {
this.windowAdaptor.showInformationMessage(`file does not exist on ${branchName} branch`);
return '';
}
}
async selectViaQuickPick(branchNames: string[]): Promise<string> {
const branch: QuickPickItem = await <any>this.windowAdaptor.showQuickPick(this.toQuickPickItems(branchNames), false);
return branch.label;
}
async getLocalBranchNames(): Promise<string[]> {
if (!this.gitAdaptor.isGitRepo()) {
this.windowAdaptor.showInformationMessage('Git repo not found!');
}
const branches: Ref[] = await this.gitAdaptor.allBranches();
return branches.map((i:Ref) => i.name || '');
}
}