summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-08-01 20:04:22 +1000
committerJesse Duffield <jessedduffield@gmail.com>2022-08-01 20:16:50 +1000
commit86ac309e08f940bfe5be8a3a7bf0e5288786bee9 (patch)
treeb267377e1b5b5104db019cdb285d47957aebec56 /main.go
parent69f4292fe3d0d3422a193a0669c1ed0d41883b41 (diff)
add build info when building from source
Diffstat (limited to 'main.go')
-rw-r--r--main.go45
1 files changed, 44 insertions, 1 deletions
diff --git a/main.go b/main.go
index 3a0f07148..e21751c27 100644
--- a/main.go
+++ b/main.go
@@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"runtime"
+ "runtime/debug"
"strings"
"github.com/integrii/flaggy"
@@ -16,17 +17,23 @@ import (
"github.com/jesseduffield/lazygit/pkg/env"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/logs"
+ "github.com/jesseduffield/lazygit/pkg/utils"
yaml "github.com/jesseduffield/yaml"
+ "github.com/samber/lo"
)
+const DEFAULT_VERSION = "unversioned"
+
var (
commit string
- version = "unversioned"
+ version = DEFAULT_VERSION
date string
buildSource = "unknown"
)
func main() {
+ updateBuildInfo()
+
flaggy.DefaultParser.ShowVersionWithVersionFlag = false
repoPath := ""
@@ -67,6 +74,10 @@ func main() {
flaggy.Parse()
+ if os.Getenv("DEBUG") == "TRUE" {
+ debuggingFlag = true
+ }
+
if repoPath != "" {
if workTree != "" || gitDir != "" {
log.Fatal("--path option is incompatible with the --work-tree and --git-dir options")
@@ -177,3 +188,35 @@ func parseGitArg(gitArg string) types.GitArg {
panic("unreachable")
}
+
+func updateBuildInfo() {
+ // if the version has already been set by build flags then we'll honour that.
+ // chances are it's something like v0.31.0 which is more informative than a
+ // commit hash.
+ if version != DEFAULT_VERSION {
+ return
+ }
+
+ buildInfo, ok := debug.ReadBuildInfo()
+ if !ok {
+ return
+ }
+
+ revision, ok := lo.Find(buildInfo.Settings, func(setting debug.BuildSetting) bool {
+ return setting.Key == "vcs.revision"
+ })
+ if ok {
+ commit = revision.Value
+ // if lazygit was built from source we'll show the version as the
+ // abbreviated commit hash
+ version = utils.ShortSha(revision.Value)
+ }
+
+ // if version hasn't been set we assume that neither has the date
+ time, ok := lo.Find(buildInfo.Settings, func(setting debug.BuildSetting) bool {
+ return setting.Key == "vcs.time"
+ })
+ if ok {
+ date = time.Value
+ }
+}