diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-04-26 08:57:45 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-04-26 11:14:22 +0300 |
commit | 29f87b312112ad31e0718ac10033cecdc8b8ab30 (patch) | |
tree | e721e60364280fbf38e1510a2fc306b597a77026 | |
parent | 2744f1ee1ad3f158b72a4149772cfb5f694453d1 (diff) |
git: Add version check for the new `core.fsync` config option
Git v2.36.0 has introduced the new `core.fsync` infrastructure, which
allows the user more fine-grained control over what exactly should be
synchronized to disk. Add a function which allows us to check whether
this new infrastructure is supported by the current Git version.
-rw-r--r-- | internal/git/version.go | 6 | ||||
-rw-r--r-- | internal/git/version_test.go | 24 |
2 files changed, 30 insertions, 0 deletions
diff --git a/internal/git/version.go b/internal/git/version.go index 981dce5e1..8f4966347 100644 --- a/internal/git/version.go +++ b/internal/git/version.go @@ -84,6 +84,12 @@ func (v Version) FlushesUpdaterefStatus() bool { }) } +// HasGranularFsyncConfig determines whether the given Git version supports the new granular fsync +// configuration via `core.fsync`. This new config has been introduced with Git v2.36.0. +func (v Version) HasGranularFsyncConfig() bool { + return !v.LessThan(Version{major: 2, minor: 36, rc: true}) +} + // 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 55bbc0ff3..6fe8c89b8 100644 --- a/internal/git/version_test.go +++ b/internal/git/version_test.go @@ -147,3 +147,27 @@ func TestVersion_FlushesUpdaterefStatus(t *testing.T) { }) } } + +func TestVersion_HasGranularFsyncConfig(t *testing.T) { + for _, tc := range []struct { + version string + expect bool + }{ + {"2.35.0", false}, + {"2.35.0-rc0", false}, + {"2.35.1", false}, + {"2.35.1.gl3", false}, + {"2.36.0-rc1", true}, + {"2.36.0", true}, + {"2.36.0.gl1", true}, + {"2.36.1", true}, + {"2.37.1", 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.HasGranularFsyncConfig()) + }) + } +} |