From 33825e39fe341989f8dee41bcb270108fc0d1bf2 Mon Sep 17 00:00:00 2001 From: zkldi Date: Fri, 9 Dec 2022 20:39:26 +0000 Subject: [PATCH] feat: allow switching branches on local dbseeds --- server/src/lib/database-seeds/repo.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/src/lib/database-seeds/repo.ts b/server/src/lib/database-seeds/repo.ts index 3acbc5fbb..9cc0f95e7 100644 --- a/server/src/lib/database-seeds/repo.ts +++ b/server/src/lib/database-seeds/repo.ts @@ -42,6 +42,14 @@ export class DatabaseSeedsRepo { this.shouldDestroy = shouldDestroy; } + /** + * Switch this repository to a new branch. This operation may + * fail if there are uncommitted changes. + */ + switchBranch(newBranch: string) { + return asyncExec(`git switch '${newBranch}'`, this.baseDir); + } + private CollectionNameToPath(collectionName: SeedsCollections) { return path.join(this.baseDir, `${collectionName}.json`); } @@ -224,7 +232,11 @@ export async function PullDatabaseSeeds( : "staging" ) { if (fetchFromLocalPath) { - return new DatabaseSeedsRepo(fetchFromLocalPath); + const local = new DatabaseSeedsRepo(fetchFromLocalPath); + + await local.switchBranch(branch); + + return local; } if (!ServerConfig.SEEDS_CONFIG) {