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