import { Reference as NodeGitReference } from "nodegit"; import { Repository } from "./repository"; type ReferenceClass = new(owner: Repository, reference: NodeGitReference) => T; export function isNodeGitReferenceBranch(ref: NodeGitReference): boolean { return Boolean(ref.isBranch()); } export function isNodeGitReferenceTag(ref: NodeGitReference): boolean { return Boolean(ref.isTag()); } export abstract class Reference { protected _ng_reference: NodeGitReference; protected _owner: Repository; public id: string; public name: string; constructor(owner: Repository, reference: NodeGitReference) { this._ng_reference = reference; this._owner = owner; this.id = reference.target().tostrS(); this.name = reference.shorthand(); } public static async all(owner: Repository, Target: ReferenceClass, ref_fn: (ref: NodeGitReference) => boolean): Promise { const references = await owner.nodegitRepository.getReferences(); return references.filter(ref_fn).map(ref => new Target(owner, ref)); } }