Repository branches API returns incorrect X-Total pagination header

Summary

When searching for branches using the repository branches REST API with a search query paramter, the X-Total header is returning the total number of branches instead of the total number of matching branches.

Steps to reproduce

  • Make a GET request to the gitlab project: GET https://gitlab.com/api/v4/projects/278964/repository/branches?search=v12

What is the current bug behavior?

Two branches are (correctly) returned in the response, but the X-Total header is 6556.

The X-Total header is returning the total number of branches in the repository without regard to the search parameter.

What is the expected correct behavior?

Two branches are returned in the response, and the X-Total header is 2.

The X-Total header should return the total number of branches that match the search parameter.

Relevant logs and/or screenshots

This behavior can be seen through the UI on the New Release page:

image

The branches section is showing 1000+ matches, despite only two branches being shown in the UI.

In contrast, the Tags section - which uses the equivalent Tags REST API - returns the correct X-Total header (139, in the example above).

Output of checks

This bug happens on GitLab.com.