t / t6038-merge-text-auto.shon commit Merge branch 'sb/check-return-from-read-ref' into maint (7a23807)
   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_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
  18
  19test_expect_success setup '
  20        git config core.autocrlf false &&
  21
  22        echo first line | append_cr >file &&
  23        echo first line >control_file &&
  24        echo only line >inert_file &&
  25
  26        git add file control_file inert_file &&
  27        test_tick &&
  28        git commit -m "Initial" &&
  29        git tag initial &&
  30        git branch side &&
  31
  32        echo "* text=auto" >.gitattributes &&
  33        touch file &&
  34        git add .gitattributes file &&
  35        test_tick &&
  36        git commit -m "normalize file" &&
  37
  38        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
  45        git rm .gitattributes &&
  46        rm file &&
  47        git checkout file &&
  48        test_tick &&
  49        git commit -m "remove .gitattributes" &&
  50        git tag c &&
  51
  52        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
  60        git checkout master
  61'
  62
  63test_expect_success 'set up fuzz_conflict() helper' '
  64        fuzz_conflict() {
  65                sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
  66        }
  67'
  68
  69test_expect_success 'Merge after setting text=auto' '
  70        cat <<-\EOF >expected &&
  71        first line
  72        same line
  73        EOF
  74
  75        if test_have_prereq NATIVE_CRLF; then
  76                append_cr <expected >expected.temp &&
  77                mv expected.temp expected
  78        fi &&
  79        git config merge.renormalize true &&
  80        git rm -fr . &&
  81        rm -f .gitattributes &&
  82        git reset --hard a &&
  83        git merge b &&
  84        test_cmp expected file
  85'
  86
  87test_expect_success 'Merge addition of text=auto' '
  88        cat <<-\EOF >expected &&
  89        first line
  90        same line
  91        EOF
  92
  93        if test_have_prereq NATIVE_CRLF; then
  94                append_cr <expected >expected.temp &&
  95                mv expected.temp expected
  96        fi &&
  97        git config merge.renormalize true &&
  98        git rm -fr . &&
  99        rm -f .gitattributes &&
 100        git reset --hard b &&
 101        git merge a &&
 102        test_cmp expected file
 103'
 104
 105test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
 106        echo "<<<<<<<" >expected &&
 107        if test_have_prereq NATIVE_CRLF; then
 108                echo first line | append_cr >>expected &&
 109                echo same line | append_cr >>expected &&
 110                echo ======= | append_cr >>expected
 111        else
 112                echo first line >>expected &&
 113                echo same line >>expected &&
 114                echo ======= >>expected
 115        fi &&
 116        echo first line | append_cr >>expected &&
 117        echo same line | append_cr >>expected &&
 118        echo ">>>>>>>" >>expected &&
 119        git config merge.renormalize false &&
 120        rm -f .gitattributes &&
 121        git reset --hard a &&
 122        test_must_fail git merge b &&
 123        fuzz_conflict file >file.fuzzy &&
 124        test_cmp expected file.fuzzy
 125'
 126
 127test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
 128        echo "<<<<<<<" >expected &&
 129        echo first line | append_cr >>expected &&
 130        echo same line | append_cr >>expected &&
 131        if test_have_prereq NATIVE_CRLF; then
 132                echo ======= | append_cr >>expected &&
 133                echo first line | append_cr >>expected &&
 134                echo same line | append_cr >>expected
 135        else
 136                echo ======= >>expected &&
 137                echo first line >>expected &&
 138                echo same line >>expected
 139        fi &&
 140        echo ">>>>>>>" >>expected &&
 141        git config merge.renormalize false &&
 142        rm -f .gitattributes &&
 143        git reset --hard b &&
 144        test_must_fail git merge a &&
 145        fuzz_conflict file >file.fuzzy &&
 146        test_cmp expected file.fuzzy
 147'
 148
 149test_expect_failure 'checkout -m after setting text=auto' '
 150        cat <<-\EOF >expected &&
 151        first line
 152        same line
 153        EOF
 154
 155        git config merge.renormalize true &&
 156        git rm -fr . &&
 157        rm -f .gitattributes &&
 158        git reset --hard initial &&
 159        git checkout a -- . &&
 160        git checkout -m b &&
 161        test_cmp expected file
 162'
 163
 164test_expect_failure 'checkout -m addition of text=auto' '
 165        cat <<-\EOF >expected &&
 166        first line
 167        same line
 168        EOF
 169
 170        git config merge.renormalize true &&
 171        git rm -fr . &&
 172        rm -f .gitattributes file &&
 173        git reset --hard initial &&
 174        git checkout b -- . &&
 175        git checkout -m a &&
 176        test_cmp expected file
 177'
 178
 179test_expect_failure 'cherry-pick patch from after text=auto was added' '
 180        append_cr <<-\EOF >expected &&
 181        first line
 182        same line
 183        EOF
 184
 185        git config merge.renormalize true &&
 186        git rm -fr . &&
 187        git reset --hard b &&
 188        test_must_fail git cherry-pick a >err 2>&1 &&
 189        grep "[Nn]othing added" err &&
 190        test_cmp expected file
 191'
 192
 193test_expect_success 'Test delete/normalize conflict' '
 194        git checkout -f side &&
 195        git rm -fr . &&
 196        rm -f .gitattributes &&
 197        git reset --hard initial &&
 198        git rm file &&
 199        git commit -m "remove file" &&
 200        git checkout master &&
 201        git reset --hard a^ &&
 202        git merge side
 203'
 204
 205test_done