aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/tree.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server/src/git/tree.ts')
-rw-r--r--packages/server/src/git/tree.ts16
1 files changed, 9 insertions, 7 deletions
diff --git a/packages/server/src/git/tree.ts b/packages/server/src/git/tree.ts
index 8697010..2cec528 100644
--- a/packages/server/src/git/tree.ts
+++ b/packages/server/src/git/tree.ts
@@ -2,6 +2,7 @@ import { Blob } from "./blob";
import { Tree as NodeGitTree } from "nodegit";
import { Repository } from "./repository";
import { TreeEntry } from "./tree_entry";
+import { createError, TreeError } from "./error";
export class Tree {
private _ng_tree: NodeGitTree;
@@ -16,18 +17,14 @@ export class Tree {
return this._ng_tree.entries().map(entry => new TreeEntry(this._owner, entry));
}
- public async find(path: string): Promise<Blob | Tree | null> {
+ public async find(path: string): Promise<Blob | Tree> {
const entry = await this._ng_tree.getEntry(path).catch(err => {
if(err.errno === -3) {
- return null;
+ throw(createError(TreeError, 404, "Path not found"));
}
- throw(err);
+ throw(createError(TreeError, 500, "Failed to get tree path"));
});
- if(!entry) {
- return null;
- }
-
return entry.isBlob() ? new Blob(entry) : new Tree(this._owner, await entry.getTree());
}
@@ -36,4 +33,9 @@ export class Tree {
.then(() => true)
.catch(() => false);
}
+
+ public static async ofRepository(owner: Repository): Promise<Tree> {
+ const master_commit = await owner.masterCommit();
+ return master_commit.tree();
+ }
} \ No newline at end of file