Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore serialized items with Git autocrlf

We're experiencing a problem with serialized items. Our use case is to work locally with own databases and sync all the items with Unicorn. Then we push all the items to our Git repository. The local Git config is set to autocrlf=true. This is needed because we have some frontend engineers on the project which work with Mac OS X. We serialize the complete "core" database with Unicorn (like in the default configuration after installation).

It seems, that some of the items in the core database were created with a non Windows system. If we i.e. look into the item /sitecore/system/Dictionary/O/One or more items have been changed Do you want to overwrite these changes: When I serialize this item and look into it, I see that the Key field contains multiple lines and the the line feeds are marked with "\n" and that the content-length is 77 (see attached screenshot from Notepad++, the left side). After this I push this file to the Git repository and pull the item on another workstation from the repository. Due to the setting autocrlf=true, the "\n" is automatically converted to a "\r\n", which results in a content-length of 79 instead of the original 77 (see right side of attached screenshot). When I want to deserialize this item I get the exception that the content-length does not match.

enter image description here

Does anyone have had such an error before and what did you do to avoid this? I see the option to disable the autocrlf or to exclude these items from the serialization sync. But I would like to avoid doing one of these options.

like image 911
Kevin Brechbühl Avatar asked Jan 22 '14 14:01

Kevin Brechbühl


1 Answers

You can control that behavior from a .gitattributes file.

In my attributes file, .item files are set to be treated as binary files.

This is the .gitattributes file I use on our projects.

* text=auto

# These files are text and should be normalized (convert crlf => lf)
*.cs      text diff=csharp
*.xaml    text
*.csproj  text
*.sln     text
*.tt      text
*.ps1     text
*.cmd     text
*.msbuild text
*.md      text

# TDS files should be treated as binary
*.item -text
like image 92
dunston Avatar answered Oct 13 '22 19:10

dunston