Skip to content

Commit 14ce633

Browse files
feat: add rev:* syntax to explicitly search all branches (#281)
1 parent 7e54931 commit 14ce633

File tree

4 files changed

+117
-8
lines changed

4 files changed

+117
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- Added special `*` value for `rev:` to allow searching across all branches. [#281](https://github.com/sourcebot-dev/sourcebot/pull/281)
12+
1013
## [3.1.2] - 2025-04-30
1114

1215
### Added

docs/docs.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,25 @@
2929
"group": "Connecting your code",
3030
"pages": [
3131
"docs/connections/overview",
32-
"docs/connections/github",
33-
"docs/connections/gitlab",
34-
"docs/connections/bitbucket-cloud",
35-
"docs/connections/bitbucket-data-center",
36-
"docs/connections/gitea",
37-
"docs/connections/gerrit",
38-
"docs/connections/request-new"
32+
{
33+
"group": "Supported platforms",
34+
"pages": [
35+
"docs/connections/github",
36+
"docs/connections/gitlab",
37+
"docs/connections/bitbucket-cloud",
38+
"docs/connections/bitbucket-data-center",
39+
"docs/connections/gitea",
40+
"docs/connections/gerrit",
41+
"docs/connections/request-new"
42+
]
43+
}
3944
]
4045
},
4146
{
4247
"group": "More",
4348
"pages": [
4449
"docs/more/syntax-reference",
50+
"docs/more/multi-branch-indexing",
4551
"docs/more/roles-and-permissions"
4652
]
4753
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: Searching multiple branches and tags
3+
sidebarTitle: Searching multiple branches
4+
---
5+
6+
By default, only the default branch of a repository is indexed and can be searched. Sourcebot can be configured to index additional branches (or tags) enabling multi-branch search. This is useful for scenarios such as:
7+
8+
- Searching across different releases
9+
- Searching through feature branches during development
10+
- Tracking changes across multiple maintenance branches simultaneously
11+
12+
## Configuration
13+
14+
<Warning>
15+
Multi-branch indexing is currently limited to 64 branches and tags. If this limitation impacts your use-case, please [open a discussion](https://github.com/sourcebot-dev/sourcebot/discussions/categories/support).
16+
</Warning>
17+
18+
Multi-branch indexing is configured on in the [connection](/docs/connections/overview) using the `revisions.branches` and `revisions.tags` arrays. Glob patterns are supported. For example:
19+
20+
```json
21+
{
22+
"$schema": "https://raw.githubusercontent.com/sourcebot-dev/sourcebot/main/schemas/v3/index.json",
23+
"connections": {
24+
"my-connection": {
25+
"type": "github",
26+
// For each of the repositories defined in this connection...
27+
"repos": [
28+
"org/repo1",
29+
"org/repo2"
30+
],
31+
// ... index the default branch, as well as...
32+
"revisions": {
33+
// These branches (if they exist):
34+
"branches": [
35+
// Exact matches
36+
"dev",
37+
"staging",
38+
39+
// Glob patterns
40+
"feature/*" // Matches: feature/auth, feature/ui, etc.
41+
],
42+
43+
// These tags (if they exist):
44+
"tags": [
45+
// Exact matches
46+
"v4.0.0-dev",
47+
48+
// Glob patterns
49+
"v3.*.*", // Matches: v3.0.0, v3.0.1, etc.
50+
"rc-*" // Matches: rc-1, rc-2, etc.
51+
]
52+
}
53+
}
54+
}
55+
}
56+
```
57+
58+
For each repo defined in the connection, any branches or tags matching the patterns in `branches` and `tags` array will be indexed.
59+
60+
## Search syntax
61+
62+
To search branches other than the default, the `rev:` prefix can be used followed by the branch (or tag) name:
63+
64+
| Example | Explanation |
65+
| :--- | :--- |
66+
| `rev:feature/foo repo:A useEffect` | Search for `/useEffect/` on branch `feature/foo` in repo `A` |
67+
| `rev:feature/foo useEffect ` | Search for `/useEffect/` on branch `feature/foo` across all repos |
68+
| `rev:feature/ useEffect` | Search for `/useEffect/` on branches that contain `feature/` across all repos |
69+
| `rev:feature/a rev:feature/b foo` | Search for `/foo/` on branches `feature/a` and `feature/b` |
70+
| `rev:feature/ -rev:feature/a foo` | Search for `/foo/` on branches that contain `feature/` _except_ for `feature/a` across all repos |
71+
72+
To search across **all** branches, `rev:*`:
73+
| Example | Explanation |
74+
| :--- | :--- |
75+
| `rev:* repo:A "error message"` | Search for `/error message/` across **all** branches in repo `A` |
76+
| `rev:* "error message"` | Search for `/error message/` across **all** branches and **all** repos |
77+
78+
Additional info:
79+
- `refs/heads/` or `refs/tags/` can be included to fully qualify a branch or a tag, respectively. E.g., `rev:refs/heads/foo` will search the branch `foo`, while `rev:refs/tags/foo` will search the tag `foo`.
80+
- `rev:` does **not** support regular expressions or glob patterns. It uses a simple `contains` call between the branch name and the pattern. See [here](https://github.com/sourcebot-dev/zoekt/blob/7d1896215eea6f97af66c9549c9ec70436356b51/matchtree.go#L1067).
81+
82+
83+
## Platform support
84+
85+
| Platform | Multi-branch indexing support |
86+
|:----------|------------------------------|
87+
| GitHub ||
88+
| GitLab ||
89+
| Bitbucket Cloud ||
90+
| Bitbucket Data Center ||
91+
| Gitea ||
92+
| Gerrit ||
93+

packages/web/src/lib/server/searchService.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ const transformZoektQuery = async (query: string, orgId: number): Promise<string
4141
// Handle mapping `rev:` and `revision:` to `branch:`
4242
if (part.match(/^-?(rev|revision):.+$/)) {
4343
const isNegated = part.startsWith("-");
44-
const revisionName = part.slice(part.indexOf(":") + 1);
44+
let revisionName = part.slice(part.indexOf(":") + 1);
45+
46+
// Special case: `*` -> search all revisions.
47+
// In zoekt, providing a blank string will match all branches.
48+
// @see: https://github.com/sourcebot-dev/zoekt/blob/main/eval.go#L560-L562
49+
if (revisionName === "*") {
50+
revisionName = "";
51+
}
4552
newQueryParts.push(`${isNegated ? "-" : ""}${zoektPrefixes.branch}${revisionName}`);
4653
}
4754

0 commit comments

Comments
 (0)