diff options
author | HampusM <hampus@hampusmat.com> | 2021-07-26 17:33:54 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-07-26 17:33:54 +0200 |
commit | a737bc4695f99b05a3c4807c88fc30b1a1eb89b5 (patch) | |
tree | 4ca8f9955a80a09a508c55f86daeb2aba2ae64ac /packages/server/src/git/tree.ts | |
parent | 35151a0283141ddac96f8cc71b59cd1030e31f3d (diff) |
Refactored the git tree, tree entry & blob classes
Diffstat (limited to 'packages/server/src/git/tree.ts')
-rw-r--r-- | packages/server/src/git/tree.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/packages/server/src/git/tree.ts b/packages/server/src/git/tree.ts index 2cec528..ca645ef 100644 --- a/packages/server/src/git/tree.ts +++ b/packages/server/src/git/tree.ts @@ -1,23 +1,25 @@ -import { Blob } from "./blob"; import { Tree as NodeGitTree } from "nodegit"; import { Repository } from "./repository"; -import { TreeEntry } from "./tree_entry"; +import { BaseTreeEntry, createTreeEntry, TreeEntry } from "./tree_entry"; import { createError, TreeError } from "./error"; export class Tree { - private _ng_tree: NodeGitTree; - private _owner: Repository; + protected _owner: Repository; + protected _ng_tree: NodeGitTree; + + public path: string; constructor(owner: Repository, tree: NodeGitTree) { - this._ng_tree = tree; this._owner = owner; + this._ng_tree = tree; + this.path = tree.path(); } public entries(): TreeEntry[] { return this._ng_tree.entries().map(entry => new TreeEntry(this._owner, entry)); } - public async find(path: string): Promise<Blob | Tree> { + public async find(path: string): Promise<BaseTreeEntry> { const entry = await this._ng_tree.getEntry(path).catch(err => { if(err.errno === -3) { throw(createError(TreeError, 404, "Path not found")); @@ -25,7 +27,7 @@ export class Tree { throw(createError(TreeError, 500, "Failed to get tree path")); }); - return entry.isBlob() ? new Blob(entry) : new Tree(this._owner, await entry.getTree()); + return createTreeEntry(this._owner, entry); } public findExists(path: string): Promise<boolean> { |