From a13786d6cc185822f5940582efde2349ef729145 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 24 Jun 2021 22:50:38 +0200 Subject: Refactored the backend yet again --- packages/server/src/git/branch.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 packages/server/src/git/branch.ts (limited to 'packages/server/src/git/branch.ts') diff --git a/packages/server/src/git/branch.ts b/packages/server/src/git/branch.ts new file mode 100644 index 0000000..2142724 --- /dev/null +++ b/packages/server/src/git/branch.ts @@ -0,0 +1,24 @@ +import { CommitSummary } from "./commit"; +import { Reference } from "./reference"; +import { Repository } from "./repository"; + +export class Branch extends Reference { + async latestCommit(): Promise { + const latest_commit = this._owner.nodegitRepository.getBranchCommit(this._ng_reference); + return { + id: (await latest_commit).sha(), + message: (await latest_commit).message(), + date: (await latest_commit).time() + }; + } + + static async lookup(owner: Repository, branch: string): Promise { + const reference = await owner.nodegitRepository.getBranch(branch).catch(err => { + if(err.errno === -3) { + return null; + } + throw(err); + }); + return reference ? new Branch(owner, reference) : null; + } +} \ No newline at end of file -- cgit v1.2.3-18-g5258