Files
lazygit/pkg/app/entry_point_test.go
Stefan HallerandClaude Opus 5.5 cc7f8f483b Show which release a build from a git checkout is based on
For a build from a git checkout, lazygit reported the abbreviated commit hash as its version, e.g. in the bottom-right corner. This didn't say which release the build was based on, or whether it had uncommitted changes.

Go records a module version for such builds too. It is a pseudo-version
that contains the release that the commit is based on, or the tag of the
commit, followed by "+dirty" if there were uncommitted changes. Show the
release and the commit, e.g. "v0.66.3+d0d00783", the same way as for
builds made with `go install` from a branch, and append "-dirty" if
there were uncommitted changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:11:45 +01:00

99 lines
3.2 KiB
Go

package app
import (
"runtime/debug"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMergeBuildInfo(t *testing.T) {
scenarios := []struct {
name string
buildInfo BuildInfo
goBuildInfo *debug.BuildInfo
expected BuildInfo
}{
{
name: "version set by ldflags",
buildInfo: BuildInfo{Version: "0.66.2", BuildSource: "binaryRelease"},
goBuildInfo: &debug.BuildInfo{
Main: debug.Module{Version: "(devel)"},
Settings: []debug.BuildSetting{{Key: "vcs.revision", Value: "0123456789abcdef"}},
},
expected: BuildInfo{Version: "0.66.2", BuildSource: "binaryRelease"},
},
{
name: "built from a git checkout",
buildInfo: BuildInfo{BuildSource: "unknown"},
goBuildInfo: &debug.BuildInfo{
Main: debug.Module{Version: "v0.66.3-0.20261103120000-0123456789ab+dirty"},
Settings: []debug.BuildSetting{
{Key: "vcs.revision", Value: "0123456789abcdef"},
{Key: "vcs.time", Value: "2026-11-03T12:00:00Z"},
},
},
expected: BuildInfo{
Commit: "0123456789abcdef",
Date: "2026-11-03T12:00:00Z",
Version: "v0.66.2+01234567-dirty",
BuildSource: "unknown",
},
},
{
name: "built from a git checkout at a tag",
buildInfo: BuildInfo{BuildSource: "unknown"},
goBuildInfo: &debug.BuildInfo{
Main: debug.Module{Version: "v0.66.2"},
Settings: []debug.BuildSetting{{Key: "vcs.revision", Value: "0123456789abcdef"}},
},
expected: BuildInfo{Commit: "0123456789abcdef", Version: "v0.66.2+01234567", BuildSource: "unknown"},
},
{
name: "built from a git checkout without module version",
buildInfo: BuildInfo{BuildSource: "unknown"},
goBuildInfo: &debug.BuildInfo{
Main: debug.Module{Version: "(devel)"},
Settings: []debug.BuildSetting{{Key: "vcs.revision", Value: "0123456789abcdef"}},
},
expected: BuildInfo{Commit: "0123456789abcdef", Version: "01234567", BuildSource: "unknown"},
},
{
name: "built with go install",
buildInfo: BuildInfo{BuildSource: "unknown"},
goBuildInfo: &debug.BuildInfo{Main: debug.Module{Version: "v0.66.2"}},
expected: BuildInfo{Version: "0.66.2", BuildSource: "goInstall"},
},
{
name: "built with go install from a branch",
buildInfo: BuildInfo{BuildSource: "unknown"},
goBuildInfo: &debug.BuildInfo{
Main: debug.Module{Version: "v0.66.3-0.20261103120000-0123456789ab"},
},
expected: BuildInfo{Commit: "0123456789ab", Version: "v0.66.2+01234567", BuildSource: "unknown"},
},
{
name: "built with go install from a branch without tags",
buildInfo: BuildInfo{BuildSource: "unknown"},
goBuildInfo: &debug.BuildInfo{
Main: debug.Module{Version: "v0.0.0-20261103120000-0123456789ab"},
},
expected: BuildInfo{Commit: "0123456789ab", Version: "01234567", BuildSource: "unknown"},
},
{
name: "no build info",
buildInfo: BuildInfo{BuildSource: "unknown"},
goBuildInfo: nil,
expected: BuildInfo{Version: "unversioned", BuildSource: "unknown"},
},
}
for _, s := range scenarios {
t.Run(s.name, func(t *testing.T) {
buildInfo := s.buildInfo
mergeBuildInfo(&buildInfo, s.goBuildInfo)
assert.Equal(t, s.expected, buildInfo)
})
}
}