aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/repository.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-08-18 17:29:55 +0200
committerHampusM <hampus@hampusmat.com>2021-08-18 17:29:55 +0200
commitd1a1b7dc947063aef5f8375a6a1e03246b272c84 (patch)
treef5cb9bd6d4b5463d9d022026ac6fea87cb6ebe02 /packages/server/src/git/repository.ts
parent6ed078de30a7bf35deace728857d1d293d59eb15 (diff)
Implemented caching for certain API endpoints, Added documentation & made backend-fixes
Diffstat (limited to 'packages/server/src/git/repository.ts')
-rw-r--r--packages/server/src/git/repository.ts36
1 files changed, 29 insertions, 7 deletions
diff --git a/packages/server/src/git/repository.ts b/packages/server/src/git/repository.ts
index c1410ab..53245be 100644
--- a/packages/server/src/git/repository.ts
+++ b/packages/server/src/git/repository.ts
@@ -38,7 +38,7 @@ export class Repository {
public name: RepositoryName;
public git_dir: string;
- public branch_name: string;
+ private _branch: string;
/**
* @param repository - An instance of a Nodegit repository
@@ -52,7 +52,7 @@ export class Repository {
};
this.git_dir = dirname(repository.path());
- this.branch_name = branch;
+ this._branch = branch;
}
/**
@@ -69,23 +69,31 @@ export class Repository {
return getFile(this.git_dir, this.name.full, "owner");
}
+ get branch(): string {
+ return this._branch;
+ }
+
+ set branch(branch: string) {
+ this._branch = branch;
+ }
+
/**
* Returns the repository's branch
*
* @returns An instance of a branch
*/
- public branch(): Promise<Branch> {
- return Branch.lookup(this, this.branch_name);
+ public getBranch(): Promise<Branch> {
+ return Branch.lookup(this, this._branch);
}
/**
* Returns the repository's commits
*
- * @param [count=20] - The number of commits to get
+ * @param [amount=20] - The number of commits to get or whether or not to get all commits
* @returns An array of commit instances
*/
- public async commits(count?: number): Promise<Commit[]> {
- return Commit.getMultiple(this, count);
+ public async commits(amount?: number | boolean): Promise<Commit[]> {
+ return Commit.getMultiple(this, amount);
}
/**
@@ -119,6 +127,20 @@ export class Repository {
}
/**
+ * Returns this repository instance with a different branch
+ *
+ * @param branch - The branch to switch to
+ * @returns An instance of a repository
+ */
+ public async withBranch(branch: string): Promise<Repository> {
+ if(!await Branch.lookupExists(this.ng_repository, branch)) {
+ throw(createError(ErrorWhere.Repository, NotFoundError, "branch"));
+ }
+
+ return new Repository(this.ng_repository, branch);
+ }
+
+ /**
* Returns the repository's branches
*
* @returns An array of branch instances