Converting between tabs and spaces

It is very easy to convert between tabs and spaces automatically when committing and check-outing text files with GIT. GIT allows it with the attributes mechanism:

http://git-scm.com/book/ch7-2.html

http://stackoverflow.com/questions/2316677/can-git-automatically-switch-between-spaces-and-tabs

To configure this behavior all you need is:

  1. Place 'expand' and 'unexpand' commands in your 'PATH' environment variable. For Windows they are part of GnuWin32 CoreUtils package:
    1. http://gnuwin32.sourceforge.net/packages.html
  2. Define needed GIT filter names. These are examples if you want tabs locally and two or four spaces in the repository:
      1. git config --system filter.tabspace2.clean "expand --tabs=2 --initial"
      2. git config --system filter.tabspace2.smudge "unexpand --tabs=2 --first-only"
      3. git config --system filter.tabspace4.clean "expand --tabs=4 --initial"
      4. git config --system filter.tabspace4.smudge "unexpand --tabs=4 --first-only"
  3. Apply settings to your local repository.
    1. Create .git/info/attributes file inside your local repository directory and add following line(s) to it:
      1. *.<extension> filter=tabspace2
    2. Where <extension> is file extension than will be filtered.
  4. If you have any changes, commit them and then checkout all files to have filtered version on a disc:
      1. git checkout HEAD -- **

Nemerle

Things may be a little more complicated when you want to do the same with Nemerle source codes, because there is a risk that 'unexpand' command can corrupt files that are using indentation-based syntax. The solution is to use script that expands/unexpands only files with non indentation-based syntax. You can copy tabs_nemerle.sh script to the bin directory of git and configure filters that way:

git config --system filter.tabspace2.clean "tabs_nemerle.sh 2 expand"
git config --system filter.tabspace2.smudge "tabs_nemerle.sh 2 unexpand"