Add follow parameter to List Repository Commits API

What does this MR do and why?

Contributes to #382081 (closed)

Problem

When using the "List repository commits" API with a path filter, users receive unrelated commits in the history. This happens because Git's --follow flag (rename detection) is automatically enabled, which shows commits from files with similar content even if they were never actually renamed.

Solution

Add an optional follow parameter to the API endpoint that allows users to explicitly control rename tracking behavior. When not provided, the existing feature flag-based behavior is preserved. When explicitly set to false, users can disable rename detection to see only commits where the file existed at its current path.

Changelog: added

References

Screenshots or screen recordings

N/A - API-only change

How to set up and validate locally

  1. Start GDK with the GitLab rails server running
  2. Create a project with a file that has similar content to another file (or use an existing project)
  3. Test the API endpoint with the new follow parameter:
# With follow=false (disables rename tracking)
curl --header "PRIVATE-TOKEN: <token>" \
  "http://localhost:3000/api/v4/projects/<id>/repository/commits?path=<file>&follow=false"

# With follow=true (enables rename tracking - current default behavior)
curl --header "PRIVATE-TOKEN: <token>" \
  "http://localhost:3000/api/v4/projects/<id>/repository/commits?path=<file>&follow=true"

# Without follow parameter (uses feature flag-based default)
curl --header "PRIVATE-TOKEN: <token>" \
  "http://localhost:3000/api/v4/projects/<id>/repository/commits?path=<file>"
  1. Run the tests:
bundle exec rspec spec/models/repository_spec.rb -e "follow"
bundle exec rspec spec/requests/api/commits_spec.rb -e "follow optional parameter"

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vasilii Iakliushin

Merge request reports

Loading