aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/search_test.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-05-03 17:13:48 +0800
committerGitHub <noreply@github.com>2024-05-03 09:13:48 +0000
commit0f3e717a1abb2b2161b87dac557beb6475224a2e (patch)
tree239585a4006625fe5acae2bb8400c6a20d9d0aea /routers/web/repo/search_test.go
parent9f0ef3621a3b63ccbe93f302a446b67dc54ad725 (diff)
downloadgitea-0f3e717a1abb2b2161b87dac557beb6475224a2e.tar.gz
gitea-0f3e717a1abb2b2161b87dac557beb6475224a2e.zip
Improve grep search (#30843)
Reduce the context line number to 1, make "git grep" search respect the include/exclude patter, and fix #30785
Diffstat (limited to 'routers/web/repo/search_test.go')
-rw-r--r--routers/web/repo/search_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/routers/web/repo/search_test.go b/routers/web/repo/search_test.go
new file mode 100644
index 0000000000..33a1610384
--- /dev/null
+++ b/routers/web/repo/search_test.go
@@ -0,0 +1,19 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package repo
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/test"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestIndexSettingToGitGrepPathspecList(t *testing.T) {
+ defer test.MockVariableValue(&setting.Indexer.IncludePatterns, setting.IndexerGlobFromString("a"))()
+ defer test.MockVariableValue(&setting.Indexer.ExcludePatterns, setting.IndexerGlobFromString("b"))()
+ assert.Equal(t, []string{":(glob)a", ":(glob,exclude)b"}, indexSettingToGitGrepPathspecList())
+}