a7ea4b626b553d5563207b95fbd10afdae47002c
   1#!/bin/sh
   2
   3test_description='CRLF merge conflict across text=auto change
   4
   5* [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
  15. ./test-lib.sh
  16
  17test_expect_success setup '
  18        git config merge.renormalize true &&
  19        git config core.autocrlf false &&
  20
  21        echo first line | append_cr >file &&
  22        echo first line >control_file &&
  23        echo only line >inert_file &&
  24
  25        git add file control_file inert_file &&
  26        test_tick &&
  27        git commit -m "Initial" &&
  28        git tag initial &&
  29        git branch side &&
  30
  31        echo "* text=auto" >.gitattributes &&
  32        touch file &&
  33        git add .gitattributes file &&
  34        test_tick &&
  35        git commit -m "normalize file" &&
  36
  37        echo same line | append_cr >>file &&
  38        echo same line >>control_file &&
  39        git add file control_file &&
  40        test_tick &&
  41        git commit -m "add line from a" &&
  42        git tag a &&
  43
  44        git rm .gitattributes &&
  45        rm file &&
  46        git checkout file &&
  47        test_tick &&
  48        git commit -m "remove .gitattributes" &&
  49        git tag c &&
  50
  51        git checkout side &&
  52        echo same line | append_cr >>file &&
  53        echo same line >>control_file &&
  54        git add file control_file &&
  55        test_tick &&
  56        git commit -m "add line from b" &&
  57        git tag b &&
  58
  59        git checkout master
  60'
  61
  62test_expect_success 'Merge after setting text=auto' '
  63        cat <<-\EOF >expected &&
  64        first line
  65        same line
  66        EOF
  67
  68        git rm -fr . &&
  69        rm -f .gitattributes &&
  70        git reset --hard a &&
  71        git merge b &&
  72        test_cmp expected file
  73'
  74
  75test_expect_success 'Merge addition of text=auto' '
  76        cat <<-\EOF >expected &&
  77        first line
  78        same line
  79        EOF
  80
  81        git rm -fr . &&
  82        rm -f .gitattributes &&
  83        git reset --hard b &&
  84        git merge a &&
  85        test_cmp expected file
  86'
  87
  88test_expect_failure 'checkout -m after setting text=auto' '
  89        cat <<-\EOF >expected &&
  90        first line
  91        same line
  92        EOF
  93
  94        git rm -fr . &&
  95        rm -f .gitattributes &&
  96        git reset --hard initial &&
  97        git checkout a -- . &&
  98        git checkout -m b &&
  99        test_cmp expected file
 100'
 101
 102test_expect_failure 'checkout -m addition of text=auto' '
 103        cat <<-\EOF >expected &&
 104        first line
 105        same line
 106        EOF
 107
 108        git rm -fr . &&
 109        rm -f .gitattributes file &&
 110        git reset --hard initial &&
 111        git checkout b -- . &&
 112        git checkout -m a &&
 113        test_cmp expected file
 114'
 115
 116test_expect_failure 'cherry-pick patch from after text=auto was added' '
 117        append_cr <<-\EOF >expected &&
 118        first line
 119        same line
 120        EOF
 121
 122        git rm -fr . &&
 123        git reset --hard b &&
 124        test_must_fail git cherry-pick a >err 2>&1 &&
 125        grep "[Nn]othing added" err &&
 126        test_cmp expected file
 127'
 128
 129test_expect_success 'Test delete/normalize conflict' '
 130        git checkout -f side &&
 131        git rm -fr . &&
 132        rm -f .gitattributes &&
 133        git reset --hard initial &&
 134        git rm file &&
 135        git commit -m "remove file" &&
 136        git checkout master &&
 137        git reset --hard a^ &&
 138        git merge side
 139'
 140
 141test_done