Skip to content

Web editors and commit API convert CRLF line endings to LF

Summary

When committing a text file through either the ACE web editor, the WebIDE, or the commits API, any CRLF line endings in the file will be converted to LF.

This is due to our use of core.autocrlf=input, which was originally introduced in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/858 because text in HTML forms always gets encoded with CRLF (\r\n).

This behaviour introduces unwanted changes / merge conflicts for Windows users who don't use core.autocrlf=true, or similar.

Steps to reproduce

For the editors:

  1. Create a CRLF file locally and push to GitLab
  2. Make an edit through the ACE editor or WebIDE

For the API case: https://gitlab.com/gitlab-org/gitlab-ce/issues/50096#steps-to-reproduce

Example Project

What is the current bug behavior?

All CRLFs of the changed files are converted to LFs inside the repository on the server.

What is the expected correct behavior?

Existing CRLFs inside the repository on the server should stay as CRLFs. Newly added lines should use the existing line endings of the file.

Output of checks

This bug happens on GitLab.com

Possible fixes

Maybe we can just check if a file is CRLF when committing and not apply autocrlf=input in that case. This might be trickier than it sounds :)

The setting is applied in Gitaly. On the Rails side we have some references as well:

  • A spec testing the Gitaly behaviour in spec/models/repository_spec.rb
  • Instructions for source installations in doc/install/installation.md, and a verification check for this in lib/system_check/app/git_config_check.rb
Edited by Markus Koller