提交 57dddacf 编写于 作者: R Rémy Coutable

Merge branch '32983-merge-conflict-resolution-removed-the-newline-in-the-end-of-file' into 'master'

Resolve "Merge conflict resolution removed the newline in the end of file"

Closes #32983

See merge request !11817
......@@ -37,11 +37,13 @@ module MergeRequests
private
def write_resolved_file_to_index(merge_index, rugged, file, params)
new_file = if params[:sections]
file.resolve_lines(params[:sections]).map(&:text).join("\n")
elsif params[:content]
file.resolve_content(params[:content])
end
if params[:sections]
new_file = file.resolve_lines(params[:sections]).map(&:text).join("\n")
new_file << "\n" if file.our_blob.data.ends_with?("\n")
elsif params[:content]
new_file = file.resolve_content(params[:content])
end
our_path = file.our_path
......
---
title: Keep trailing newline when resolving conflicts by picking sides
merge_request:
author:
......@@ -26,6 +26,10 @@ describe MergeRequests::Conflicts::ResolveService do
describe '#execute' do
let(:service) { described_class.new(merge_request) }
def blob_content(project, ref, path)
project.repository.blob_at(ref, path).data
end
context 'with section params' do
let(:params) do
{
......@@ -66,6 +70,35 @@ describe MergeRequests::Conflicts::ResolveService do
end
end
context 'when some files have trailing newlines' do
let!(:source_head) do
branch = 'conflict-resolvable'
path = 'files/ruby/popen.rb'
popen_content = blob_content(project, branch, path)
project.repository.update_file(
user,
path,
popen_content.chomp("\n"),
message: 'Remove trailing newline from popen.rb',
branch_name: branch
)
end
before do
service.execute(user, params)
end
it 'preserves trailing newlines from our side of the conflicts' do
head_sha = merge_request.source_branch_head.sha
popen_content = blob_content(project, head_sha, 'files/ruby/popen.rb')
regex_content = blob_content(project, head_sha, 'files/ruby/regex.rb')
expect(popen_content).not_to end_with("\n")
expect(regex_content).to end_with("\n")
end
end
context 'when the source project is a fork and does not contain the HEAD of the target branch' do
let!(:target_head) do
project.repository.create_file(
......@@ -142,10 +175,13 @@ describe MergeRequests::Conflicts::ResolveService do
end
it 'sets the content to the content given' do
blob = merge_request.source_project.repository.blob_at(merge_request.source_branch_head.sha,
'files/ruby/popen.rb')
blob = blob_content(
merge_request.source_project,
merge_request.source_branch_head.sha,
'files/ruby/popen.rb'
)
expect(blob.data).to eq(popen_content)
expect(blob).to eq(popen_content)
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册