diff --git a/modules/git/grep.go b/modules/git/grep.go index 5572bd994f..41466bf537 100644 --- a/modules/git/grep.go +++ b/modules/git/grep.go @@ -17,6 +17,7 @@ import ( "strings" "time" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" ) @@ -30,7 +31,7 @@ type GrepResult struct { type GrepOptions struct { RefName string MaxResultLimit int - MatchesPerFile int + MatchesPerFile int // >= git 2.38 ContextLineNumber int IsFuzzy bool PathSpec []setting.Glob @@ -77,7 +78,14 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO "-I", "--null", "--break", "--heading", "--column", "--fixed-strings", "--line-number", "--ignore-case", "--full-name") cmd.AddOptionValues("--context", fmt.Sprint(opts.ContextLineNumber)) - cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile)) + + // --max-count requires at least git 2.38 + if CheckGitVersionAtLeast("2.38.0") == nil { + cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile)) + } else { + log.Warn("git-grep: --max-count requires at least git 2.38") + } + words := []string{search} if opts.IsFuzzy { words = strings.Fields(search)