From 2c8307b3d8e0d5bf68b5e7edb1deef180883b458 Mon Sep 17 00:00:00 2001 From: Wladimir Palant <374261+palant@users.noreply.github.com> Date: Thu, 24 Oct 2024 02:50:30 +0200 Subject: [PATCH] fix: Do not require Git for development (#3015) --- config/env.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/config/env.ts b/config/env.ts index 87429089..d2d31d2d 100644 --- a/config/env.ts +++ b/config/env.ts @@ -29,9 +29,30 @@ export const isPreview = isPR || process.env.CONTEXT === 'deploy-preview' || pro const git = Git() export async function getGitInfo() { - const branch = gitBranch || await git.revparse(['--abbrev-ref', 'HEAD']) - const commit = await git.revparse(['HEAD']) - const shortCommit = await git.revparse(['--short=7', 'HEAD']) + let branch + try { + branch = gitBranch || await git.revparse(['--abbrev-ref', 'HEAD']) + } + catch { + branch = 'unknown' + } + + let commit + try { + commit = await git.revparse(['HEAD']) + } + catch { + commit = 'unknown' + } + + let shortCommit + try { + shortCommit = await git.revparse(['--short=7', 'HEAD']) + } + catch { + shortCommit = 'unknown' + } + return { branch, commit, shortCommit } }