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
- Issue: #382081 (closed)
- Proposal: #382081 (comment 3128094236)
Screenshots or screen recordings
N/A - API-only change
How to set up and validate locally
- Start GDK with the GitLab rails server running
- Create a project with a file that has similar content to another file (or use an existing project)
- Test the API endpoint with the new
followparameter:
# 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>"
- 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.