mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-05 18:05:19 +02: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
|
||||
SupportCheckAttrOnBare bool // >= 2.40
|
||||
SupportGitMergeTree bool // >= 2.38
|
||||
SupportGrepMaxCount bool // >= 2.38
|
||||
|
||||
HasSSHExecutable bool
|
||||
|
||||
|
@ -191,6 +192,7 @@ func InitFull(ctx context.Context) (err error) {
|
|||
|
||||
InvertedGitFlushEnv = CheckGitVersionEqual("2.43.1") == nil
|
||||
SupportGitMergeTree = CheckGitVersionAtLeast("2.38") == nil
|
||||
SupportGrepMaxCount = CheckGitVersionAtLeast("2.38") == nil
|
||||
|
||||
if setting.LFS.StartServer {
|
||||
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))
|
||||
|
||||
// --max-count requires at least git 2.38
|
||||
if CheckGitVersionAtLeast("2.38.0") == nil {
|
||||
if SupportGrepMaxCount {
|
||||
cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile))
|
||||
} else {
|
||||
log.Warn("git-grep: --max-count requires at least git 2.38")
|
||||
|
|
|
@ -59,48 +59,55 @@ func TestGrepSearch(t *testing.T) {
|
|||
},
|
||||
}, res)
|
||||
|
||||
res, err = GrepSearch(t.Context(), repo, "world", GrepOptions{MatchesPerFile: 1})
|
||||
require.NoError(t, err)
|
||||
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)
|
||||
t.Run("Max count", func(t *testing.T) {
|
||||
if !SupportGrepMaxCount {
|
||||
t.Skip("Skipping, git grep --max-count is not supported")
|
||||
return
|
||||
}
|
||||
|
||||
res, err = GrepSearch(t.Context(), repo, "world", GrepOptions{
|
||||
MatchesPerFile: 1,
|
||||
Filename: "java-hello/",
|
||||
res, err = GrepSearch(t.Context(), repo, "world", GrepOptions{MatchesPerFile: 1})
|
||||
require.NoError(t, err)
|
||||
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{})
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -251,10 +251,14 @@ func TestGitAttributeCheckerError(t *testing.T) {
|
|||
cancel()
|
||||
|
||||
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")
|
||||
require.Error(t, err)
|
||||
_, err = ac.CheckPath("i-am-a-python.p")
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Cancelled/DuringRun", func(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue