diff --git a/app/models/repository.rb b/app/models/repository.rb index 9e2dfebc7cdd3f0421935eb49aea661544e6b2b0..61dacd7d454d046893a7536912624bdd6cbc95a2 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -152,7 +152,7 @@ def commits(ref = nil, opts = {}) ref: ref, path: opts[:path], author: opts[:author], - follow: Array(opts[:path]).length == 1 && Feature.disabled?(:remove_file_commit_history_following, type: :ops), + follow: opts[:path].blank? && Array(opts[:path]).length == 1 && Feature.disabled?(:remove_file_commit_history_following, type: :ops), limit: opts[:limit], offset: opts[:offset], skip_merges: !!opts[:skip_merges], diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index 0ac4ad61addd6bd81e77589e8a1cc9353856d957..722157e4f6e441056aab840768a9ff6ea87faaab 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -262,6 +262,29 @@ expect(response).to include_limited_pagination_headers expect(response.headers['X-Page']).to eql('1') end + + # Test for GitLab issue #559254 - Path Parameter Bug Fix + it "correctly filters commits for files modified by single commit" do + # Test with a file from the existing test repository that should have limited commits + # The Gemfile.zip in the test repository should have been modified only once or twice + + get api("/projects/#{project_id}/repository/commits", user), params: { path: 'Gemfile.zip' } + + expect(response).to have_gitlab_http_status(:ok) + + # Get all commits for comparison + get api("/projects/#{project_id}/repository/commits", user) + total_commits = json_response.length + + # Re-test the file path filter + get api("/projects/#{project_id}/repository/commits", user), params: { path: 'Gemfile.zip' } + filtered_commits = json_response.length + + # The filtered result should be significantly less than total commits + # If they're equal, the bug is present + expect(filtered_commits).to be < total_commits, + "Path filtering returned #{filtered_commits} commits, same as total #{total_commits}." + end end context 'all optional parameter' do