From f220f4231af35150eed910cbdc44fac8f85cdfb3 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Thu, 11 Jan 2024 04:29:01 +0800 Subject: [PATCH] Add -F to commit search to treat keywords as strings (#28744) (#28748) Backport #28744 by @me-heer Fixes #28269 The [default behavior](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp) of --grep in git log is to interpret the keyword as a regular expression. This causes the search to fail in the cases where the search keyword contains a `[`, since `[` is a special character used in grep. If we want our keywords to be interpreted as 'strings', we should use [-F flag](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp). Co-authored-by: Mihir Joshi --- modules/git/repo_commit.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index 6fc3063629..f69ecb88bc 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -148,6 +148,9 @@ func (repo *Repository) searchCommits(id SHA1, opts SearchCommitsOptions) ([]*Co cmd.AddArguments("--all") } + // interpret search string keywords as string instead of regex + cmd.AddArguments("-F") + // add remaining keywords from search string // note this is done only for command created above if len(opts.Keywords) > 0 {