diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-02-15 01:18:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-14 17:18:30 +0000 |
commit | d0183dfa49125a9e533dbe8beab4d8a3724a4f07 (patch) | |
tree | d296ab35ae6b79499ea9ccbde7130e97c0458eb0 /modules/git/git_test.go | |
parent | 37061e8266806c0b2b66ac64138e725632b295db (diff) | |
download | gitea-d0183dfa49125a9e533dbe8beab4d8a3724a4f07.tar.gz gitea-d0183dfa49125a9e533dbe8beab4d8a3724a4f07.zip |
Refactor git version functions and check compatibility (#29155)
Introduce a new function checkGitVersionCompatibility, when the git
version can't be used by Gitea, tell the end users to downgrade or
upgrade. The refactored functions are related to make the code easier to
test.
And simplify the comments for "safe.directory"
---------
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'modules/git/git_test.go')
-rw-r--r-- | modules/git/git_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/git/git_test.go b/modules/git/git_test.go index 37ab669ea4..fc92bebe04 100644 --- a/modules/git/git_test.go +++ b/modules/git/git_test.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + "github.com/hashicorp/go-version" "github.com/stretchr/testify/assert" ) @@ -93,3 +94,25 @@ func TestSyncConfig(t *testing.T) { assert.True(t, gitConfigContains("[sync-test]")) assert.True(t, gitConfigContains("cfg-key-a = CfgValA")) } + +func TestParseGitVersion(t *testing.T) { + v, err := parseGitVersionLine("git version 2.29.3") + assert.NoError(t, err) + assert.Equal(t, "2.29.3", v.String()) + + v, err = parseGitVersionLine("git version 2.29.3.windows.1") + assert.NoError(t, err) + assert.Equal(t, "2.29.3", v.String()) + + _, err = parseGitVersionLine("git version") + assert.Error(t, err) + + _, err = parseGitVersionLine("git version windows") + assert.Error(t, err) +} + +func TestCheckGitVersionCompatibility(t *testing.T) { + assert.NoError(t, checkGitVersionCompatibility(version.Must(version.NewVersion("2.43.0")))) + assert.ErrorContains(t, checkGitVersionCompatibility(version.Must(version.NewVersion("2.43.1"))), "regression bug of GIT_FLUSH") + assert.NoError(t, checkGitVersionCompatibility(version.Must(version.NewVersion("2.43.2")))) +} |