Skip to content

Commit 3f58b8d

Browse files
author
Earl Warren
committed
Merge pull request '[v9.0/forgejo] fix git-grep for code search when git version is below 2.38' (go-gitea#5759) from earl-warren/forgejo:wip-v9.0-grep into v9.0/forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5759 Reviewed-by: Otto <[email protected]>
2 parents be36f91 + 908bd64 commit 3f58b8d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

modules/git/grep.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"strings"
1818
"time"
1919

20+
"code.gitea.io/gitea/modules/log"
2021
"code.gitea.io/gitea/modules/setting"
2122
)
2223

@@ -30,7 +31,7 @@ type GrepResult struct {
3031
type GrepOptions struct {
3132
RefName string
3233
MaxResultLimit int
33-
MatchesPerFile int
34+
MatchesPerFile int // >= git 2.38
3435
ContextLineNumber int
3536
IsFuzzy bool
3637
PathSpec []setting.Glob
@@ -77,7 +78,14 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
7778
"-I", "--null", "--break", "--heading", "--column",
7879
"--fixed-strings", "--line-number", "--ignore-case", "--full-name")
7980
cmd.AddOptionValues("--context", fmt.Sprint(opts.ContextLineNumber))
80-
cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile))
81+
82+
// --max-count requires at least git 2.38
83+
if CheckGitVersionAtLeast("2.38.0") == nil {
84+
cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile))
85+
} else {
86+
log.Warn("git-grep: --max-count requires at least git 2.38")
87+
}
88+
8189
words := []string{search}
8290
if opts.IsFuzzy {
8391
words = strings.Fields(search)

0 commit comments

Comments
 (0)