MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / baseVersion

Function baseVersion

internal/update/update.go:188–202  ·  view source on GitHub ↗

baseVersion extracts the base semver from a git-describe version string. For example, "0.4.0-61-gd06835b" returns "0.4.0". Handles dirty builds too: "0.4.0-61-gd06835b-dirty" returns "0.4.0". A plain version like "0.4.0" is returned unchanged.

(v string)

Source from the content-addressed store, hash-verified

186// Handles dirty builds too: "0.4.0-61-gd06835b-dirty" returns "0.4.0".
187// A plain version like "0.4.0" is returned unchanged.
188func baseVersion(v string) string {
189 v = normalizeVersion(v)
190 // Strip "-dirty" suffix from uncommitted builds.
191 v = strings.TrimSuffix(v, "-dirty")
192 // Git describe format: "0.4.0-61-gd06835b" (tag-commits-ghash)
193 // Strip the "-N-gHASH" suffix to get the base semver.
194 parts := strings.Split(v, "-")
195 if len(parts) >= 3 {
196 last := parts[len(parts)-1]
197 if strings.HasPrefix(last, "g") {
198 return strings.Join(parts[:len(parts)-2], "-")
199 }
200 }
201 return v
202}
203
204// CompareVersions returns true if latest is different from the base version of current.
205// Dev builds (e.g. "0.4.0-61-gd06835b") are compared by their base tag ("0.4.0").

Callers 4

CheckForUpdateFunction · 0.85
PerformUpdateFunction · 0.85
CompareVersionsFunction · 0.85
TestBaseVersionFunction · 0.85

Calls 1

normalizeVersionFunction · 0.85

Tested by 1

TestBaseVersionFunction · 0.68