diff options
author | HampusM <hampus@hampusmat.com> | 2021-07-26 23:56:53 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-07-26 23:56:53 +0200 |
commit | 09ff261f156a8599d45c1496fe246ded6e035191 (patch) | |
tree | 306f79709da372b562eca70d356fa25afcde1f95 /packages/server/src/git/tree.ts | |
parent | c575df758b269db8e05c597d5870e948771d4c2b (diff) |
Added backend TSDoc/JSDoc comments & refactored a tiny bit
Diffstat (limited to 'packages/server/src/git/tree.ts')
-rw-r--r-- | packages/server/src/git/tree.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/packages/server/src/git/tree.ts b/packages/server/src/git/tree.ts index ca645ef..6c08e1a 100644 --- a/packages/server/src/git/tree.ts +++ b/packages/server/src/git/tree.ts @@ -3,22 +3,40 @@ import { Repository } from "./repository"; import { BaseTreeEntry, createTreeEntry, TreeEntry } from "./tree_entry"; import { createError, TreeError } from "./error"; +/** + * A representation of a git tree + */ export class Tree { protected _owner: Repository; protected _ng_tree: NodeGitTree; public path: string; + /** + * @param owner The repository which the tree is in + * @param tree An instance of a Nodegit tree + */ constructor(owner: Repository, tree: NodeGitTree) { this._owner = owner; this._ng_tree = tree; this.path = tree.path(); } + /** + * The tree's entries + * + * @returns An array of tree entry instances + */ public entries(): TreeEntry[] { return this._ng_tree.entries().map(entry => new TreeEntry(this._owner, entry)); } + /** + * Returns the entry of a path + * + * @param path - The path of a blob or tree + * @returns An instance of an tree entry + */ public async find(path: string): Promise<BaseTreeEntry> { const entry = await this._ng_tree.getEntry(path).catch(err => { if(err.errno === -3) { @@ -30,12 +48,29 @@ export class Tree { return createTreeEntry(this._owner, entry); } + /** + * Returns if a path exists or not + * + * @param path - The path to look for + * @returns Whether or not there exists an entry for the path + */ public findExists(path: string): Promise<boolean> { return this._ng_tree.getEntry(path) .then(() => true) .catch(() => false); } + /** + * Returns the tree of a repository + * + * @remarks + * + * Assumes that you want to use the master branch. + * This will be fixed in the future. + * + * @param owner The repository which the tree is in + * @returns An instance of a tree + */ public static async ofRepository(owner: Repository): Promise<Tree> { const master_commit = await owner.masterCommit(); return master_commit.tree(); |