From fb1c17426864aa633a6ebd065d21e9c6a954f584 Mon Sep 17 00:00:00 2001 From: Mihir Date: Tue, 9 Jan 2024 20:40:25 +0530 Subject: [PATCH 1/2] Add -F to commit search to treat keywords as strings --- 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 ccb3eb4adef0..a69229055ffe 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -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 { From 32acd66020a2a922a08d89b4d905f19a8dcd6f22 Mon Sep 17 00:00:00 2001 From: Mihir Joshi Date: Wed, 10 Jan 2024 22:33:32 +0530 Subject: [PATCH 2/2] Add commits search test for keywords containing square brackets Change fixed strings commit search flag from -F to --fixed-strings for readability --- modules/git/repo_commit.go | 2 +- tests/integration/repo_commits_search_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index a69229055ffe..9c9ee7768feb 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -143,7 +143,7 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([ } // interpret search string keywords as string instead of regex - cmd.AddArguments("-F") + cmd.AddArguments("--fixed-strings") // add remaining keywords from search string // note this is done only for command created above diff --git a/tests/integration/repo_commits_search_test.go b/tests/integration/repo_commits_search_test.go index 1c27b6db9d60..74ac25c0f56e 100644 --- a/tests/integration/repo_commits_search_test.go +++ b/tests/integration/repo_commits_search_test.go @@ -32,6 +32,7 @@ func TestRepoCommitsSearch(t *testing.T) { testRepoCommitsSearch(t, "38a9cb", "") testRepoCommitsSearch(t, "6e8e", "6e8eabd9a7") testRepoCommitsSearch(t, "58e97", "58e97d1a24") + testRepoCommitsSearch(t, "[build]", "") testRepoCommitsSearch(t, "author:alice", "6e8eabd9a7") testRepoCommitsSearch(t, "author:alice 6e8ea", "6e8eabd9a7") testRepoCommitsSearch(t, "committer:Tom", "58e97d1a24")