fix(api): return a single object for an exact git ref - #38735
Open
davidpavlovschi wants to merge 1 commit into
Open
fix(api): return a single object for an exact git ref#38735davidpavlovschi wants to merge 1 commit into
davidpavlovschi wants to merge 1 commit into
Conversation
The ref filter from the route has no "refs/" prefix, so the exact-match
branch in getGitRefsInternal never fired and GET /repos/{owner}/{repo}/git/refs/{ref}
always returned an array.
Fixes go-gitea#38190
Signed-off-by: davidpavlovschi <davidpavlov2048@gmail.com>
wxiaoguang
reviewed
Aug 2, 2026
| if len(apiRefs) == 1 && apiRefs[0].Ref == filter { | ||
| // If single reference is found and it matches filter exactly return it as object. | ||
| // The filter may omit the "refs/" prefix, while the reference name always has it. | ||
| if len(apiRefs) == 1 && (apiRefs[0].Ref == filter || apiRefs[0].Ref == "refs/"+filter) { |
Contributor
There was a problem hiding this comment.
why apiRefs[0].Ref == filter still makes sense?
wxiaoguang
reviewed
Aug 2, 2026
| AddTokenAuth(token) | ||
| resp := MakeRequest(t, req, http.StatusOK) | ||
| var ref api.Reference | ||
| DecodeJSON(t, resp, &ref) |
Contributor
There was a problem hiding this comment.
Take a look at the comment of DecodeJSON
wxiaoguang
reviewed
Aug 2, 2026
| if len(apiRefs) == 1 && apiRefs[0].Ref == filter { | ||
| // If single reference is found and it matches filter exactly return it as object. | ||
| // The filter may omit the "refs/" prefix, while the reference name always has it. | ||
| if len(apiRefs) == 1 && (apiRefs[0].Ref == filter || apiRefs[0].Ref == "refs/"+filter) { |
Contributor
There was a problem hiding this comment.
Another question: what is "exact match"?
For example: for branch "main" and "main1", when you query "main", then len(apiRefs) == 1 or 2? What's the response?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GET /repos/{owner}/{repo}/git/refs/{ref}returned an array even when the ref matched exactly, contradicting the documented behavior. The route passes the filter without therefs/prefix (heads/main) while the reference name is fully qualified (refs/heads/main), so the exact-match branch ingetGitRefsInternalwas dead code.The check now also accepts
"refs/"+filter; prefix filters such asheadskeep returning a list.TestAPIReposGitRefscovers both cases.Fixes #38190
AI was used to assist with this change.