Merge branch 'sb/parse-options'
[gitweb.git] / t / t4124-apply-ws-rule.sh
index f53ac466d6e13d21ef1a1e31817db1e7ea299757..fac2093d7f20d502f41f895d2ccdfccd5e639e2b 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-test_description='core.whitespace rules and git-apply'
+test_description='core.whitespace rules and git apply'
 
 . ./test-lib.sh
 
@@ -112,6 +112,15 @@ test_expect_success 'whitespace=error-all, no rule' '
 
 '
 
+test_expect_success 'whitespace=error-all, no rule (attribute)' '
+
+       git config --unset core.whitespace &&
+       echo "target -whitespace" >.gitattributes &&
+       apply_patch --whitespace=error-all &&
+       diff file target
+
+'
+
 for t in - ''
 do
        case "$t" in '') tt='!' ;; *) tt= ;; esac
@@ -121,13 +130,44 @@ do
                for i in - ''
                do
                        case "$i" in '') ti='#' ;; *) ti= ;; esac
-                       rule=${t}trailing,${s}space,${i}indent &&
+                       rule=${t}trailing,${s}space,${i}indent
+
+                       rm -f .gitattributes
                        test_expect_success "rule=$rule" '
                                git config core.whitespace "$rule" &&
                                test_fix "$tt$ts$ti"
                        '
+
+                       test_expect_success "rule=$rule (attributes)" '
+                               git config --unset core.whitespace &&
+                               echo "target whitespace=$rule" >.gitattributes &&
+                               test_fix "$tt$ts$ti"
+                       '
+
                done
        done
 done
 
+create_patch () {
+       sed -e "s/_/ /" <<-\EOF
+               diff --git a/target b/target
+               index e69de29..8bd6648 100644
+               --- a/target
+               +++ b/target
+               @@ -0,0 +1,3 @@
+               +An empty line follows
+               +
+               +A line with trailing whitespace and no newline_
+               \ No newline at end of file
+       EOF
+}
+
+test_expect_success 'trailing whitespace & no newline at the end of file' '
+       >target &&
+       create_patch >patch-file &&
+       git apply --whitespace=fix patch-file &&
+       grep "newline$" target &&
+       grep "^$" target
+'
+
 test_done