Skip to content

Commit

Permalink
Ignore .git and .svn directories (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienfalque authored Jan 14, 2018
1 parent e880861 commit b612447
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
9 changes: 8 additions & 1 deletion check-trailing-whitespaces
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/bash

files_with_trailing_spaces=$(find . -type f -exec grep -EIHn "\\s$" {} \; | sort -fh)
files_with_trailing_spaces=$(
find . \
-type f \
-not -regex ".*/\\.git/.*" \
-not -regex ".*/\\.svn/.*" \
-exec grep -EIHn "\\s$" {} \; \
| sort -fh
)

if [[ ${files_with_trailing_spaces} ]]
then
Expand Down
5 changes: 5 additions & 0 deletions tests/default_ignored_paths/files/.svn/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$foo = '
line with spaces
';
5 changes: 5 additions & 0 deletions tests/default_ignored_paths/files/directory/.svn/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$foo = '
line with spaces
';
5 changes: 5 additions & 0 deletions tests/default_ignored_paths/files/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$foo = '
line with spaces
';
6 changes: 6 additions & 0 deletions tests/default_ignored_paths/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--STATUS-CODE--
3
--OUTPUT--
\e[97;41mTrailing whitespaces detected:\e[0m
\e[0;31m - in \e[0;33mfile.php\e[0;31m at line \e[0;33m4
\e[0;31m>\e[0m line with spaces\e[41;1m \e[0m
13 changes: 12 additions & 1 deletion tests/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ run_test() {
cd "${1}files" || return 3
output=$(../../../check-trailing-whitespaces)
status_code="$?"
cd ../.. || return 3
cd "$OLDPWD" || return 3

if [ "${status_code}" != "${expected_status_code}" ]
then
Expand All @@ -31,6 +31,13 @@ run_test() {
return 0
}

# setup
# Git does not allow to track a .git directory so we copy .svn
rm -rf tests/default_ignored_paths/files/.git tests/default_ignored_paths/files/directory/.git
cp -r tests/default_ignored_paths/files/.svn tests/default_ignored_paths/files/.git
cp -r tests/default_ignored_paths/files/directory/.svn tests/default_ignored_paths/files/directory/.git

# run tests
i=0
failures=0
for test_case in "$(dirname "$(realpath "$0")")"/*/
Expand All @@ -49,6 +56,10 @@ do
((++i))
done

# clean
rm -rf tests/default_ignored_paths/files/.git tests/default_ignored_paths/files/directory/.git

# exit
if [ "${failures}" -ne 0 ]
then
exit 3
Expand Down

0 comments on commit b612447

Please sign in to comment.