blob: b24f72d25ff37073cc124bd87fe65854335ac161 (
plain)
| 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
 | import { Reference as NodeGitReference } from "nodegit";
import { Repository } from "./repository";
type ReferenceClass<T> = 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<T>(owner: Repository, Target: ReferenceClass<T>, ref_fn: (ref: NodeGitReference) => boolean): Promise<T[]> {
		const references = await owner.nodegitRepository.getReferences();
		return references.filter(ref_fn).map(ref => new Target(owner, ref));
	}
}
 |