1#!/bin/sh
   2test_description='CRLF conversion'
   4. ./test-lib.sh
   6has_cr() {
   8        tr '\015' Q <"$1" | grep Q >/dev/null
   9}
  10test_expect_success setup '
  12        git config core.autocrlf false &&
  14        echo "one text" > .gitattributes &&
  16        for w in Hello world how are you; do echo $w; done >one &&
  18        for w in I am very very fine thank you; do echo $w; done >two &&
  19        git add . &&
  20        git commit -m initial &&
  22        one=`git rev-parse HEAD:one` &&
  24        two=`git rev-parse HEAD:two` &&
  25        echo happy.
  27'
  28test_expect_success 'eol=lf puts LFs in normalized file' '
  30        rm -f .gitattributes tmp one two &&
  32        git config core.eol lf &&
  33        git read-tree --reset -u HEAD &&
  34        ! has_cr one &&
  36        ! has_cr two &&
  37        onediff=`git diff one` &&
  38        twodiff=`git diff two` &&
  39        test -z "$onediff" -a -z "$twodiff"
  40'
  41test_expect_success 'eol=crlf puts CRLFs in normalized file' '
  43        rm -f .gitattributes tmp one two &&
  45        git config core.eol crlf &&
  46        git read-tree --reset -u HEAD &&
  47        has_cr one &&
  49        ! has_cr two &&
  50        onediff=`git diff one` &&
  51        twodiff=`git diff two` &&
  52        test -z "$onediff" -a -z "$twodiff"
  53'
  54test_expect_success 'autocrlf=true overrides eol=lf' '
  56        rm -f .gitattributes tmp one two &&
  58        git config core.eol lf &&
  59        git config core.autocrlf true &&
  60        git read-tree --reset -u HEAD &&
  61        has_cr one &&
  63        has_cr two &&
  64        onediff=`git diff one` &&
  65        twodiff=`git diff two` &&
  66        test -z "$onediff" -a -z "$twodiff"
  67'
  68test_expect_success 'autocrlf=true overrides unset eol' '
  70        rm -f .gitattributes tmp one two &&
  72        git config --unset-all core.eol &&
  73        git config core.autocrlf true &&
  74        git read-tree --reset -u HEAD &&
  75        has_cr one &&
  77        has_cr two &&
  78        onediff=`git diff one` &&
  79        twodiff=`git diff two` &&
  80        test -z "$onediff" -a -z "$twodiff"
  81'
  82test_done