From fc85cef9e1428e6f28c3e2994b1d918e5bf3cb98 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 7 Jun 2023 14:57:37 +0200 Subject: [PATCH] git: fall back to git tag in detached HEAD state Signed-off-by: CrazyMax --- src/git.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/git.ts b/src/git.ts index 44f61fe..5a0306c 100644 --- a/src/git.ts +++ b/src/git.ts @@ -61,7 +61,13 @@ export class Git { } public static async ref(): Promise { - return await Git.exec(['symbolic-ref', 'HEAD']); + return await Git.exec(['symbolic-ref', 'HEAD']).catch(() => { + // if it fails (for example in a detached HEAD state), falls back to + // using git tag or describe to get the exact matching tag name. + return Git.tag().then(tag => { + return `refs/tags/${tag}`; + }); + }); } public static async fullCommit(): Promise {