t / t6038-merge-text-auto.shon commit Merge branch 'tr/push-no-verify-doc' (3f261c0)
   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        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'
  82
  83test_expect_success 'Merge addition of text=auto' '
  84        cat <<-\EOF >expected &&
  85        first line
  86        same line
  87        EOF
  88
  89        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'
  96
  97test_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
 108        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'
 115
 116test_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
 127        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'
 134
 135test_expect_failure 'checkout -m after setting text=auto' '
 136        cat <<-\EOF >expected &&
 137        first line
 138        same line
 139        EOF
 140
 141        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'
 149
 150test_expect_failure 'checkout -m addition of text=auto' '
 151        cat <<-\EOF >expected &&
 152        first line
 153        same line
 154        EOF
 155
 156        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'
 164
 165test_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
 171        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'
 178
 179test_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'
 190
 191test_done