Skip to content

Commit

Permalink
Add -F to commit search to treat keywords as strings (go-gitea#28744)
Browse files Browse the repository at this point in the history
Fixes go-gitea#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).
  • Loading branch information
me-heer authored and silverwind committed Feb 20, 2024
1 parent c7fc499 commit df8cbba
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/git/repo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([
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
for _, v := range opts.Keywords {
Expand Down

0 comments on commit df8cbba

Please sign in to comment.