Merge branch 'jc/fsck-retire-require-eoh' into maint
[gitweb.git] / t / t0020-crlf.sh
index 9fa26df729fe45ad81d4c80d791da0fd7eb1bc02..f94120a8940a37c48fbb97abd85002da95e3abe9 100755 (executable)
@@ -8,6 +8,13 @@ has_cr() {
        tr '\015' Q <"$1" | grep Q >/dev/null
 }
 
+# add or remove CRs to disk file in-place
+# usage: munge_cr <append|remove> <file>
+munge_cr () {
+       "${1}_cr" <"$2" >tmp &&
+       mv tmp "$2"
+}
+
 test_expect_success setup '
 
        git config core.autocrlf false &&
@@ -28,9 +35,7 @@ test_expect_success setup '
        for w in Some extra lines here; do echo $w; done >>one &&
        git diff >patch.file &&
        patched=$(git hash-object --stdin <one) &&
-       git read-tree --reset -u HEAD &&
-
-       echo happy.
+       git read-tree --reset -u HEAD
 '
 
 test_expect_success 'safecrlf: autocrlf=input, all CRLF' '
@@ -100,14 +105,9 @@ test_expect_success 'update with autocrlf=input' '
        rm -f tmp one dir/two three &&
        git read-tree --reset -u HEAD &&
        git config core.autocrlf input &&
-
-       for f in one dir/two
-       do
-               append_cr <$f >tmp && mv -f tmp $f &&
-               git update-index -- $f ||
-               break
-       done &&
-
+       munge_cr append one &&
+       munge_cr append dir/two &&
+       git update-index -- one dir/two &&
        differs=$(git diff-index --cached HEAD) &&
        verbose test -z "$differs"
 
@@ -118,14 +118,9 @@ test_expect_success 'update with autocrlf=true' '
        rm -f tmp one dir/two three &&
        git read-tree --reset -u HEAD &&
        git config core.autocrlf true &&
-
-       for f in one dir/two
-       do
-               append_cr <$f >tmp && mv -f tmp $f &&
-               git update-index -- $f ||
-               break
-       done &&
-
+       munge_cr append one &&
+       munge_cr append dir/two &&
+       git update-index -- one dir/two &&
        differs=$(git diff-index --cached HEAD) &&
        verbose test -z "$differs"
 
@@ -136,13 +131,9 @@ test_expect_success 'checkout with autocrlf=true' '
        rm -f tmp one dir/two three &&
        git config core.autocrlf true &&
        git read-tree --reset -u HEAD &&
-
-       for f in one dir/two
-       do
-               remove_cr <"$f" >tmp && mv -f tmp $f &&
-               verbose git update-index -- $f ||
-               break
-       done &&
+       munge_cr remove one &&
+       munge_cr remove dir/two &&
+       git update-index -- one dir/two &&
        test "$one" = $(git hash-object --stdin <one) &&
        test "$two" = $(git hash-object --stdin <dir/two) &&
        differs=$(git diff-index --cached HEAD) &&
@@ -154,18 +145,9 @@ test_expect_success 'checkout with autocrlf=input' '
        rm -f tmp one dir/two three &&
        git config core.autocrlf input &&
        git read-tree --reset -u HEAD &&
-
-       for f in one dir/two
-       do
-               if has_cr "$f"
-               then
-                       echo "Eh? $f"
-                       false
-                       break
-               else
-                       git update-index -- $f
-               fi
-       done &&
+       test_must_fail has_cr one &&
+       test_must_fail has_cr two &&
+       git update-index -- one dir/two &&
        test "$one" = $(git hash-object --stdin <one) &&
        test "$two" = $(git hash-object --stdin <dir/two) &&
        differs=$(git diff-index --cached HEAD) &&
@@ -241,29 +223,9 @@ test_expect_success '.gitattributes says two is binary' '
        git config core.autocrlf true &&
        git read-tree --reset -u HEAD &&
 
-       if has_cr dir/two
-       then
-               echo "Huh?"
-               false
-       else
-               : happy
-       fi &&
-
-       if has_cr one
-       then
-               : happy
-       else
-               echo "Huh?"
-               false
-       fi &&
-
-       if has_cr three
-       then
-               echo "Huh?"
-               false
-       else
-               : happy
-       fi
+       test_must_fail has_cr dir/two &&
+       verbose has_cr one &&
+       test_must_fail has_cr three
 '
 
 test_expect_success '.gitattributes says two is input' '
@@ -272,13 +234,7 @@ test_expect_success '.gitattributes says two is input' '
        echo "two crlf=input" >.gitattributes &&
        git read-tree --reset -u HEAD &&
 
-       if has_cr dir/two
-       then
-               echo "Huh?"
-               false
-       else
-               : happy
-       fi
+       test_must_fail has_cr dir/two
 '
 
 test_expect_success '.gitattributes says two and three are text' '