Skip to content

Commit

Permalink
git: fall back to git tag in detached HEAD state
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Jun 7, 2023
1 parent fdd740d commit fc85cef
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit fc85cef

Please sign in to comment.