diff options
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 |