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

Open
opened 2025-11-02 10:33:14 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @cosmoswafer on GitHub (Jun 16, 2024).

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

Originally created by @cosmoswafer on GitHub (Jun 16, 2024). ### 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
GiteaMirror added the type/proposal label 2025-11-02 10:33:14 -06:00
Author
Owner

@yardenshoham commented on GitHub (Jun 16, 2024):

Relevant line:
f446e3b4ab/routers/web/repo/search.go (L81)

@yardenshoham commented on GitHub (Jun 16, 2024): Relevant line: https://github.com/go-gitea/gitea/blob/f446e3b4ab2d3f787a17d1cfe09ee8f5f7b10089/routers/web/repo/search.go#L81
Author
Owner

@wxiaoguang commented on GitHub (Jun 16, 2024):

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.

@wxiaoguang commented on GitHub (Jun 16, 2024): 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.
Author
Owner

@techknowlogick commented on GitHub (Jun 17, 2024):

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

@techknowlogick commented on GitHub (Jun 17, 2024): > 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
Author
Owner

@cosmoswafer commented on GitHub (Jun 17, 2024):

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.

@cosmoswafer commented on GitHub (Jun 17, 2024): 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.
Author
Owner

@lunny commented on GitHub (Aug 14, 2024):

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?

@lunny commented on GitHub (Aug 14, 2024): 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?
Author
Owner

@Ratstail91 commented on GitHub (Jul 5, 2025):

Is this error from the docker image (updated earlier today) relevant to this issue?

gitea  | 2025/07/05 17:41:20 routers/web/repo/search.go:65:Search() [E] gitgrep.PerformSearch: git.GrepSearch: unable to run git grep: exit status 128, stderr: fatal: unable to resolve revision: refs/heads/main

I should note that the repo's only branch is master, as it predates the Great Renaming, and the repo's settings point to main instead of master. I don't know if there's a way to correct the default branches en masse, but it's an easy manual fix.

@Ratstail91 commented on GitHub (Jul 5, 2025): Is this error from the docker image (updated earlier today) relevant to this issue? ``` gitea | 2025/07/05 17:41:20 routers/web/repo/search.go:65:Search() [E] gitgrep.PerformSearch: git.GrepSearch: unable to run git grep: exit status 128, stderr: fatal: unable to resolve revision: refs/heads/main ``` I should note that the repo's only branch is `master`, as it predates the Great Renaming, and the repo's settings point to `main` instead of `master`. I don't know if there's a way to correct the default branches en masse, but it's an easy manual fix.
Author
Owner

@ve3 commented on GitHub (Sep 28, 2025):

My problem is when I created new branch from master branch.

New files was added (commit and push) to new branch.

But in Repo > Settings > Administrator Settings, the Code Indexer always showing latest commit from master branch only.

It seems that Gitea did not index another branch and that's why code search not working.
Problem first found (for myself) since 1.22, but tested on 1.24.5 still not working.

@ve3 commented on GitHub (Sep 28, 2025): My problem is when I created new branch from master branch. New files was added (commit and push) to new branch. But in Repo > Settings > Administrator Settings, the **Code Indexer** always showing latest commit from master branch only. It seems that Gitea did not index another branch and that's why code search not working. Problem first found (for myself) since 1.22, but tested on 1.24.5 still not working.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13163