BigW Consortium Gitlab

Commit 247385a7 by Dmitriy Zaporozhets

Merge branch 'fix-removed-file-in-diff' into 'master'

Fix bug when removed file was not appearing in merge request diff Finally we can see removed files in merge request diff Signed-off-by: 's avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Fixes #2533 See merge request !1471
parents 1ca11993 46503b78
...@@ -17,6 +17,7 @@ v 8.1.0 (unreleased) ...@@ -17,6 +17,7 @@ v 8.1.0 (unreleased)
- Move CI variables page to project settings area - Move CI variables page to project settings area
- Move CI triggers page to project settings area - Move CI triggers page to project settings area
- Move CI project settings page to CE project settings area - Move CI project settings page to CE project settings area
- Fix bug when removed file was not appearing in merge request diff
v 8.0.3 v 8.0.3
- Fix URL shown in Slack notifications - Fix URL shown in Slack notifications
......
...@@ -167,4 +167,23 @@ module DiffHelper ...@@ -167,4 +167,23 @@ module DiffHelper
content_tag(:span, commit_id, class: 'monospace'), content_tag(:span, commit_id, class: 'monospace'),
].join(' ').html_safe ].join(' ').html_safe
end end
def commit_for_diff(diff)
if diff.deleted_file
@merge_request ? @merge_request.commits.last : @commit.parent_id
else
@commit
end
end
def diff_file_html_data(project, diff_commit, diff_file)
{
blob_diff_path: namespace_project_blob_diff_path(project.namespace, project,
tree_join(diff_commit.id, diff_file.file_path))
}
end
def editable_diff?(diff)
!diff.deleted_file && @merge_request && @merge_request.source_project
end
end end
...@@ -15,7 +15,12 @@ ...@@ -15,7 +15,12 @@
.files .files
- diff_files.each_with_index do |diff_file, index| - diff_files.each_with_index do |diff_file, index|
= render 'projects/diffs/file', diff_file: diff_file, i: index, project: project - diff_commit = commit_for_diff(diff_file.diff)
- blob = project.repository.blob_for_diff(diff_commit, diff_file.diff)
- next unless blob
= render 'projects/diffs/file', i: index, project: project,
diff_file: diff_file, diff_commit: diff_commit, blob: blob
- if @diff_timeout - if @diff_timeout
.alert.alert-danger .alert.alert-danger
......
- blob = project.repository.blob_for_diff(@commit, diff_file.diff) .diff-file{id: "diff-#{i}", data: diff_file_html_data(project, diff_commit, diff_file)}
- return unless blob
- blob_diff_path = namespace_project_blob_diff_path(project.namespace, project, tree_join(@commit.id, diff_file.file_path))
.diff-file{id: "diff-#{i}", data: {blob_diff_path: blob_diff_path }}
.diff-header{id: "file-path-#{hexdigest(diff_file.new_path || diff_file.old_path)}"} .diff-header{id: "file-path-#{hexdigest(diff_file.new_path || diff_file.old_path)}"}
- if diff_file.deleted_file - if diff_file.diff.submodule?
%span="#{diff_file.old_path} deleted"
.diff-btn-group
- if @commit.parent_ids.present?
= view_file_btn(@commit.parent_id, diff_file, project)
- elsif diff_file.diff.submodule?
%span %span
- submodule_item = project.repository.blob_at(@commit.id, diff_file.file_path) - submodule_item = project.repository.blob_at(@commit.id, diff_file.file_path)
= submodule_link(submodule_item, @commit.id, project.repository) = submodule_link(submodule_item, @commit.id, project.repository)
- else - else
%span %span
- if diff_file.renamed_file - if diff_file.deleted_file
= "#{diff_file.old_path} deleted"
- elsif diff_file.renamed_file
= "#{diff_file.old_path} renamed to #{diff_file.new_path}" = "#{diff_file.old_path} renamed to #{diff_file.new_path}"
- else - else
= diff_file.new_path = diff_file.new_path
- if diff_file.mode_changed? - if diff_file.mode_changed?
%span.file-mode= "#{diff_file.diff.a_mode}#{diff_file.diff.b_mode}" %span.file-mode= "#{diff_file.diff.a_mode}#{diff_file.diff.b_mode}"
...@@ -28,12 +22,12 @@ ...@@ -28,12 +22,12 @@
%i.fa.fa-comments %i.fa.fa-comments
&nbsp; &nbsp;
- if @merge_request && @merge_request.source_project - if editable_diff?(diff_file)
= edit_blob_link(@merge_request.source_project, = edit_blob_link(@merge_request.source_project,
@merge_request.source_branch, diff_file.new_path, @merge_request.source_branch, diff_file.new_path,
after: '&nbsp;', from_merge_request_id: @merge_request.id) after: '&nbsp;', from_merge_request_id: @merge_request.id)
= view_file_btn(@commit.id, diff_file, project) = view_file_btn(diff_commit.id, diff_file, project)
.diff-content.diff-wrap-lines .diff-content.diff-wrap-lines
-# Skipp all non non-supported blobs -# Skipp all non non-supported blobs
......
...@@ -115,40 +115,40 @@ Feature: Project Merge Requests ...@@ -115,40 +115,40 @@ Feature: Project Merge Requests
Given project "Shop" have "Bug NS-05" open merge request with diffs inside Given project "Shop" have "Bug NS-05" open merge request with diffs inside
And I visit merge request page "Bug NS-05" And I visit merge request page "Bug NS-05"
And I click on the Changes tab And I click on the Changes tab
And I leave a comment like "Line is wrong" on line 39 of the second file And I leave a comment like "Line is wrong" on line 39 of the third file
And I click link "Hide inline discussion" of the second file And I click link "Hide inline discussion" of the third file
Then I should not see a comment like "Line is wrong here" in the second file Then I should not see a comment like "Line is wrong here" in the third file
@javascript @javascript
Scenario: I show comments on a merge request diff with comments in a single file Scenario: I show comments on a merge request diff with comments in a single file
Given project "Shop" have "Bug NS-05" open merge request with diffs inside Given project "Shop" have "Bug NS-05" open merge request with diffs inside
And I visit merge request page "Bug NS-05" And I visit merge request page "Bug NS-05"
And I click on the Changes tab And I click on the Changes tab
And I leave a comment like "Line is wrong" on line 39 of the second file And I leave a comment like "Line is wrong" on line 39 of the third file
Then I should see a comment like "Line is wrong" in the second file Then I should see a comment like "Line is wrong" in the third file
@javascript @javascript
Scenario: I hide comments on a merge request diff with comments in multiple files Scenario: I hide comments on a merge request diff with comments in multiple files
Given project "Shop" have "Bug NS-05" open merge request with diffs inside Given project "Shop" have "Bug NS-05" open merge request with diffs inside
And I visit merge request page "Bug NS-05" And I visit merge request page "Bug NS-05"
And I click on the Changes tab And I click on the Changes tab
And I leave a comment like "Line is correct" on line 12 of the first file And I leave a comment like "Line is correct" on line 12 of the second file
And I leave a comment like "Line is wrong" on line 39 of the second file And I leave a comment like "Line is wrong" on line 39 of the third file
And I click link "Hide inline discussion" of the second file And I click link "Hide inline discussion" of the third file
Then I should not see a comment like "Line is wrong here" in the second file Then I should not see a comment like "Line is wrong here" in the third file
And I should still see a comment like "Line is correct" in the first file And I should still see a comment like "Line is correct" in the second file
@javascript @javascript
Scenario: I show comments on a merge request diff with comments in multiple files Scenario: I show comments on a merge request diff with comments in multiple files
Given project "Shop" have "Bug NS-05" open merge request with diffs inside Given project "Shop" have "Bug NS-05" open merge request with diffs inside
And I visit merge request page "Bug NS-05" And I visit merge request page "Bug NS-05"
And I click on the Changes tab And I click on the Changes tab
And I leave a comment like "Line is correct" on line 12 of the first file And I leave a comment like "Line is correct" on line 12 of the second file
And I leave a comment like "Line is wrong" on line 39 of the second file And I leave a comment like "Line is wrong" on line 39 of the third file
And I click link "Hide inline discussion" of the second file And I click link "Hide inline discussion" of the third file
And I click link "Show inline discussion" of the second file And I click link "Show inline discussion" of the third file
Then I should see a comment like "Line is wrong" in the second file Then I should see a comment like "Line is wrong" in the third file
And I should still see a comment like "Line is correct" in the first file And I should still see a comment like "Line is correct" in the second file
@javascript @javascript
Scenario: I unfold diff Scenario: I unfold diff
...@@ -163,8 +163,8 @@ Feature: Project Merge Requests ...@@ -163,8 +163,8 @@ Feature: Project Merge Requests
Given project "Shop" have "Bug NS-05" open merge request with diffs inside Given project "Shop" have "Bug NS-05" open merge request with diffs inside
And I visit merge request page "Bug NS-05" And I visit merge request page "Bug NS-05"
And I click on the Changes tab And I click on the Changes tab
And I leave a comment like "Line is correct" on line 12 of the first file And I leave a comment like "Line is correct" on line 12 of the second file
And I leave a comment like "Line is wrong" on line 39 of the second file And I leave a comment like "Line is wrong" on line 39 of the third file
And I click Side-by-side Diff tab And I click Side-by-side Diff tab
Then I should see comments on the side-by-side diff page Then I should see comments on the side-by-side diff page
......
...@@ -224,43 +224,43 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -224,43 +224,43 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
end end
end end
step 'I click link "Hide inline discussion" of the second file' do step 'I click link "Hide inline discussion" of the third file' do
page.within '.files [id^=diff]:nth-child(2)' do page.within '.files [id^=diff]:nth-child(3)' do
find('.js-toggle-diff-comments').trigger('click') find('.js-toggle-diff-comments').trigger('click')
end end
end end
step 'I click link "Show inline discussion" of the second file' do step 'I click link "Show inline discussion" of the third file' do
page.within '.files [id^=diff]:nth-child(2)' do page.within '.files [id^=diff]:nth-child(3)' do
find('.js-toggle-diff-comments').trigger('click') find('.js-toggle-diff-comments').trigger('click')
end end
end end
step 'I should not see a comment like "Line is wrong" in the second file' do step 'I should not see a comment like "Line is wrong" in the third file' do
page.within '.files [id^=diff]:nth-child(2)' do page.within '.files [id^=diff]:nth-child(3)' do
expect(page).not_to have_visible_content "Line is wrong" expect(page).not_to have_visible_content "Line is wrong"
end end
end end
step 'I should see a comment like "Line is wrong" in the second file' do step 'I should see a comment like "Line is wrong" in the third file' do
page.within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do page.within '.files [id^=diff]:nth-child(3) .note-body > .note-text' do
expect(page).to have_visible_content "Line is wrong" expect(page).to have_visible_content "Line is wrong"
end end
end end
step 'I should not see a comment like "Line is wrong here" in the second file' do step 'I should not see a comment like "Line is wrong here" in the third file' do
page.within '.files [id^=diff]:nth-child(2)' do page.within '.files [id^=diff]:nth-child(3)' do
expect(page).not_to have_visible_content "Line is wrong here" expect(page).not_to have_visible_content "Line is wrong here"
end end
end end
step 'I should see a comment like "Line is wrong here" in the second file' do step 'I should see a comment like "Line is wrong here" in the third file' do
page.within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do page.within '.files [id^=diff]:nth-child(3) .note-body > .note-text' do
expect(page).to have_visible_content "Line is wrong here" expect(page).to have_visible_content "Line is wrong here"
end end
end end
step 'I leave a comment like "Line is correct" on line 12 of the first file' do step 'I leave a comment like "Line is correct" on line 12 of the second file' do
init_diff_note_first_file init_diff_note_first_file
page.within(".js-discussion-note-form") do page.within(".js-discussion-note-form") do
...@@ -268,12 +268,12 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -268,12 +268,12 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
click_button "Add Comment" click_button "Add Comment"
end end
page.within ".files [id^=diff]:nth-child(1) .note-body > .note-text" do page.within ".files [id^=diff]:nth-child(2) .note-body > .note-text" do
expect(page).to have_content "Line is correct" expect(page).to have_content "Line is correct"
end end
end end
step 'I leave a comment like "Line is wrong" on line 39 of the second file' do step 'I leave a comment like "Line is wrong" on line 39 of the third file' do
init_diff_note_second_file init_diff_note_second_file
page.within(".js-discussion-note-form") do page.within(".js-discussion-note-form") do
...@@ -282,8 +282,8 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -282,8 +282,8 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
end end
end end
step 'I should still see a comment like "Line is correct" in the first file' do step 'I should still see a comment like "Line is correct" in the second file' do
page.within '.files [id^=diff]:nth-child(1) .note-body > .note-text' do page.within '.files [id^=diff]:nth-child(2) .note-body > .note-text' do
expect(page).to have_visible_content "Line is correct" expect(page).to have_visible_content "Line is correct"
end end
end end
...@@ -303,7 +303,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -303,7 +303,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
end end
step 'I should see comments on the side-by-side diff page' do step 'I should see comments on the side-by-side diff page' do
page.within '.files [id^=diff]:nth-child(1) .parallel .note-body > .note-text' do page.within '.files [id^=diff]:nth-child(2) .parallel .note-body > .note-text' do
expect(page).to have_visible_content "Line is correct" expect(page).to have_visible_content "Line is correct"
end end
end end
......
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