Skip to content

Commit

Permalink
Merge pull request #112 from crazy-max/fix-git-ref
Browse files Browse the repository at this point in the history
git: fall back to git tag in detached HEAD state
  • Loading branch information
crazy-max committed Jun 7, 2023
2 parents a5b683b + fc85cef commit f05a598
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/git.ts
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 f05a598

Please sign in to comment.