diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-09-13 12:02:03 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-09-14 09:24:56 +0300 |
commit | 5958cf6357310f932b49915458ce8b9b592f7e9d (patch) | |
tree | 420634f48b7a83bec66b1a7232fdbc612beb769a | |
parent | 15267b19d750c9b09f134039fc822f220ce80599 (diff) |
git: Implement version check for git-update-ref(1) status flushing
In the updateref package, we'll want to conditionally wait for status
reports after doing transactional status transitions. This logic depends
on whether git-update-ref(1) correctly flushes status updates to its
stdout though, which is only supported starting either with Git v2.34 or
with our backported patch in Git v2.33.0.gl3.
Provide a function which determines support for correct flushing
semantics via a version check.
-rw-r--r-- | internal/git/version.go | 17 | ||||
-rw-r--r-- | internal/git/version_test.go | 19 |
2 files changed, 36 insertions, 0 deletions
diff --git a/internal/git/version.go b/internal/git/version.go index 0fdbc091e..dddf152ee 100644 --- a/internal/git/version.go +++ b/internal/git/version.go @@ -104,6 +104,23 @@ func (v Version) SupportsObjectTypeFilter() bool { return !v.LessThan(Version{major: 2, minor: 32, patch: 0}) } +// FlushesUpdaterefStatus determines whether the given Git version properly flushes status messages +// in git-update-ref(1). +func (v Version) FlushesUpdaterefStatus() bool { + // We need to be a bit more careful here given that this comes in via a custom patch. The + // fix will be released as part of v2.34, so it's either in v2.33 with at least patch level + // 3, or it's greater than or equal to v2.34. + switch { + case v.major == 2 && v.minor == 33 && v.gl >= 3: + return true + case v.major == 2 && v.minor >= 34: + return true + case v.major >= 3: + return true + } + return false +} + // LessThan determines whether the version is older than another version. func (v Version) LessThan(other Version) bool { switch { diff --git a/internal/git/version_test.go b/internal/git/version_test.go index a7a31c392..a452c0f50 100644 --- a/internal/git/version_test.go +++ b/internal/git/version_test.go @@ -247,6 +247,25 @@ func TestVersion_SupportsObjectTypeFilter(t *testing.T) { version string expect bool }{ + {"2.32.0.gl3", false}, + {"2.33.0.gl3", true}, + {"2.33.1.gl3", true}, + {"2.34.0", true}, + {"3.0.0", true}, + } { + t.Run(tc.version, func(t *testing.T) { + version, err := parseVersion(tc.version) + require.NoError(t, err) + require.Equal(t, tc.expect, version.FlushesUpdaterefStatus()) + }) + } +} + +func TestVersion_FlushesUpdaterefStatus(t *testing.T) { + for _, tc := range []struct { + version string + expect bool + }{ {"2.31.0", false}, {"2.31.0-rc0", false}, {"2.31.1", false}, |