mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-18 15:15:18 +00:00
fix: make test suite run on older git version (#8188)
Ref: forgejo/forgejo#8140, forgejo/forgejo#8144 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8188 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
53d5e6d754
commit
90f8239448
7 changed files with 71 additions and 46 deletions
|
@ -38,6 +38,7 @@ var (
|
||||||
InvertedGitFlushEnv bool // 2.43.1
|
InvertedGitFlushEnv bool // 2.43.1
|
||||||
SupportCheckAttrOnBare bool // >= 2.40
|
SupportCheckAttrOnBare bool // >= 2.40
|
||||||
SupportGitMergeTree bool // >= 2.38
|
SupportGitMergeTree bool // >= 2.38
|
||||||
|
SupportGrepMaxCount bool // >= 2.38
|
||||||
|
|
||||||
HasSSHExecutable bool
|
HasSSHExecutable bool
|
||||||
|
|
||||||
|
@ -191,6 +192,7 @@ func InitFull(ctx context.Context) (err error) {
|
||||||
|
|
||||||
InvertedGitFlushEnv = CheckGitVersionEqual("2.43.1") == nil
|
InvertedGitFlushEnv = CheckGitVersionEqual("2.43.1") == nil
|
||||||
SupportGitMergeTree = CheckGitVersionAtLeast("2.38") == nil
|
SupportGitMergeTree = CheckGitVersionAtLeast("2.38") == nil
|
||||||
|
SupportGrepMaxCount = CheckGitVersionAtLeast("2.38") == nil
|
||||||
|
|
||||||
if setting.LFS.StartServer {
|
if setting.LFS.StartServer {
|
||||||
if CheckGitVersionAtLeast("2.1.2") != nil {
|
if CheckGitVersionAtLeast("2.1.2") != nil {
|
||||||
|
|
|
@ -98,8 +98,7 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
|
||||||
|
|
||||||
cmd.AddOptionValues("--context", fmt.Sprint(opts.ContextLineNumber))
|
cmd.AddOptionValues("--context", fmt.Sprint(opts.ContextLineNumber))
|
||||||
|
|
||||||
// --max-count requires at least git 2.38
|
if SupportGrepMaxCount {
|
||||||
if CheckGitVersionAtLeast("2.38.0") == nil {
|
|
||||||
cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile))
|
cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile))
|
||||||
} else {
|
} else {
|
||||||
log.Warn("git-grep: --max-count requires at least git 2.38")
|
log.Warn("git-grep: --max-count requires at least git 2.38")
|
||||||
|
|
|
@ -59,48 +59,55 @@ func TestGrepSearch(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, res)
|
}, res)
|
||||||
|
|
||||||
res, err = GrepSearch(t.Context(), repo, "world", GrepOptions{MatchesPerFile: 1})
|
t.Run("Max count", func(t *testing.T) {
|
||||||
require.NoError(t, err)
|
if !SupportGrepMaxCount {
|
||||||
assert.Equal(t, []*GrepResult{
|
t.Skip("Skipping, git grep --max-count is not supported")
|
||||||
{
|
return
|
||||||
Filename: "i-am-a-python.p",
|
}
|
||||||
LineNumbers: []int{1},
|
|
||||||
LineCodes: []string{"## This is a simple file to do a hello world"},
|
|
||||||
HighlightedRanges: [][3]int{{0, 39, 44}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Filename: "java-hello/main.java",
|
|
||||||
LineNumbers: []int{1},
|
|
||||||
LineCodes: []string{"public class HelloWorld"},
|
|
||||||
HighlightedRanges: [][3]int{{0, 18, 23}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Filename: "main.vendor.java",
|
|
||||||
LineNumbers: []int{1},
|
|
||||||
LineCodes: []string{"public class HelloWorld"},
|
|
||||||
HighlightedRanges: [][3]int{{0, 18, 23}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Filename: "python-hello/hello.py",
|
|
||||||
LineNumbers: []int{1},
|
|
||||||
LineCodes: []string{"## This is a simple file to do a hello world"},
|
|
||||||
HighlightedRanges: [][3]int{{0, 39, 44}},
|
|
||||||
},
|
|
||||||
}, res)
|
|
||||||
|
|
||||||
res, err = GrepSearch(t.Context(), repo, "world", GrepOptions{
|
res, err = GrepSearch(t.Context(), repo, "world", GrepOptions{MatchesPerFile: 1})
|
||||||
MatchesPerFile: 1,
|
require.NoError(t, err)
|
||||||
Filename: "java-hello/",
|
assert.Equal(t, []*GrepResult{
|
||||||
|
{
|
||||||
|
Filename: "i-am-a-python.p",
|
||||||
|
LineNumbers: []int{1},
|
||||||
|
LineCodes: []string{"## This is a simple file to do a hello world"},
|
||||||
|
HighlightedRanges: [][3]int{{0, 39, 44}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Filename: "java-hello/main.java",
|
||||||
|
LineNumbers: []int{1},
|
||||||
|
LineCodes: []string{"public class HelloWorld"},
|
||||||
|
HighlightedRanges: [][3]int{{0, 18, 23}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Filename: "main.vendor.java",
|
||||||
|
LineNumbers: []int{1},
|
||||||
|
LineCodes: []string{"public class HelloWorld"},
|
||||||
|
HighlightedRanges: [][3]int{{0, 18, 23}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Filename: "python-hello/hello.py",
|
||||||
|
LineNumbers: []int{1},
|
||||||
|
LineCodes: []string{"## This is a simple file to do a hello world"},
|
||||||
|
HighlightedRanges: [][3]int{{0, 39, 44}},
|
||||||
|
},
|
||||||
|
}, res)
|
||||||
|
|
||||||
|
res, err = GrepSearch(t.Context(), repo, "world", GrepOptions{
|
||||||
|
MatchesPerFile: 1,
|
||||||
|
Filename: "java-hello/",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, []*GrepResult{
|
||||||
|
{
|
||||||
|
Filename: "java-hello/main.java",
|
||||||
|
LineNumbers: []int{1},
|
||||||
|
LineCodes: []string{"public class HelloWorld"},
|
||||||
|
HighlightedRanges: [][3]int{{0, 18, 23}},
|
||||||
|
},
|
||||||
|
}, res)
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, []*GrepResult{
|
|
||||||
{
|
|
||||||
Filename: "java-hello/main.java",
|
|
||||||
LineNumbers: []int{1},
|
|
||||||
LineCodes: []string{"public class HelloWorld"},
|
|
||||||
HighlightedRanges: [][3]int{{0, 18, 23}},
|
|
||||||
},
|
|
||||||
}, res)
|
|
||||||
|
|
||||||
res, err = GrepSearch(t.Context(), repo, "no-such-content", GrepOptions{})
|
res, err = GrepSearch(t.Context(), repo, "no-such-content", GrepOptions{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -251,10 +251,14 @@ func TestGitAttributeCheckerError(t *testing.T) {
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
ac, err := gitRepo.GitAttributeChecker("8fee858da5796dfb37704761701bb8e800ad9ef3", "linguist-language")
|
ac, err := gitRepo.GitAttributeChecker("8fee858da5796dfb37704761701bb8e800ad9ef3", "linguist-language")
|
||||||
require.NoError(t, err)
|
if SupportCheckAttrOnBare {
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = ac.CheckPath("i-am-a-python.p")
|
_, err = ac.CheckPath("i-am-a-python.p")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
} else {
|
||||||
|
require.Error(t, err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Cancelled/DuringRun", func(t *testing.T) {
|
t.Run("Cancelled/DuringRun", func(t *testing.T) {
|
||||||
|
|
|
@ -32,10 +32,15 @@ func TestPatchStatus(t *testing.T) {
|
||||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||||
session := loginUser(t, user2.Name)
|
session := loginUser(t, user2.Name)
|
||||||
|
|
||||||
|
var objectFormat optional.Option[string]
|
||||||
|
if git.SupportHashSha256 {
|
||||||
|
objectFormat = optional.Some("sha256")
|
||||||
|
}
|
||||||
|
|
||||||
repo, _, f := tests.CreateDeclarativeRepoWithOptions(t, user2, tests.DeclarativeRepoOptions{
|
repo, _, f := tests.CreateDeclarativeRepoWithOptions(t, user2, tests.DeclarativeRepoOptions{
|
||||||
AutoInit: optional.Some(true),
|
AutoInit: optional.Some(true),
|
||||||
EnabledUnits: optional.Some([]unit_model.Type{unit_model.TypeCode}),
|
EnabledUnits: optional.Some([]unit_model.Type{unit_model.TypeCode}),
|
||||||
ObjectFormat: optional.Some("sha256"),
|
ObjectFormat: objectFormat,
|
||||||
Files: optional.Some([]*files_service.ChangeRepoFile{
|
Files: optional.Some([]*files_service.ChangeRepoFile{
|
||||||
{
|
{
|
||||||
Operation: "create",
|
Operation: "create",
|
||||||
|
|
|
@ -25,6 +25,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepoSSHSignedTags(t *testing.T) {
|
func TestRepoSSHSignedTags(t *testing.T) {
|
||||||
|
if git.CheckGitVersionAtLeast("2.34") != nil {
|
||||||
|
t.Skip("Skipping, does not support SSH signing")
|
||||||
|
return
|
||||||
|
}
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
// Preparations
|
// Preparations
|
||||||
|
|
|
@ -42,6 +42,10 @@ func TestInstanceSigning(t *testing.T) {
|
||||||
defer test.MockProtect(&setting.Repository.Signing.CRUDActions)()
|
defer test.MockProtect(&setting.Repository.Signing.CRUDActions)()
|
||||||
|
|
||||||
t.Run("SSH", func(t *testing.T) {
|
t.Run("SSH", func(t *testing.T) {
|
||||||
|
if git.CheckGitVersionAtLeast("2.34") != nil {
|
||||||
|
t.Skip("Skipping, does not support git SSH signing")
|
||||||
|
return
|
||||||
|
}
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
pubKeyContent, err := os.ReadFile("tests/integration/ssh-signing-key.pub")
|
pubKeyContent, err := os.ReadFile("tests/integration/ssh-signing-key.pub")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue