version.go 743 B

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import "runtime/debug"
  3. // version is the release number shown on the About page. Bump it in the PR
  4. // that makes a user-visible change.
  5. const version = "0.5.1"
  6. // buildCommit returns the short git revision that `go build` stamped into the
  7. // binary, with "-dirty" if the tree had uncommitted changes, or "" if the
  8. // binary was built outside a git checkout.
  9. func buildCommit() string {
  10. info, ok := debug.ReadBuildInfo()
  11. if !ok {
  12. return ""
  13. }
  14. var rev string
  15. var dirty bool
  16. for _, s := range info.Settings {
  17. switch s.Key {
  18. case "vcs.revision":
  19. rev = s.Value
  20. case "vcs.modified":
  21. dirty = s.Value == "true"
  22. }
  23. }
  24. if len(rev) > 7 {
  25. rev = rev[:7]
  26. }
  27. if rev != "" && dirty {
  28. rev += "-dirty"
  29. }
  30. return rev
  31. }