Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore .git and .svn directories #7

Merged
merged 1 commit into from
Jan 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to cd - > /dev/null.


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