t / t0025-crlf-auto.shon commit Merge branch 'db/delta-applier' into svn-fe (a8d3d26)
   1#!/bin/sh
   2
   3test_description='CRLF conversion'
   4
   5. ./test-lib.sh
   6
   7has_cr() {
   8        tr '\015' Q <"$1" | grep Q >/dev/null
   9}
  10
  11test_expect_success setup '
  12
  13        git config core.autocrlf false &&
  14
  15        for w in Hello world how are you; do echo $w; done >one &&
  16        for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >two &&
  17        for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >three &&
  18        git add . &&
  19
  20        git commit -m initial &&
  21
  22        one=`git rev-parse HEAD:one` &&
  23        two=`git rev-parse HEAD:two` &&
  24        three=`git rev-parse HEAD:three` &&
  25
  26        echo happy.
  27'
  28
  29test_expect_success 'default settings cause no changes' '
  30
  31        rm -f .gitattributes tmp one two three &&
  32        git read-tree --reset -u HEAD &&
  33
  34        ! has_cr one &&
  35        has_cr two &&
  36        onediff=`git diff one` &&
  37        twodiff=`git diff two` &&
  38        threediff=`git diff three` &&
  39        test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
  40'
  41
  42test_expect_success 'crlf=true causes a CRLF file to be normalized' '
  43
  44        # Backwards compatibility check
  45        rm -f .gitattributes tmp one two three &&
  46        echo "two crlf" > .gitattributes &&
  47        git read-tree --reset -u HEAD &&
  48
  49        # Note, "normalized" means that git will normalize it if added
  50        has_cr two &&
  51        twodiff=`git diff two` &&
  52        test -n "$twodiff"
  53'
  54
  55test_expect_success 'text=true causes a CRLF file to be normalized' '
  56
  57        rm -f .gitattributes tmp one two three &&
  58        echo "two text" > .gitattributes &&
  59        git read-tree --reset -u HEAD &&
  60
  61        # Note, "normalized" means that git will normalize it if added
  62        has_cr two &&
  63        twodiff=`git diff two` &&
  64        test -n "$twodiff"
  65'
  66
  67test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
  68
  69        rm -f .gitattributes tmp one two three &&
  70        git config core.autocrlf false &&
  71        echo "one eol=crlf" > .gitattributes &&
  72        git read-tree --reset -u HEAD &&
  73
  74        has_cr one &&
  75        onediff=`git diff one` &&
  76        test -z "$onediff"
  77'
  78
  79test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
  80
  81        rm -f .gitattributes tmp one two three &&
  82        git config core.autocrlf input &&
  83        echo "one eol=crlf" > .gitattributes &&
  84        git read-tree --reset -u HEAD &&
  85
  86        has_cr one &&
  87        onediff=`git diff one` &&
  88        test -z "$onediff"
  89'
  90
  91test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' '
  92
  93        rm -f .gitattributes tmp one two three &&
  94        git config core.autocrlf true &&
  95        echo "one eol=lf" > .gitattributes &&
  96        git read-tree --reset -u HEAD &&
  97
  98        ! has_cr one &&
  99        onediff=`git diff one` &&
 100        test -z "$onediff"
 101'
 102
 103test_expect_success 'autocrlf=true does not normalize CRLF files' '
 104
 105        rm -f .gitattributes tmp one two three &&
 106        git config core.autocrlf true &&
 107        git read-tree --reset -u HEAD &&
 108
 109        has_cr one &&
 110        has_cr two &&
 111        onediff=`git diff one` &&
 112        twodiff=`git diff two` &&
 113        threediff=`git diff three` &&
 114        test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
 115'
 116
 117test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '
 118
 119        rm -f .gitattributes tmp one two three &&
 120        git config core.autocrlf true &&
 121        echo "* text=auto" > .gitattributes &&
 122        git read-tree --reset -u HEAD &&
 123
 124        has_cr one &&
 125        has_cr two &&
 126        onediff=`git diff one` &&
 127        twodiff=`git diff two` &&
 128        threediff=`git diff three` &&
 129        test -z "$onediff" -a -n "$twodiff" -a -z "$threediff"
 130'
 131
 132test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '
 133
 134        rm -f .gitattributes tmp one two three &&
 135        git config core.autocrlf true &&
 136        echo "* text=auto" > .gitattributes &&
 137        git read-tree --reset -u HEAD &&
 138
 139        ! has_cr three &&
 140        threediff=`git diff three` &&
 141        test -z "$threediff"
 142'
 143
 144test_expect_success 'eol=crlf _does_ normalize binary files' '
 145
 146        rm -f .gitattributes tmp one two three &&
 147        echo "three eol=crlf" > .gitattributes &&
 148        git read-tree --reset -u HEAD &&
 149
 150        has_cr three &&
 151        threediff=`git diff three` &&
 152        test -z "$threediff"
 153'
 154
 155test_done