Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-06-15 08:53:52 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-06-21 08:49:55 +0300
commit0d53150dceed1c90dd2119291add50d86b6a4702 (patch)
tree4be8327072965ee8389b1da0a2a260c818b022cc
parent09624e64ea907f13759677bf9f712430f9de14c1 (diff)
git: Implement test to check for object type filter support
With Git v2.32.0, a new filter has been added to git-rev-list(1) which allows to filter by object type. We're about to start using this new feature, but our minimum required Git version is still at v2.31.0. As such, we can only conditionally make use of it. Add a new function `SupportsObjectTypeFilter()` which allows callers to see whether a specific Git version supports the feature. This function will be used by a subsequent commit which implements object type filters for LFS pointers.
-rw-r--r--internal/git/version.go6
-rw-r--r--internal/git/version_test.go20
2 files changed, 26 insertions, 0 deletions
diff --git a/internal/git/version.go b/internal/git/version.go
index db31701ea..cf5ca632d 100644
--- a/internal/git/version.go
+++ b/internal/git/version.go
@@ -74,6 +74,12 @@ func (v Version) IsSupported() bool {
return !v.LessThan(minimumVersion)
}
+// SupportsObjectTypeFilter checks if a version corresponds to a Git version which supports object
+// type filters.
+func (v Version) SupportsObjectTypeFilter() bool {
+ return !v.LessThan(Version{major: 2, minor: 32, patch: 0})
+}
+
// 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 123f366cd..17b832ca1 100644
--- a/internal/git/version_test.go
+++ b/internal/git/version_test.go
@@ -130,3 +130,23 @@ func TestVersion_IsSupported(t *testing.T) {
})
}
}
+
+func TestVersion_SupportsObjectTypeFilter(t *testing.T) {
+ for _, tc := range []struct {
+ version string
+ expect bool
+ }{
+ {"2.31.0", false},
+ {"2.31.0-rc0", false},
+ {"2.31.1", false},
+ {"2.32.0", true},
+ {"2.32.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.SupportsObjectTypeFilter())
+ })
+ }
+}