Skip to content

Commit f05a598

Browse files
authored
Merge pull request #112 from crazy-max/fix-git-ref
git: fall back to git tag in detached HEAD state
2 parents a5b683b + fc85cef commit f05a598

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/git.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ export class Git {
6161
}
6262

6363
public static async ref(): Promise<string> {
64-
return await Git.exec(['symbolic-ref', 'HEAD']);
64+
return await Git.exec(['symbolic-ref', 'HEAD']).catch(() => {
65+
// if it fails (for example in a detached HEAD state), falls back to
66+
// using git tag or describe to get the exact matching tag name.
67+
return Git.tag().then(tag => {
68+
return `refs/tags/${tag}`;
69+
});
70+
});
6571
}
6672

6773
public static async fullCommit(): Promise<string> {

0 commit comments

Comments
 (0)