git update-index x
-cat << EOF > x
+tr '_' ' ' << EOF > x
whitespace at beginning
whitespace change
white space in the middle
-whitespace at end
+whitespace at end__
unchanged line
CR at end
EOF
-tr 'Q' '\015' << EOF > expect
+tr 'Q_' '\015 ' << EOF > expect
diff --git a/x b/x
index d99af23..8b32fb5 100644
--- a/x
+ whitespace at beginning
+whitespace change
+white space in the middle
-+whitespace at end
++whitespace at end__
unchanged line
-CR at endQ
+CR at end
test_expect_success 'check with trailing whitespace' '
echo "foo(); " > x &&
- ! git diff --check
+ test_must_fail git diff --check
'
# indent has space followed by hard tab
echo " foo();" > x &&
- ! git diff --check
+ test_must_fail git diff --check
'
echo "foo(); " > x &&
git add x &&
- ! git diff --cached --check
+ test_must_fail git diff --cached --check
'
# indent has space followed by hard tab
echo " foo();" > x &&
git add x &&
- ! git diff --cached --check
+ test_must_fail git diff --cached --check
'
echo "foo(); " > x &&
git add x &&
- ! git diff-index --check HEAD
+ test_must_fail git diff-index --check HEAD
'
# indent has space followed by hard tab
echo " foo();" > x &&
git add x &&
- ! git diff-index --check HEAD
+ test_must_fail git diff-index --check HEAD
'
echo "foo(); " > x &&
git add x &&
- ! git diff-index --cached --check HEAD
+ test_must_fail git diff-index --cached --check HEAD
'
# indent has space followed by hard tab
echo " foo();" > x &&
git add x &&
- ! git diff-index --cached --check HEAD
+ test_must_fail git diff-index --cached --check HEAD
'
echo "foo(); " > x &&
git commit -m "another commit" x &&
- ! git diff-tree --check HEAD^ HEAD
+ test_must_fail git diff-tree --check HEAD^ HEAD
'
# indent has space followed by hard tab
echo " foo();" > x &&
git commit -m "yet another" x &&
- ! git diff-tree --check HEAD^ HEAD
+ test_must_fail git diff-tree --check HEAD^ HEAD
'
git config core.whitespace "trailing-space" &&
echo "foo (); " > x &&
- ! git diff --check
+ test_must_fail git diff --check
'
# indent contains space followed by HT
git config core.whitespace "space-before-tab" &&
echo " foo (); " > x &&
- ! git diff --check
+ test_must_fail git diff --check
'
git config core.whitespace "indent-with-non-tab" &&
echo " foo ();" > x &&
- ! git diff --check
+ test_must_fail git diff --check
'
git config core.whitespace "indent-with-non-tab" &&
echo " foo ();" > x &&
- ! git diff --check
+ test_must_fail git diff --check
'
'
+test_expect_success 'checkdiff detects trailing blank lines' '
+ echo "foo();" >x &&
+ echo "" >>x &&
+ git diff --check | grep "ends with blank"
+'
+
test_done