Commit e1a238c3 authored by Robert Speicher's avatar Robert Speicher Committed by Regis

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
parent 50020499
...@@ -1230,6 +1230,14 @@ class Repository ...@@ -1230,6 +1230,14 @@ class Repository
action[:content] action[:content]
end 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) oid = rugged.write(content, :blob)
index.add(path: path, oid: oid, mode: mode) index.add(path: path, oid: oid, mode: mode)
......
...@@ -351,6 +351,17 @@ describe Repository, models: true do ...@@ -351,6 +351,17 @@ describe Repository, models: true do
expect(blob.data).to eq('Changelog!') expect(blob.data).to eq('Changelog!')
end 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 context "when an author is specified" do
it "uses the given email/name to set the commit's author" do it "uses the given email/name to set the commit's author" do
expect 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