tags:

views:

532

answers:

4

Context

A number of my application user configuration files are kept in a git repository for easy sharing across multiple machines and multiple platforms. Amongst these configuration files is .gitconfig which contains the following settings for handling the carriage return linefeed characters

[core]
    autocrlf = true
    safecrlf = false

Problem

These settings also gets applied on a GNU/Linux platform which causes obscure errors.

Question

What are some best practices for handling these platform specific differences in configuration files?

Proposed solution

I realize this problem could be solved by having a branch for each platform and keeping the common stuff in master and merging with the platform branch when master moves forward. I'm wondering if there are any easier solutions to this problem?

A: 

I think you should have the .gitconfig depend on the operating system the user is using. Windows users don't need autocrlf at all while Linux users do. E.g. save the text files with crlf and have Git convert the files automatically back and forth for the Linux users.

You might also want to check .gitattributes, which allows you to define which files are converted and which are not. If you have the configuration files in just one place, you could define that the conversion is only done in that directory just to be on the safe side.

Makis
+4  A: 

I have reviewed that kind of config setting (crlf) extensively in the question:
distributing git configuration with the code.

The conclusion was:

*.java +crlf
*.txt +crlf
...
  • avoid doing any kind of conversion of type of files which don't need it, because of the various side-effect of such a conversion on merges, git status, shell environment and svn import (see "distributing git configuration with the code" for links and references).
  • avoid any crlf conversion all together if you can.

Now, regarding the specific issue of per-platform settings, branch is not always the right tool, especially for non-program related data (i.e; those settings are not related to what you are developing, only to the VCS storing the history of your development)

As stated in the question Git: How to maintain two branches of a project and merge only shared data?:

your life will be vastly simpler if you put the system-dependent code in different directories and deal with the cross-platform dependencies in the build system (Makefiles or whatever you use).

In this case, while branches could be use for system-dependent code, I would recommend directory for support tools system-dependent settings, with a script able to build the appropriate .gitattributes file to apply the right setting depending on the repo deployment platform.

VonC
+2  A: 

Never turn autocrlf on, it causes nothing but headaches and sorrows.

There's no excuse to use \r\n on windows, all decent editors (by definition) can handle \n.

hasen j
A: 

Do not put autocrlf and safecrlf in .gitconfig at all.

It might not work in your case, but works well in mine. Default settings for current git versions are right for most platforms. Linux/unix version uses autocrlf=false and msysgit is (by default) installed presetted for autocrlf=auto.

I recommend msysgit over cygwin git if you are doing non-cygwin development on Windows.

Sometimes I need different settings for certain projects. Then I set it on repository level.

Tomek Szpakowicz