Merge branch 'hv/doc-commit-reference-style' into maint
[gitweb.git] / t / t6038-merge-text-auto.sh
index 85c10b0940a896bb49aefee9a2885b1c39217bab..5e8d5fa50c9a6a548e5f2fdb11186c165519d06f 100755 (executable)
@@ -16,6 +16,13 @@ test_description='CRLF merge conflict across text=auto change
 
 test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
 
+compare_files () {
+       tr '\015\000' QN <"$1" >"$1".expect &&
+       tr '\015\000' QN <"$2" >"$2".actual &&
+       test_cmp "$1".expect "$2".actual &&
+       rm "$1".expect "$2".actual
+}
+
 test_expect_success setup '
        git config core.autocrlf false &&
 
@@ -30,7 +37,7 @@ test_expect_success setup '
        git branch side &&
 
        echo "* text=auto" >.gitattributes &&
-       touch file &&
+       echo first line >file &&
        git add .gitattributes file &&
        test_tick &&
        git commit -m "normalize file" &&
@@ -81,38 +88,49 @@ test_expect_success 'Merge after setting text=auto' '
        rm -f .gitattributes &&
        git reset --hard a &&
        git merge b &&
-       test_cmp expected file
+       compare_files expected file
 '
 
-test_expect_success 'Merge addition of text=auto' '
+test_expect_success 'Merge addition of text=auto eol=LF' '
+       git config core.eol lf &&
        cat <<-\EOF >expected &&
        first line
        same line
        EOF
 
-       if test_have_prereq NATIVE_CRLF; then
-               append_cr <expected >expected.temp &&
-               mv expected.temp expected
-       fi &&
        git config merge.renormalize true &&
        git rm -fr . &&
        rm -f .gitattributes &&
        git reset --hard b &&
        git merge a &&
-       test_cmp expected file
+       compare_files  expected file
+'
+
+test_expect_success 'Merge addition of text=auto eol=CRLF' '
+       git config core.eol crlf &&
+       cat <<-\EOF >expected &&
+       first line
+       same line
+       EOF
+
+       append_cr <expected >expected.temp &&
+       mv expected.temp expected &&
+       git config merge.renormalize true &&
+       git rm -fr . &&
+       rm -f .gitattributes &&
+       git reset --hard b &&
+       echo >&2 "After git reset --hard b" &&
+       git ls-files -s --eol >&2 &&
+       git merge a &&
+       compare_files  expected file
 '
 
 test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
+       git config core.eol native &&
        echo "<<<<<<<" >expected &&
-       if test_have_prereq NATIVE_CRLF; then
-               echo first line | append_cr >>expected &&
-               echo same line | append_cr >>expected &&
-               echo ======= | append_cr >>expected
-       else
-               echo first line >>expected &&
-               echo same line >>expected &&
-               echo ======= >>expected
-       fi &&
+       echo first line >>expected &&
+       echo same line >>expected &&
+       echo ======= >>expected &&
        echo first line | append_cr >>expected &&
        echo same line | append_cr >>expected &&
        echo ">>>>>>>" >>expected &&
@@ -121,29 +139,23 @@ test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
        git reset --hard a &&
        test_must_fail git merge b &&
        fuzz_conflict file >file.fuzzy &&
-       test_cmp expected file.fuzzy
+       compare_files expected file.fuzzy
 '
 
 test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
        echo "<<<<<<<" >expected &&
        echo first line | append_cr >>expected &&
        echo same line | append_cr >>expected &&
-       if test_have_prereq NATIVE_CRLF; then
-               echo ======= | append_cr >>expected &&
-               echo first line | append_cr >>expected &&
-               echo same line | append_cr >>expected
-       else
-               echo ======= >>expected &&
-               echo first line >>expected &&
-               echo same line >>expected
-       fi &&
+       echo ======= >>expected &&
+       echo first line >>expected &&
+       echo same line >>expected &&
        echo ">>>>>>>" >>expected &&
        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
+       compare_files expected file.fuzzy
 '
 
 test_expect_failure 'checkout -m after setting text=auto' '
@@ -158,7 +170,7 @@ test_expect_failure 'checkout -m after setting text=auto' '
        git reset --hard initial &&
        git checkout a -- . &&
        git checkout -m b &&
-       test_cmp expected file
+       compare_files expected file
 '
 
 test_expect_failure 'checkout -m addition of text=auto' '
@@ -173,7 +185,7 @@ test_expect_failure 'checkout -m addition of text=auto' '
        git reset --hard initial &&
        git checkout b -- . &&
        git checkout -m a &&
-       test_cmp expected file
+       compare_files expected file
 '
 
 test_expect_failure 'cherry-pick patch from after text=auto was added' '
@@ -187,7 +199,7 @@ test_expect_failure 'cherry-pick patch from after text=auto was added' '
        git reset --hard b &&
        test_must_fail git cherry-pick a >err 2>&1 &&
        grep "[Nn]othing added" err &&
-       test_cmp expected file
+       compare_files expected file
 '
 
 test_expect_success 'Test delete/normalize conflict' '