Create BranchesFinder to lib/gitlab/git/finders

Create a new Gitlab::Git::Finders::BranchesFinder class that uses the ListRefs Gitaly RPC (via RefsFinder) to provide server-side search and pagination for branches.

Features

  • Server-side search: Delegates to RefsFinder which uses ListRefs Gitaly RPC
  • Search operators: Supports ^ (starts with), $ (ends with), * (wildcard)
  • Sorting: name_asc, name_desc, updated_asc, updated_desc
  • Pagination: per_page and page_token for cursor-based pagination
  • Optional commit hydration: include_commits: true fetches commit data via Commit.batch_by_oid

API

# Basic usage (no commits, fastest)
finder = Gitlab::Git::Finders::BranchesFinder.new(repository, { search: 'feature' })
branches = finder.execute
# With commit data (for API responses needing commit info)
finder = Gitlab::Git::Finders::BranchesFinder.new(repository, params, include_commits: true)
branches = finder.execute
# Pagination
finder.next_cursor  # => last branch name for cursor
finder.total        # => total branch count

Search pattern translation

Input Glob Pattern Matches
fix refs/heads/**/*fix* Contains "fix"
^feature refs/heads/feature* Starts with "feature"
release$ refs/heads/**/*release Ends with "release"
^v1*rc$ refs/heads/v1*rc Starts with "v1", ends with "rc"

Behavioral differences from legacy BranchesFinder

  1. Case-sensitive search: Git globs are case-sensitive (legacy used case-insensitive Ruby matching)
  2. No regex support: Only glob patterns supported; use legacy finder for full regex (regex param)
Edited by Vasilii Iakliushin