Permalink
Browse files

Add --ignore-untracked flag

  • Loading branch information...
1 parent 4fc0b5c commit b71a3e7ddda188a2982fbd8f011ae54c575dcd49 @sbuss sbuss committed Jan 29, 2014
Showing with 17 additions and 5 deletions.
  1. +7 −1 codequality/main.py
  2. +10 −4 codequality/scmhandlers.py
View
@@ -87,7 +87,8 @@ def codequality(self, paths):
checker_to_loc_to_filename = {}
for filename, location in scmhandler.srcs_to_check(
- paths, rev=self.options.rev):
+ paths, rev=self.options.rev,
+ ignore_untracked=self.options.ignore_untracked):
if self._should_ignore(filename):
continue
@@ -240,6 +241,11 @@ def main():
action='store_true', default=False,
help='Prints extra information to stderr.',
)
+ parser.add_option(
+ '--ignore-untracked', dest='ignore_untracked',
+ action='store_true', default=False,
+ help='Ignore untracked files (only applicable if using scm).',
+ )
options, paths = parser.parse_args()
View
@@ -67,11 +67,12 @@ class GitHandler(SCMHandler):
"""
# Begin public API
- def srcs_to_check(self, limit_paths, rev=None):
+ def srcs_to_check(self, limit_paths, rev=None, ignore_untracked=False):
rev = self._resolve_rev(rev)
relative_paths = self._add_and_modified_in_rev(rev) \
- if rev else self._add_and_modified_in_working_copy()
+ if rev else self._add_and_modified_in_working_copy(
+ ignore_untracked)
if limit_paths:
relative_paths = set(relative_paths).intersection(limit_paths)
@@ -92,7 +93,7 @@ def srcs_to_check(self, limit_paths, rev=None):
r'^ (?P<type>\w+) mode (?P<mode>\w+) (?P<path>.+)')
GIT_SUBMODULE_MODE = 160000
- def _add_and_modified_in_working_copy(self):
+ def _add_and_modified_in_working_copy(self, ignore_untracked=False):
inside_work_tree = \
self._git_cmd('rev-parse --is-inside-work-tree') == 'true'
if not inside_work_tree:
@@ -112,7 +113,12 @@ def _add_and_modified_in_working_copy(self):
#
# Note that we use "." at the end of the status command to limit
# paths to those under the current working directory.
- cmd = 'status --porcelain --untracked-files=all .'
+ if ignore_untracked:
+ untracked = "no"
+ else:
+ untracked = "all"
+ cmd = 'status --porcelain --untracked-files={untracked} .'.format(
+ untracked=untracked)
status_output = self._git_cmd(cmd)
for line in status_output.splitlines():

0 comments on commit b71a3e7

Please sign in to comment.