mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-18 09:45:36 -05:00
Reworks branch parsing to include tracking info
Reworks current branch retrieval for better performance
This commit is contained in:
@@ -5,15 +5,9 @@ export class GitBranch {
|
||||
current: boolean;
|
||||
name: string;
|
||||
remote: boolean;
|
||||
tracking?: string;
|
||||
|
||||
constructor(branch: string) {
|
||||
branch = branch.trim();
|
||||
|
||||
if (branch.startsWith('* ')) {
|
||||
branch = branch.substring(2);
|
||||
this.current = true;
|
||||
}
|
||||
|
||||
constructor(public readonly repoPath: string, branch: string, current: boolean = false, tracking?: string) {
|
||||
if (branch.startsWith('remotes/')) {
|
||||
branch = branch.substring(8);
|
||||
this.remote = true;
|
||||
@@ -24,6 +18,24 @@ export class GitBranch {
|
||||
branch = branch.substring(0, index);
|
||||
}
|
||||
|
||||
this.current = current;
|
||||
this.name = branch;
|
||||
this.tracking = tracking;
|
||||
}
|
||||
|
||||
getName(): string {
|
||||
return this.remote
|
||||
? this.name.substring(this.name.indexOf('/') + 1)
|
||||
: this.name;
|
||||
}
|
||||
|
||||
getRemote(): string | undefined {
|
||||
if (this.remote) return GitBranch.getRemote(this.name);
|
||||
if (this.tracking !== undefined) return GitBranch.getRemote(this.tracking);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
static getRemote(branch: string): string {
|
||||
return branch.substring(0, branch.indexOf('/'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user