Skip to content

search: search the code of repositories - #8549

Merged
unknwon merged 11 commits into
mainfrom
code-search-react-flamego
Nov 17, 2026
Merged

unknwon merged 11 commits into
mainfrom
code-search-react-flamego

Conversation

@unknwon

@unknwon unknwon commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

Adds built-in code search with git grep, so there is no index to build, store or keep up to date.

  • Search in a repository at any branch, tag or commit, from the search button next to "Go to file" on the repository home page and in the file browser toolbar (/{owner}/{repo}/search/{ref}?q=).
  • Search all repositories the viewer can read, at their default branches, from a search box in the navbar (/search?q=) and a "Search code" button on organization pages.
  • Qualifiers narrow down the search like on GitHub: org: and user: for the repositories of an owner, repo:owner/name for one repository, and path: for files whose path contains a text or matches a * pattern. Repository search takes path:.
  • The search box shows qualifiers as removable chips, and suggests qualifiers, and owners and repositories for their values, while typing. Suggestions come from the explore endpoints, so they only list what the viewer can see.
  • Search options are icon toggles at the end of the search box, each with a tooltip, which look pressed when on. Both search pages have Match case (?matchCase=true). Letter case is ignored by default.
  • Exhaustive search of a repository lists every matching line of a file rather than the first 10, from the search options (?exhaustive=true). When a search is cut short, it also offers to run an exhaustive one.
  • Results are grouped by file, with one line of context around each match, colored like the file view with the matches marked. Line numbers link to the line in the file view.

Matching is literal. Binary files are skipped.

With the glass look on, results, the empty state and the timeout warning sit on glass panels, the search boxes take the field color, and the suggestions blur what is behind them like other popovers.

Limits

A search lists at most 200 matching lines and 10 per file, stops after 10 seconds, and at most one search per CPU runs at a time. An exhaustive search of a repository lists at most 5,000 matching lines with no limit per file, and stops after a minute. A search of all repositories looks at up to 1,000 of them, most recently updated first, and shows what it found so far when it runs out of time.

Behavior changes

  • The name search is reserved for users and organizations.

Screenshots

Search all repositories, scoped to an organization and a path

Light Dark
Code search with org:acme and path:cmd/ chips and highlighted results The same search in dark mode

Suggestions for qualifiers and their values

Qualifiers Repositories for repo:
Empty search box listing the org:, user:, repo: and path: qualifiers Search box suggesting acme repositories for repo:ac

Search in a repository

Repository code search with a path:internal/git chip and highlighted Go results

Search options

Match case (Aa) and Exhaustive search sit at the end of the search box, and look pressed when on. Turning one runs the search of what is in the box again. newRepo in the gogs source finds 11 files with NewRepo and newRepo marked by default, and 8 files with only newRepo with Match case.

Repository search for newRepo with both toggles off at the end of the search box
The Match case tooltip
Match case on, only newRepo marked
Both toggles on, with the focus ring on Exhaustive search
Search of all repositories, which has Match case
Both toggles on in dark
Both toggles on in dark glass
Both toggles on in light glass
Repository search at 375px with both toggles in the box Repository search at 375px with a path chip, the toggles at the end of the second row Search of all repositories at 375px

When a search is cut short, it offers an exhaustive one. In the gogs source, errors.Wrap lists 200 lines in 28 files, and 720 lines in 85 files when exhaustive.

The truncated hint followed by a Run an exhaustive search link

Search buttons on the repository home page, in the file browser and on organization pages

Repository home (glass) File browser
Search button between Go to file and Add file on the repository home page Search button next to Add file in the file browser toolbar

Search code button on an organization page

Glass look

Results, light Repository search, dark
Code search results on glass panels in light mode Repository code search on glass panels in dark mode

Empty search page with the qualifier suggestions over the help panel in the glass look

Timeout warning, light Timeout warning, dark
Timeout warning on a frosted panel in light mode Timeout warning on a frosted panel in dark mode
Navbar suggestions, dark Qualifier suggestions, dark
Navbar search suggesting repositories in the dark glass look Qualifier suggestions over the help panel in the dark glass look

Organization page with the Search code button in the dark glass look

Code search at 375px in the glass look Repository code search at 375px in the dark glass look Timeout warning at 375px in the dark glass look

At 375px

Code search at 375px with chips wrapping inside the box Repository code search at 375px in dark mode

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code and provided the test plan below.
  • I have added an entry to CHANGELOG.

Test plan

  1. go test ./cmd/gogs/internal/web/ ./internal/git/ ./internal/database/ passes, including the git grep tests with and without matching case, and the query parser. golangci-lint run ./... reports no issues. In web/, tsc -b, pnpm run lint, Prettier and pnpm run build pass.
  2. The integration suite passes against PostgreSQL with -shuffle=on, and every route has a test. TestCodeSearch searches a public and a private repository of one user as the owner, another user and an anonymous viewer: results with one line of context, case-insensitive matching, path: with text and with *, a search at a commit before the files existed, an unknown ref (404), and an exhaustive search: a file with 15 matches lists 10 by default and with exhaustive=false, and all 15 with their context lines with exhaustive=true, path: still applies, a file with 5,001 matches lists 5,000 and is marked truncated, and a private repository stays hidden from other viewers, Match case in a repository, with an exhaustive search and across all repositories, where lines around a match that contain the keyword in another case stay context, and user: and repo: across all repositories. Neither search nor naming the private repository with repo: returns its code to the other viewers. The test fails without the read check on repositories, when path: is ignored, and without context lines. The exhaustive tests fail when it keeps the limit per file, keeps the limit of 200 lines, has no limit, drops context lines, ignores path:, or turns on for any value of exhaustive. The Match case tests fail when either search ignores matchCase, when Git always ignores case, and when matches are marked ignoring case.
  3. Built with -tags prod and checked in the browser: the search of all repositories with org: and path: chips, qualifier and repository suggestions, a repository search with a path: chip, the search buttons on the repository home page, the file browser and an organization page, the empty search page, and an exhaustive search: the toggle and the "Run an exhaustive search" link both set ?exhaustive=true, and path:internal/database errors.Wrap in the gogs source goes from 115 to 169 lines, and Match case on both search pages, alone and with an exhaustive search. A toggle searches for what is typed in the box even before it is submitted, works with Space from the keyboard, and does not open the suggestions. Checked in light, dark, light glass and dark glass at 1280px and at 375px, including the navbar search box and its suggestions, and the timeout warning (by marking a response as timed out in the browser). Nothing scrolls sideways at 375px, and long code lines scroll inside their result.

unknwon added a commit that referenced this pull request Nov 14, 2026
unknwon added a commit that referenced this pull request Nov 14, 2026
@unknwon unknwon mentioned this pull request Nov 14, 2026
4 tasks done
@unknwon
unknwon added this pull request to stack #8457 November 14, 2026 02:49
@unknwon
unknwon force-pushed the code-search-react-flamego branch from e13491f to 3ae738c Compare November 14, 2026 05:43
@unknwon
unknwon force-pushed the code-search-react-flamego branch 2 times, most recently from 5ae8aed to cc9b91f Compare November 14, 2026 07:11
@unknwon
unknwon force-pushed the code-search-react-flamego branch 5 times, most recently from 6edb0a8 to 8e58e07 Compare November 14, 2026 18:49
@unknwon
unknwon force-pushed the code-search-react-flamego branch 3 times, most recently from b55a615 to b850779 Compare November 14, 2026 19:40
@unknwon
unknwon force-pushed the code-search-react-flamego branch 8 times, most recently from 6b108a6 to 4beff3a Compare November 14, 2026 23:31
@unknwon
unknwon force-pushed the code-search-react-flamego branch from f4542d2 to 2ca1562 Compare November 16, 2026 00:46
@unknwon
unknwon force-pushed the code-search-react-flamego branch from 2ca1562 to aa4c3ba Compare November 16, 2026 01:45
@unknwon
unknwon force-pushed the code-search-react-flamego branch from aa4c3ba to a87fb44 Compare November 16, 2026 02:24
@unknwon
unknwon force-pushed the code-search-react-flamego branch from a87fb44 to 670c6a3 Compare November 16, 2026 03:07
Base automatically changed from bundled-libs-flamego to main November 17, 2026 16:09
@unknwon
unknwon marked this pull request as ready for review November 17, 2026 16:10
@mintlify

mintlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
Gogs 🟢 Ready View Preview Nov 17, 2026, 5:07 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

Search the files of a branch, a tag or a commit for lines that contain a
keyword, ignoring case, with `git grep` on the tree. Nothing is indexed,
so there is no extra disk use and nothing to keep up to date. A search
lists at most 200 lines, 10 per file, stops after 10 seconds, and at
most one search per CPU runs at a time.

The search page is reached from the "Search code" button of the file
browser and lists the matching lines by file, linked to the lines in the
file view.
Search the default branches of all repositories the viewer can read from
a new search page at /search, reached from a search box in the navbar
and from the pages of organizations. Qualifiers narrow down the search
like on GitHub: org: and user: for the repositories of an owner, repo:
for one repository, and path: for files whose path contains a text or
matches a pattern. Per-repository search takes path: too.

The search box shows qualifiers as chips and suggests qualifiers, and
owners and repositories for their values, while typing. Results show the
lines around each match and are highlighted like the file view.

The name "search" is now reserved for users and organizations.
An exhaustive search lists every matching line of a file, up to 5,000
lines, and gets a minute rather than 10 seconds.
Letter case is still ignored by default. With matchCase=true, both the
search of a repository and of all repositories match it, and so does
the marking of matches.
Match case and Exhaustive search move from checkboxes beside the search
box into a menu behind one button after it, which shows how many of
them are on.
Match case and Exhaustive search move from a menu after the search
button into icon toggles at the end of the search box, with a tooltip,
which look pressed when on. Turning one runs the search of what is in
the box.
Windows does not allow colons in paths, so the test commits a file with
only a space in its name there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant