Commit da857767 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'dm-quick-fix-web-edit-new-lines' into 'master'

Respect autocrlf setting when creating/updating file through web UI

Closes gitlab-com/www-gitlab-com#1152

See merge request !9198
parents 2fcc1f7e 948e1b84
......@@ -1230,6 +1230,14 @@ class Repository
action[:content]
end
detect = CharlockHolmes::EncodingDetector.new.detect(content) if content
unless detect && detect[:type] == :binary
# When writing to the repo directly as we are doing here,
# the `core.autocrlf` config isn't taken into account.
content.gsub!("\r\n", "\n") if self.autocrlf
end
oid = rugged.write(content, :blob)
index.add(path: path, oid: oid, mode: mode)
......
......@@ -351,6 +351,17 @@ describe Repository, models: true do
expect(blob.data).to eq('Changelog!')
end
it 'respects the autocrlf setting' do
repository.commit_file(user, 'hello.txt', "Hello,\r\nWorld",
message: 'Add hello world',
branch_name: 'master',
update: true)
blob = repository.blob_at('master', 'hello.txt')
expect(blob.data).to eq("Hello,\nWorld")
end
context "when an author is specified" do
it "uses the given email/name to set the commit's author" do
expect do
......
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