From 3ff3e80ea3a1730afbf07cb76445565a5935b8d8 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Fri, 12 Jan 2018 20:12:29 +0100 Subject: [PATCH] Ignore .git and .svn directories --- check-trailing-whitespaces | 9 ++++++++- tests/default_ignored_paths/files/.svn/file.php | 5 +++++ .../files/directory/.svn/file.php | 5 +++++ tests/default_ignored_paths/files/file.php | 5 +++++ tests/default_ignored_paths/test | 6 ++++++ tests/tests.sh | 13 ++++++++++++- 6 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tests/default_ignored_paths/files/.svn/file.php create mode 100644 tests/default_ignored_paths/files/directory/.svn/file.php create mode 100644 tests/default_ignored_paths/files/file.php create mode 100644 tests/default_ignored_paths/test diff --git a/check-trailing-whitespaces b/check-trailing-whitespaces index a7b1c74..7458b3f 100755 --- a/check-trailing-whitespaces +++ b/check-trailing-whitespaces @@ -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 diff --git a/tests/default_ignored_paths/files/.svn/file.php b/tests/default_ignored_paths/files/.svn/file.php new file mode 100644 index 0000000..dd63a73 --- /dev/null +++ b/tests/default_ignored_paths/files/.svn/file.php @@ -0,0 +1,5 @@ +\e[0m line with spaces\e[41;1m \e[0m diff --git a/tests/tests.sh b/tests/tests.sh index 4c0f3a1..e253a75 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -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 @@ -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")")"/*/ @@ -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