1#!/bin/sh
   2test_description='CRLF merge conflict across text=auto change
   4* [master] remove .gitattributes
   6 ! [side] add line from b
   7--
   8 + [side] add line from b
   9*  [master] remove .gitattributes
  10*  [master^] add line from a
  11*  [master~2] normalize file
  12*+ [side^] Initial
  13'
  14. ./test-lib.sh
  16test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
  18test_expect_success setup '
  20        git config core.autocrlf false &&
  21        echo first line | append_cr >file &&
  23        echo first line >control_file &&
  24        echo only line >inert_file &&
  25        git add file control_file inert_file &&
  27        test_tick &&
  28        git commit -m "Initial" &&
  29        git tag initial &&
  30        git branch side &&
  31        echo "* text=auto" >.gitattributes &&
  33        touch file &&
  34        git add .gitattributes file &&
  35        test_tick &&
  36        git commit -m "normalize file" &&
  37        echo same line | append_cr >>file &&
  39        echo same line >>control_file &&
  40        git add file control_file &&
  41        test_tick &&
  42        git commit -m "add line from a" &&
  43        git tag a &&
  44        git rm .gitattributes &&
  46        rm file &&
  47        git checkout file &&
  48        test_tick &&
  49        git commit -m "remove .gitattributes" &&
  50        git tag c &&
  51        git checkout side &&
  53        echo same line | append_cr >>file &&
  54        echo same line >>control_file &&
  55        git add file control_file &&
  56        test_tick &&
  57        git commit -m "add line from b" &&
  58        git tag b &&
  59        git checkout master
  61'
  62test_expect_success 'set up fuzz_conflict() helper' '
  64        fuzz_conflict() {
  65                sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
  66        }
  67'
  68test_expect_success 'Merge after setting text=auto' '
  70        cat <<-\EOF >expected &&
  71        first line
  72        same line
  73        EOF
  74        git config merge.renormalize true &&
  76        git rm -fr . &&
  77        rm -f .gitattributes &&
  78        git reset --hard a &&
  79        git merge b &&
  80        test_cmp expected file
  81'
  82test_expect_success 'Merge addition of text=auto' '
  84        cat <<-\EOF >expected &&
  85        first line
  86        same line
  87        EOF
  88        git config merge.renormalize true &&
  90        git rm -fr . &&
  91        rm -f .gitattributes &&
  92        git reset --hard b &&
  93        git merge a &&
  94        test_cmp expected file
  95'
  96test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
  98        q_to_cr <<-\EOF >expected &&
  99        <<<<<<<
 100        first line
 101        same line
 102        =======
 103        first lineQ
 104        same lineQ
 105        >>>>>>>
 106        EOF
 107        git config merge.renormalize false &&
 109        rm -f .gitattributes &&
 110        git reset --hard a &&
 111        test_must_fail git merge b &&
 112        fuzz_conflict file >file.fuzzy &&
 113        test_cmp expected file.fuzzy
 114'
 115test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
 117        q_to_cr <<-\EOF >expected &&
 118        <<<<<<<
 119        first lineQ
 120        same lineQ
 121        =======
 122        first line
 123        same line
 124        >>>>>>>
 125        EOF
 126        git config merge.renormalize false &&
 128        rm -f .gitattributes &&
 129        git reset --hard b &&
 130        test_must_fail git merge a &&
 131        fuzz_conflict file >file.fuzzy &&
 132        test_cmp expected file.fuzzy
 133'
 134test_expect_failure 'checkout -m after setting text=auto' '
 136        cat <<-\EOF >expected &&
 137        first line
 138        same line
 139        EOF
 140        git config merge.renormalize true &&
 142        git rm -fr . &&
 143        rm -f .gitattributes &&
 144        git reset --hard initial &&
 145        git checkout a -- . &&
 146        git checkout -m b &&
 147        test_cmp expected file
 148'
 149test_expect_failure 'checkout -m addition of text=auto' '
 151        cat <<-\EOF >expected &&
 152        first line
 153        same line
 154        EOF
 155        git config merge.renormalize true &&
 157        git rm -fr . &&
 158        rm -f .gitattributes file &&
 159        git reset --hard initial &&
 160        git checkout b -- . &&
 161        git checkout -m a &&
 162        test_cmp expected file
 163'
 164test_expect_failure 'cherry-pick patch from after text=auto was added' '
 166        append_cr <<-\EOF >expected &&
 167        first line
 168        same line
 169        EOF
 170        git config merge.renormalize true &&
 172        git rm -fr . &&
 173        git reset --hard b &&
 174        test_must_fail git cherry-pick a >err 2>&1 &&
 175        grep "[Nn]othing added" err &&
 176        test_cmp expected file
 177'
 178test_expect_success 'Test delete/normalize conflict' '
 180        git checkout -f side &&
 181        git rm -fr . &&
 182        rm -f .gitattributes &&
 183        git reset --hard initial &&
 184        git rm file &&
 185        git commit -m "remove file" &&
 186        git checkout master &&
 187        git reset --hard a^ &&
 188        git merge side
 189'
 190test_done