git p4: fix-up "import/export of labels to/from p4"
[gitweb.git] / t / t6038-merge-text-auto.sh
index e21b5d27d71eb87af353fdd4b7052f98619303b3..d9c2d386ddf8caff4b87fa457c23757f76c293c7 100755 (executable)
@@ -14,8 +14,9 @@ test_description='CRLF merge conflict across text=auto change
 
 . ./test-lib.sh
 
+test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
+
 test_expect_success setup '
-       git config merge.renormalize true &&
        git config core.autocrlf false &&
 
        echo first line | append_cr >file &&
@@ -59,12 +60,19 @@ test_expect_success setup '
        git checkout master
 '
 
+test_expect_success 'set up fuzz_conflict() helper' '
+       fuzz_conflict() {
+               sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@"
+       }
+'
+
 test_expect_success 'Merge after setting text=auto' '
        cat <<-\EOF >expected &&
        first line
        same line
        EOF
 
+       git config merge.renormalize true &&
        git rm -fr . &&
        rm -f .gitattributes &&
        git reset --hard a &&
@@ -78,6 +86,7 @@ test_expect_success 'Merge addition of text=auto' '
        same line
        EOF
 
+       git config merge.renormalize true &&
        git rm -fr . &&
        rm -f .gitattributes &&
        git reset --hard b &&
@@ -85,6 +94,88 @@ test_expect_success 'Merge addition of text=auto' '
        test_cmp expected file
 '
 
+test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
+       q_to_cr <<-\EOF >expected &&
+       <<<<<<<
+       first line
+       same line
+       =======
+       first lineQ
+       same lineQ
+       >>>>>>>
+       EOF
+
+       git config merge.renormalize false &&
+       rm -f .gitattributes &&
+       git reset --hard a &&
+       test_must_fail git merge b &&
+       fuzz_conflict file >file.fuzzy &&
+       test_cmp expected file.fuzzy
+'
+
+test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
+       q_to_cr <<-\EOF >expected &&
+       <<<<<<<
+       first lineQ
+       same lineQ
+       =======
+       first line
+       same line
+       >>>>>>>
+       EOF
+
+       git config merge.renormalize false &&
+       rm -f .gitattributes &&
+       git reset --hard b &&
+       test_must_fail git merge a &&
+       fuzz_conflict file >file.fuzzy &&
+       test_cmp expected file.fuzzy
+'
+
+test_expect_failure 'checkout -m after setting text=auto' '
+       cat <<-\EOF >expected &&
+       first line
+       same line
+       EOF
+
+       git config merge.renormalize true &&
+       git rm -fr . &&
+       rm -f .gitattributes &&
+       git reset --hard initial &&
+       git checkout a -- . &&
+       git checkout -m b &&
+       test_cmp expected file
+'
+
+test_expect_failure 'checkout -m addition of text=auto' '
+       cat <<-\EOF >expected &&
+       first line
+       same line
+       EOF
+
+       git config merge.renormalize true &&
+       git rm -fr . &&
+       rm -f .gitattributes file &&
+       git reset --hard initial &&
+       git checkout b -- . &&
+       git checkout -m a &&
+       test_cmp expected file
+'
+
+test_expect_failure 'cherry-pick patch from after text=auto was added' '
+       append_cr <<-\EOF >expected &&
+       first line
+       same line
+       EOF
+
+       git config merge.renormalize true &&
+       git rm -fr . &&
+       git reset --hard b &&
+       test_must_fail git cherry-pick a >err 2>&1 &&
+       grep "[Nn]othing added" err &&
+       test_cmp expected file
+'
+
 test_expect_success 'Test delete/normalize conflict' '
        git checkout -f side &&
        git rm -fr . &&