git: fall back to git tag in detached HEAD state

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-06-07 14:57:37 +02:00
parent fdd740da2d
commit fc85cef9e1
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7

View File

@ -61,7 +61,13 @@ export class Git {
}
public static async ref(): Promise<string> {
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<string> {