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
This commit is contained in:
commit
da85776758
2 changed files with 19 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue