mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-12 02:58:32 -05:00
24 lines
701 B
TypeScript
24 lines
701 B
TypeScript
'use strict';
|
|
import { GitBranch } from './../git';
|
|
const branchWithTrackingRegex = /^(\*?)\s+(.+?)\s+([0-9,a-f]+)\s+(?:\[(.*?\/.*?)(?:\:|\]))?/gm;
|
|
|
|
export class GitBranchParser {
|
|
|
|
static parse(data: string, repoPath: string): GitBranch[] | undefined {
|
|
if (!data) return undefined;
|
|
|
|
const branches: GitBranch[] = [];
|
|
|
|
let match: RegExpExecArray | null = null;
|
|
do {
|
|
match = branchWithTrackingRegex.exec(data);
|
|
if (match == null) break;
|
|
|
|
branches.push(new GitBranch(repoPath, match[2], match[1] === '*', match[4]));
|
|
} while (match != null);
|
|
|
|
if (!branches.length) return undefined;
|
|
|
|
return branches;
|
|
}
|
|
} |