Commit 116280a6 authored by Baodong's avatar Baodong

Fix MR diff compare with previous version

When we create a MR with a lot of commits, GitLab help us combine some commits into a version. And we can compare base with previous version.

Changelog: fixed
parent ab70437a
...@@ -163,7 +163,10 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic ...@@ -163,7 +163,10 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
end end
def render_merge_ref_head_diff? def render_merge_ref_head_diff?
Gitlab::Utils.to_boolean(params[:diff_head]) && @merge_request.diffable_merge_ref? && @start_sha.nil? params[:diff_id].blank? &&
Gitlab::Utils.to_boolean(params[:diff_head]) &&
@merge_request.diffable_merge_ref? &&
@start_sha.nil?
end end
def note_positions def note_positions
......
...@@ -69,6 +69,20 @@ RSpec.describe Projects::MergeRequests::DiffsController do ...@@ -69,6 +69,20 @@ RSpec.describe Projects::MergeRequests::DiffsController do
end end
end end
shared_examples 'show the right diff files with previous diff_id' do
context 'with previous diff_id' do
let!(:merge_request_diff_1) { merge_request.merge_request_diffs.create!(head_commit_sha: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
let!(:merge_request_diff_2) { merge_request.merge_request_diffs.create!(head_commit_sha: '5937ac0a7beb003549fc5fd26fc247adbce4a52e', diff_type: :merge_head) }
subject { go(diff_id: merge_request_diff_1.id, diff_head: true) }
it 'shows the right diff files' do
subject
expect(json_response["diff_files"].size).to eq(merge_request_diff_1.files_count)
end
end
end
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
...@@ -142,6 +156,8 @@ RSpec.describe Projects::MergeRequests::DiffsController do ...@@ -142,6 +156,8 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like '404 for unexistent diffable' it_behaves_like '404 for unexistent diffable'
it_behaves_like 'show the right diff files with previous diff_id'
context 'when not authorized' do context 'when not authorized' do
let(:another_user) { create(:user) } let(:another_user) { create(:user) }
...@@ -480,6 +496,8 @@ RSpec.describe Projects::MergeRequests::DiffsController do ...@@ -480,6 +496,8 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like '404 for unexistent diffable' it_behaves_like '404 for unexistent diffable'
it_behaves_like 'show the right diff files with previous diff_id'
context 'when not authorized' do context 'when not authorized' do
let(:other_user) { create(:user) } let(:other_user) { create(:user) }
...@@ -499,7 +517,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do ...@@ -499,7 +517,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
let(:expected_options) { collection_arguments(current_page: 1, total_pages: 1) } let(:expected_options) { collection_arguments(current_page: 1, total_pages: 1).merge(merge_ref_head_diff: false) }
end end
it_behaves_like 'successful request' it_behaves_like 'successful request'
...@@ -522,7 +540,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do ...@@ -522,7 +540,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::Compare } let(:collection) { Gitlab::Diff::FileCollection::Compare }
let(:expected_options) { collection_arguments } let(:expected_options) { collection_arguments.merge(merge_ref_head_diff: false) }
end end
it_behaves_like 'successful request' it_behaves_like 'successful request'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment