aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/tree_entry.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server/src/git/tree_entry.ts')
-rw-r--r--packages/server/src/git/tree_entry.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/packages/server/src/git/tree_entry.ts b/packages/server/src/git/tree_entry.ts
index e4780c8..52f9988 100644
--- a/packages/server/src/git/tree_entry.ts
+++ b/packages/server/src/git/tree_entry.ts
@@ -5,12 +5,19 @@ import { dirname } from "path";
import { findAsync } from "./misc";
import { Tree } from "./tree";
+/**
+ * The core structure of a tree entry
+ */
export abstract class BaseTreeEntry {
protected _ng_tree_entry: NodeGitTreeEntry;
protected _owner: Repository;
public path: string;
+ /**
+ * @param owner - The repository which the tree entry is in
+ * @param entry - An instance of a Nodegit tree entry
+ */
constructor(owner: Repository, entry: NodeGitTreeEntry) {
this._ng_tree_entry = entry;
this._owner = owner;
@@ -18,6 +25,11 @@ export abstract class BaseTreeEntry {
this.path = entry.path();
}
+ /**
+ * Returns the tree entry's latest commit
+ *
+ * @returns An instance of a commit
+ */
public async latestCommit(): Promise<Commit> {
const commits = await this._owner.commits();
@@ -32,18 +44,39 @@ export abstract class BaseTreeEntry {
}
}
+/**
+ * A representation of a tree entry that's a tree
+ */
export class TreeEntry extends BaseTreeEntry {
+ /**
+ * Returns the tree of the tree entry
+ *
+ * @returns An instance of a tree
+ */
public async tree(): Promise<Tree> {
return new Tree(this._owner, await this._ng_tree_entry.getTree());
}
}
+/**
+ * A representation of a tree entry that's a blob
+ */
export class BlobTreeEntry extends BaseTreeEntry {
+ /**
+ * Returns the blob's content
+ */
public async content(): Promise<string> {
return (await this._ng_tree_entry.getBlob()).toString();
}
}
+/**
+ * A factory which creates a tree entry
+ *
+ * @param owner - The repository that the tree entry is in
+ * @param entry - An instance of a Nodegit tree entry
+ * @returns An instance of a tree entry
+ */
export function createTreeEntry(owner: Repository, entry: NodeGitTreeEntry): BaseTreeEntry {
return entry.isBlob()
? new BlobTreeEntry(owner, entry)