Commit 948e1b84 authored by Douwe Maan's avatar Douwe Maan

Respect autocrlf setting when creating/updating file through web UI

parent 79e8e613
...@@ -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