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:
authorEric Ju <eju@gitlab.com>2023-12-05 18:41:09 +0300
committerEric Ju <eju@gitlab.com>2023-12-05 18:41:09 +0300
commitc10249b8a6033a6cd59f1c47048a24b9492d3d65 (patch)
tree940a96cc166678c9a98200e6d733f20d2f3fbcdc
parent9b54bcc1d8e0ddcefcfdf9142a16778d02a23957 (diff)
git: Add GitattributesSupportReadingFromHead flagej-5720-add-flag-GitatrributesSupportsReadingFromHead
Git 2.43.0 starts supporting reading gitattributes from HEAD reference. This is a required feature for us to get rid of gitattributes-related RPCs. This `GitattributesSupportReadingFromHead` flag function check if current git version is above or equal 2.43.0.
-rw-r--r--internal/git/version.go8
-rw-r--r--internal/git/version_test.go26
2 files changed, 34 insertions, 0 deletions
diff --git a/internal/git/version.go b/internal/git/version.go
index 4a552b62c..e0d81043a 100644
--- a/internal/git/version.go
+++ b/internal/git/version.go
@@ -109,6 +109,14 @@ func (v Version) LessThan(other Version) bool {
}
}
+// GitattributesSupportReadingFromHead detects whether the Git version supports reading
+// gitattributes from HEAD reference in bare repositories automatically.
+func (v Version) GitattributesSupportReadingFromHead() bool {
+ return !v.LessThan(Version{
+ major: 2, minor: 43,
+ })
+}
+
func parseVersion(versionStr string) (Version, error) {
versionSplit := strings.SplitN(versionStr, ".", 4)
if len(versionSplit) < 3 {
diff --git a/internal/git/version_test.go b/internal/git/version_test.go
index c9a0db8fb..e7374da77 100644
--- a/internal/git/version_test.go
+++ b/internal/git/version_test.go
@@ -122,3 +122,29 @@ func TestVersion_IsSupported(t *testing.T) {
})
}
}
+
+func TestVersion_GitattributesSupportReadingFromHead(t *testing.T) {
+ t.Parallel()
+
+ for _, tc := range []struct {
+ version string
+ expect bool
+ }{
+ {"1.0.0", false},
+ {"2.40.2", false},
+ {"2.41.0", false},
+ {"2.42.0", false},
+ {"2.42.2", false},
+ {"2.43.0", true},
+ {"2.43.1.gl2", true},
+ {"3.0.0", true},
+ } {
+ tc := tc
+ t.Run(tc.version, func(t *testing.T) {
+ version, err := parseVersion(tc.version)
+ require.NoError(t, err)
+ require.Equal(t, tc.expect,
+ version.GitattributesSupportReadingFromHead())
+ })
+ }
+}