From 8c6a59cd766fead4998c957d86a0e33fd58d1cde Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 5 Aug 2021 17:03:36 +0200 Subject: The tree API has a branch query param & made repository branch less hardcoded --- packages/server/src/git/repository.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'packages/server/src/git/repository.ts') diff --git a/packages/server/src/git/repository.ts b/packages/server/src/git/repository.ts index 411c4fb..87c6d3a 100644 --- a/packages/server/src/git/repository.ts +++ b/packages/server/src/git/repository.ts @@ -34,12 +34,11 @@ interface WeirdError extends Error { * A representation of an bare git repository */ export class Repository { - private _branch: string; - public ng_repository: NodeGitRepository; public name: RepositoryName; public base_dir: string; + public branch_name: string; /** * @param repository - An instance of a Nodegit repository @@ -53,7 +52,7 @@ export class Repository { }; this.base_dir = dirname(repository.path()); - this._branch = branch; + this.branch_name = branch; } /** @@ -76,7 +75,7 @@ export class Repository { * @returns An instance of a branch */ public branch(): Promise { - return Branch.lookup(this, this._branch); + return Branch.lookup(this, this.branch_name); } /** @@ -87,11 +86,20 @@ export class Repository { public async commits(): Promise { const walker = NodeGitRevwalk.create(this.ng_repository); - walker.pushRef(`refs/heads/${this._branch}`); + walker.pushRef(`refs/heads/${this.branch_name}`); return Promise.all((await walker.getCommitsUntil(() => true)).map(commit => new Commit(this, commit))); } + /** + * Returns the repository's head commit + * + * @returns An instance of a commit + */ + public async head(): Promise { + return Commit.branchCommit(this); + } + /** * Returns the repository's tree * @@ -133,15 +141,6 @@ export class Repository { return references.filter(ref => ref.isTag()).map(ref => new Tag(this, ref)); } - /** - * Returns the repository's master commit - * - * @returns An instance of a commit - */ - public async masterCommit(): Promise { - return Commit.masterCommit(this); - } - /** * Connect to the Git HTTP backend * -- cgit v1.2.3-18-g5258