From 09ff261f156a8599d45c1496fe246ded6e035191 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 26 Jul 2021 23:56:53 +0200 Subject: Added backend TSDoc/JSDoc comments & refactored a tiny bit --- packages/server/src/git/tree.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'packages/server/src/git/tree.ts') 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 { 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 { 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 { const master_commit = await owner.masterCommit(); return master_commit.tree(); -- cgit v1.2.3-18-g5258