From 7ab62a20831e3eba3fd8ebdf60bcc557c07f7b69 Mon Sep 17 00:00:00 2001 From: Joe Woodward Date: Fri, 16 Jun 2023 16:44:22 +0100 Subject: [PATCH] Update Gitlab::Git::Repository#find_changed_paths logic Allow passing merge_commit_diff_mode through Gitlab::Git::Repository#find_changed_paths to specify how we diff merge commits included in the request. --- lib/gitlab/git/repository.rb | 6 +++-- spec/lib/gitlab/git/repository_spec.rb | 35 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 6cae0fc1780548..ed45d3eb0306d8 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -518,13 +518,15 @@ def diff_stats(left_id, right_id) empty_diff_stats end - def find_changed_paths(commits) + def find_changed_paths(commits, merge_commit_diff_mode: nil) processed_commits = commits.reject { |ref| ref.blank? || Gitlab::Git.blank_ref?(ref) } return [] if processed_commits.empty? wrapped_gitaly_errors do - gitaly_commit_client.find_changed_paths(processed_commits) + gitaly_commit_client.find_changed_paths( + processed_commits, merge_commit_diff_mode: merge_commit_diff_mode + ) end rescue CommandError, TypeError, NoRepository [] diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 5e3b136cf2e534..b137157f2d5d6d 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -1675,6 +1675,41 @@ def create_commit(blobs) expect(collection).to be_a(Enumerable) expect(collection.to_a).to be_empty end + + describe 'merge_commit_diff_mode argument' do + let(:gitaly_commit_client) { double('Gitlab::GitalyClient::CommitService') } + + before do + allow(repository).to receive(:gitaly_commit_client).and_return(gitaly_commit_client) + allow(gitaly_commit_client).to receive(:find_changed_paths) + end + + context 'when omitted' do + before do + repository.find_changed_paths(['sha']) + end + + it 'defaults to nil' do + expect(gitaly_commit_client) + .to have_received(:find_changed_paths) + .with(['sha'], merge_commit_diff_mode: nil) + end + end + + context 'when included' do + let(:passed_value) { 'foobar' } + + before do + repository.find_changed_paths(['sha'], merge_commit_diff_mode: passed_value) + end + + it 'passes the value on to the commit client' do + expect(gitaly_commit_client) + .to have_received(:find_changed_paths) + .with(['sha'], merge_commit_diff_mode: passed_value) + end + end + end end describe "#ls_files" do -- GitLab