Fix search for IGNORE_CHECKSTYLE files. am: 4a7cc7eba1 am: 0afd78b86c
am: 86644ca317
Change-Id: I4f92fda492f3813bd519a65b0bc1090abe3972b8
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..acf7759
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,2 @@
+[Hook Scripts]
+checkstyle_test_hook = ./tests.py
\ No newline at end of file
diff --git a/checkstyle.py b/checkstyle.py
index 39ca181..97c4e93 100755
--- a/checkstyle.py
+++ b/checkstyle.py
@@ -28,9 +28,9 @@
import xml.dom.minidom
import gitlint.git as git
+
def _FindFoldersContaining(root, wanted):
- """Searches recursively from root to find directories that has a file with
- the given name.
+ """Recursively finds directories that have a file with the given name.
Args:
root: Root folder to start the search from.
@@ -40,16 +40,18 @@
List of folders that has a file with the given name
"""
+ if not root:
+ return []
if os.path.islink(root):
return []
result = []
- for fileName in os.listdir(root):
- filePath = os.path.join(root, fileName)
- if os.path.isdir(filePath):
- subResult = _FindFoldersContaining(filePath, wanted)
- result.extend(subResult)
+ for file_name in os.listdir(root):
+ file_path = os.path.join(root, file_name)
+ if os.path.isdir(file_path):
+ sub_result = _FindFoldersContaining(file_path, wanted)
+ result.extend(sub_result)
else:
- if fileName == wanted:
+ if file_name == wanted:
result.append(root)
return result
@@ -61,8 +63,8 @@
SKIPPED_RULES_FOR_TEST_FILES = ['com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck',
'com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck']
SUBPATH_FOR_TEST_FILES = ['/tests/', '/test/', '/androidTest/']
-SUBPATH_FOR_TEST_DATA_FILES = _FindFoldersContaining(os.path.dirname(os.getcwd()),
- "IGNORE_CHECKSTYLE")
+SUBPATH_FOR_TEST_DATA_FILES = _FindFoldersContaining(git.repository_root(),
+ 'IGNORE_CHECKSTYLE')
ERROR_UNCOMMITTED = 'You need to commit all modified files before running Checkstyle\n'
ERROR_UNTRACKED = 'You have untracked java files that are not being checked:\n'
@@ -105,6 +107,9 @@
Returns:
A tuple of errors and warnings.
"""
+ if not git.repository_root():
+ print 'FAILURE: not inside a git repository'
+ sys.exit(1)
explicit_commit = commit is not None
if not explicit_commit:
_WarnIfUntrackedFiles()