From e361ea833b88a133d1f678910a49d479fd8f6e59 Mon Sep 17 00:00:00 2001 From: Nicholas Charriere Date: Fri, 25 Oct 2024 13:25:08 -0700 Subject: [PATCH] Handle non existing git repo (#425) * Handle non existing git repo * Add changeset --- .changeset/smart-elephants-fly.md | 6 ++++++ packages/api/apps/git.mts | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 .changeset/smart-elephants-fly.md diff --git a/.changeset/smart-elephants-fly.md b/.changeset/smart-elephants-fly.md new file mode 100644 index 00000000..9f0db3d1 --- /dev/null +++ b/.changeset/smart-elephants-fly.md @@ -0,0 +1,6 @@ +--- +'@srcbook/api': patch +'srcbook': patch +--- + +Bugfix: dont crash if the git repo didnt previously exist diff --git a/packages/api/apps/git.mts b/packages/api/apps/git.mts index 1c6120c0..2ef5fbfd 100644 --- a/packages/api/apps/git.mts +++ b/packages/api/apps/git.mts @@ -81,7 +81,14 @@ export async function ensureRepoExists(app: DBAppType): Promise { // Get the current commit SHA export async function getCurrentCommitSha(app: DBAppType): Promise { const git = getGit(app); + // There might not be a .git initialized yet, so we need to handle that + const isRepo = await git.checkIsRepo(); + if (!isRepo) { + await initRepo(app); + } + const revparse = await git.revparse(['HEAD']); + return revparse; }