go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.41k stars 5.43k forks source link

Code search using git grep doesn't respect branch name #31388

Open cosmoswafer opened 3 months ago

cosmoswafer commented 3 months ago

Description

When using the code search on another branch, Gitea doesn’t respect the branch name and only searches the default branch. I guess the search URL loses the branch name from the context because there is no related information passed together with the request.

Gitea Version

1.22.0

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

git version 2.44.2

Operating System

Gentoo

How are you running Gitea?

Running the executable binaries from github release. And I think it doesn't matter to this issue.

Database

MySQL/MariaDB

yardenshoham commented 3 months ago

Relevant line: https://github.com/go-gitea/gitea/blob/f446e3b4ab2d3f787a17d1cfe09ee8f5f7b10089/routers/web/repo/search.go#L81

wxiaoguang commented 3 months ago

The root problem is that there is no "branch name" support on the web UI (and I guess there is no such support for other search engine/indexers).

So it could be an enhancement to introduce "current branch" support.

techknowlogick commented 3 months ago

The root problem is that there is no "branch name" support on the web UI (and I guess there is no such support for other search engine/indexers).

IIRC the other code indexers will only index on the default branch, and GitHub also has the same behaviour, as if we allow searching on other/all branches our index will explode in size

cosmoswafer commented 3 months ago

I see. I’ve read the source code and found that the branch name is in the context. I thought there were some bugs because it doesn’t recognize the branch name. By the way, git grep should support searching by branch name, and the branch name is, in fact, part of the URL. Thus, I think technically we can pass the branch name from the URL to the code search box as another query parameter.

lunny commented 1 month ago

If we implemented search via git grep with branch name but other indexes will not support it. It's inconsistent between different indexes. Maybe it will result in confusing?