aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/reference.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-07-21 22:00:04 +0200
committerHampusM <hampus@hampusmat.com>2021-07-21 22:00:04 +0200
commit7b9fca8d0061cf5e5af08cba98e9d5b6dbbed8ec (patch)
tree2a75dfaaa495c90e5519012e2c8e20ab0bd7ac4e /packages/server/src/git/reference.ts
parentc0eb6635964de276b44851df67fb857ae94dc401 (diff)
Began with better backend error handling & cleaned up the backend
Diffstat (limited to 'packages/server/src/git/reference.ts')
-rw-r--r--packages/server/src/git/reference.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/server/src/git/reference.ts b/packages/server/src/git/reference.ts
index 36f1312..b24f72d 100644
--- a/packages/server/src/git/reference.ts
+++ b/packages/server/src/git/reference.ts
@@ -1,6 +1,16 @@
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;
@@ -15,4 +25,9 @@ export abstract class Reference {
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));
+ }
} \ No newline at end of file