autocrlf and safecrlf set to false don't work for api commits
Summary
We try to commit files changes with api commit function. but our file end of line are automatically converted to LF. We want to be sure that we have the same end of line characters that we use in local on the server (if crlf keep crlf, if lf keep lf)
It works when we commit with git commit and push commands on local repository. But we need to use the API commit to automate some stuffs.
Steps to reproduce
-
Read a file on our gitlab server with the API (that contains crlf)
(projects/:projectId/repository/files/:file_location/raw?ref=branch_name) => here we got crlf -
Modify the file in memory
-
Post a commit to the API with the crlf
(projects/:projectId:/repository/commits)
with a Json body :
{
"branch": "branch_name",
"commit_message": "a message",
"actions": [
{
"action": "update",
"file_path": "file_location",
"content": "the modified content of the file"
}]
}
Here the content contains always crlf when we create the request.
But when we look the result on our gitlab server the file contains now lf as end of lines.
We already tried
-
* -text
in .gitattributes of our repo -
* text eol=crlf
(get crlf in local but the server file contains lf) -
core.autocrlf=false
in local, global and system gitconfigs (None works for API) -
core.safecrlf=false
in local, global and system gitconfigs (None works for API) - autocrlf and safecrlf on server in /etc/gitlab/gitlab.rb in
omnibus_gitconfig['system']
In source code
We made a quick search in the source code of gitlab and found :
in "/opt/gitlab/embedded/service/gitlab-rails/lib/system_check/app/git_config_check.rb"
OPTIONS = {
'core.autocrlf' => 'input'
}.freeze
set_name 'Git configured correctly?'
def check?
correct_options = OPTIONS.map do |name, value|
run_command(%W(#{Gitlab.config.git.bin_path} config --global --get #{name})).try(:squish) == value
end
correct_options.all?
end
in "/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/git/operation_service.rb"
def update_autocrlf_option
if repository.autocrlf != :input
repository.autocrlf = :input
end
end
It seems that it force autocrlf to input directly in code. But we Don't know if it is linked to the use of the API.
Proposition
If nothing already exists. It would be great to add a request parameter to the commit action of each file to set the end of line mode we want to use at commit time.
/label ~bug /weight 3