Skip to content

Commit

Permalink
Improve versioning from shallow git clones
Browse files Browse the repository at this point in the history
if an annotated tag is found, the git describe string will be similar to:
v0.7.2-15-g2c897d90

When using shallow clones, the commit being built may not have an
annotated tag in its history, `git describe` will only be the
abbreviated commit hash in this case:
2c897d9

This commit tries to detect these situations, and adds a 'git' prefix to
the hash in these cases to make the version info look a bit better:

$ gvproxy --version:
gvproxy version git2c897d90

Signed-off-by: Christophe Fergeau <[email protected]>
  • Loading branch information
cfergeau committed Jan 22, 2024
1 parent 7314677 commit 6ded4a2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/types/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ func moduleVersion() string {
return gitArchiveVersion
// This will be set when building from git using make
case gitVersion != "":
if !strings.HasPrefix(gitVersion, "v") {
// if an annotated tag is found, the git describe string will be similar to:
// v0.7.2-15-g2c897d90
// When using shallow clones, the commit being built
// may not have an annotated tag in its history,
// `git describe` will only be the abbreviated commit hash in this case:
// 2c897d90
return fmt.Sprintf("git%s", gitVersion)

}
return gitVersion
// moduleVersionFromBuildInfo() will be set when using `go install`
default:
Expand Down

0 comments on commit 6ded4a2

Please sign in to comment.