diff options
author | HampusM <hampus@hampusmat.com> | 2021-06-24 22:50:38 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-06-24 22:50:38 +0200 |
commit | a13786d6cc185822f5940582efde2349ef729145 (patch) | |
tree | 7d4f49b50fc30ced65c5661b22b027456b79948e /packages/server/src/git/branch.ts | |
parent | 01e5d215dbc152e34ecd005111171457f87c235d (diff) |
Refactored the backend yet again
Diffstat (limited to 'packages/server/src/git/branch.ts')
-rw-r--r-- | packages/server/src/git/branch.ts | 24 |
1 files changed, 24 insertions, 0 deletions
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<CommitSummary> { + 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<Branch | null> { + 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 |