Deploying Sitecore items with Git and TDS

Fixing autocrlf and content-length issue

Hans Léautaud
Sitecore Tips & Tricks

--

Autocrlf = true

Git has a really cool feature which helps users to avoid annoying line ending issues in their IDE’s. A lot of client-side developers use a Mac or a different IDE than the server-side developers use. In Visual Studio this results in constantly popping up messages with the question if you want to fix these issues. Yes, there are extensions to fix these problems but we want to fix the problem at the source, right? The autocrlf property can come in handy in these situations. Git will convert all line-endings to LF when commiting your code.

Sitecore serialization

When you are familiar with Sitecore, you probably are also familiar with the serialization option in Sitecore. If you are not, open the Content Editor and activate the Developer tab in your ribbon.

Developer ribbon in Sitecore

Sitecore will serialize items into .item files on disk. This is extremely useful in some cases. Team Development for Sitecore (TDS) also uses this technique to serialize and deploy items.

These .item files are not JSON or XML formatted. No, they’re just plain text files.

.item file generated by Sitecore

As you can see in the file above, all files are marked with the —-field—— comment. All fields are also provided with a field GUID and a content-length. This works fine in most cases (although I find it somewhat cumbersome). However, this will give you some headaches when you are using fields with multiple lines. Then, in combination with the autocrlf option in Git, the content-length field and the actual length of the field do not correspond which will result in an error in Sitecore (and thus also in TDS):

Length of field content does not match the content-length attribute

The solution

Fortunately this is fixable with a so called .gitattributes file. Just add the following line to this file:

*.item -text

This will not fix your problem immediately though. You should remove all the previously synced .item files from Git and re-sync them with TDS.

When using TeamCity

If you are using TeamCity, don’t forget to disable the following setting in your VCS settings:

VCS settings in TeamCity

Now all Sitecore items should be deployed correctly! Hope it helps!

--

--